Feat/unitary definitions - #45
Conversation
…e-token and astt-ype-qumode
Older flake8 4.0.1 crashes under Python 3.12's importlib.metadata. Also apply small pre-commit whitespace/newline fixes and sync uv.lock. Co-authored-by: Cursor <cursoragent@cursor.com>
Parse snap([θ…])-style calls as a single classical ASTAngleArray argument, and move fork-local production rules into the 10000+ range to avoid colliding with upstream numbering. Co-authored-by: Cursor <cursoragent@cursor.com>
added comments explaining how tokens are created
changed ASTTypeQubit to ASTTypQumode for Qumode token
Feat/qumode
Qumode (and mixed qubit/qumode) call-site args resolve and validate like qubits, with opaque snap/ecd/disp stubs for CV gates. Co-authored-by: Cursor <cursoragent@cursor.com>
Register TOK_DISP / ASTDispGateNode, accept a complex parameter and qumode target, and allow leading qubit controls only under ctrl/negctrl. Include related tests and the preprocessor full-file read fix. Co-authored-by: Cursor <cursoragent@cursor.com>
Add builtin disp gate and qumode CV gate call support
Fix/qumode subscript op support
Support explicit classical formals (angle/float/complex and arrays), typed qubit/qumode operands, GateType compatibility (including array sizes), mixed array+scalar call args, and angle-array body indexing across gates. Co-authored-by: Cursor <cursoragent@cursor.com>
GateEOp construction was appending the bare target while the modifier statement was also appended; skip or pop the target so only the wrapped op remains in gate bodies. Co-authored-by: Cursor <cursoragent@cursor.com>
Emit FullyTyped/FormalParamTypes/FormalQuantumTypes from ASTGateNode::print, and encode complex/array formals plus qubit vs qumode in definition mangled names (remangle after Formal* is attached). Co-authored-by: Cursor <cursoragent@cursor.com>
Rename quantum carriers to Operands/OperandParams and GateOperandParam (keeping mangler tag GQP), materialize qumode formals as ASTQumodeNode, and attach BinaryOp/UnaryOp trees on disp complex Params instead of folding through angle→real+0i. Co-authored-by: Cursor <cursoragent@cursor.com>
Real literals and expressions against complex formals (and builtin disp) become MPComplex directly instead of angle coercion; document call-site GateQOpList as a representation quirk. Co-authored-by: Cursor <cursoragent@cursor.com>
Support gate foo[uint N](array[T, N] …) with inferred or explicit N at calls, and move array-initialization notes to GitHub issue #11. Co-authored-by: Cursor <cursoragent@cursor.com>
Introduce Fock control distinct from qubit ctrl(n), switch templates and Fock levels to square brackets, and allow arithmetic in ctrl[…] brackets. Co-authored-by: Cursor <cursoragent@cursor.com>
Replace opaque SNAP with a typed cvgates definition, keep induction indices and template bindings intact for lowering, and drop a local issue draft already filed as GitHub #15. Co-authored-by: Cursor <cursoragent@cursor.com>
Store float/mpdecimal (and call-site conversions) in Params as declared types, use angle arrays for SNAP, and document the stable disp/snap/ecd call contract plus project stable vs WIP split for compiler consumers. Co-authored-by: Cursor <cursoragent@cursor.com>
…um-params Typed gate declarations with fixed numbers of parameters
unitary u = {
{1, 0},
{0, 1}
};
semantic analysis will need to check
are all rows the same length?
is the matrix square?
are the entries valid numeric/complex expressions?
does it satisfy U†U=I?
|
|
|
Hi @Katie1harrison: a quick heads up that this project is no longer actively maintained by the original authors. You are welcome to fork this for your own use, or if you want to become a maintainer of the repo in its currently location, we would consider that. I'm curious if this |
Add Matrix Definitions for the Unitary Data Type
Summary
This PR extends the
unitarydata type so that a unitary can be defined using a matrix initializer.Previously, unitary declarations supported:
This PR adds support for:
unitary u = { {1, 0}, {0, 1} };Changes
ASTUnitaryNode
Updated
ASTUnitaryNodeto optionally store anASTInitializerListrepresenting the matrix used to define the unitary.Added:
along with a constructor for initialized unitaries and methods for accessing the initializer list.
The existing constructors for uninitialized unitary declarations and unitary gate calls are preserved.
ASTBuilder
Added an overloaded
CreateASTUnitaryNodethat accepts anASTInitializerList.This allows the builder to construct both:
and:
unitary u = { {1, 0}, {0, 1} };ASTProductionFactory
Added a production rule for constructing a unitary declaration containing an initializer list. The new production rule passes the parsed initializer list to
ASTBuilder.Parser Grammar
Added grammar support for:
unitary Identifier = { { ... }, { ... } };The implementation reuses the existing
InitializerListgrammar rather than introducing a separate matrix AST type.AST Representation
For example:
unitary u = { {1, 0}, {0, 1} };is represented as:
Testing
Added/tested parsing of an initialized unitary using:
The parser successfully produces an
ASTTypeUnitarydeclaration containing the expectedInitializerListand matrix entries.Not Included
This PR adds the syntax and AST representation for matrix-defined unitaries. It does not yet validate that the provided matrix is mathematically unitary.
Matrix shape, element type, and unitarity validation can be handled later during semantic analysis/compiler validation.