Skip to content

Signature.build with flexible typing and shape syntax#1826

Merged
mpharrigan merged 6 commits intoquantumlib:mainfrom
mpharrigan:2026-03/qsignature
Mar 16, 2026
Merged

Signature.build with flexible typing and shape syntax#1826
mpharrigan merged 6 commits intoquantumlib:mainfrom
mpharrigan:2026-03/qsignature

Conversation

@mpharrigan
Copy link
Copy Markdown
Collaborator

  • a new ShapedQCDType capable of specifying quantum arrays natively through subscripting (e.g., QInt(8)[20])
  • upgraded Signature.build syntactic sugar. Signature.build can now seamlessly handle fully instantiated types, shaped types, positional lists of registers/signatures, and granular side directives via tuples. fixes Syntactic sugar for declaring signatures #1769
            >>> from qualtran import QBit, QUInt
            >>> sig = Signature.build(ctrl=QBit()[5, 5], system=QUInt(32))
            >>> sig == Signature([
            ...     Register('ctrl', QBit(), shape=(5, 5)),
            ...     Register('system', QUInt(32))
            ... ])
            True

            >>> sig = Signature.build(a=(QBit(), QBit()), b=(None, QBit()))
            >>> sig == Signature([
            ...     Register('a', QBit(), side=Side.THRU),
            ...     Register('b', QBit(), side=Side.RIGHT)
            ... ])
            True

@mpharrigan mpharrigan force-pushed the 2026-03/qsignature branch from d7cd375 to 77698d2 Compare March 9, 2026 23:41
@mpharrigan mpharrigan marked this pull request as ready for review March 9, 2026 23:42
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a more flexible syntax for building Signature objects by adding ShapedQCDType and enhancing Signature.build. The changes allow for more intuitive definitions of registers, including shaped arrays and side specifications. My review found one issue where the implementation of Signature.build for positional arguments is more restrictive than its documentation suggests, only handling lists instead of general iterables. I've suggested a fix to align the implementation with the documented behavior.

mpharrigan and others added 2 commits March 16, 2026 10:33
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@mpharrigan mpharrigan merged commit 992afe8 into quantumlib:main Mar 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syntactic sugar for declaring signatures

1 participant