Skip to content

fix: correct circuit state handling, QASM serialization, and gate semantics - #72

Merged
jianjian01 merged 8 commits into
cq-lib:release/2.0from
jianjian01:release/2.0
Oct 29, 2026
Merged

jianjian01 merged 8 commits into
cq-lib:release/2.0from
jianjian01:release/2.0

Conversation

@jianjian01

Copy link
Copy Markdown
Collaborator

Fix circuit state corruption during composition, parameter binding, and failed control-flow construction. Correct stabilizer half-rotation signs, QASM handling, and missing native gate lowering paths.

Changes

  • Correct stabilizer Y2P/Y2M conjugation signs to match Ry(±π/2).
  • Fix QASM2 serialization of X/Y/XY half rotations, including instruction terminators and ASCII pi formatting.
  • Reject unsupported QASM3 end statements before lowering discards unreachable branches or expands loops.
  • Complete single-qubit lowering paths into U, RXY, and RZ with same-polarity X/Y half rotations, preserving symbolic parameters and global phase.
  • Make compose reject duplicate target qubits and preserve destination identity, existing classical handles, and state on failure.
  • Remap classical references to the new circuit identity during parameter binding.
  • Restore appended qubits and the previous global phase when control-flow construction rolls back, preventing dangling phase indices.
  • Stage only newly introduced parameter expressions during composition, eliminating repeated copies of the existing parameter table.

Align the signed tableau updates with Ry(+pi/2) and Ry(-pi/2), and clarify conjugation and global-phase comments.

Add regressions for complete Pauli product eigenstates, packed-word boundaries, interference and Bell circuits, sampling and execution, and seeded random Clifford circuits. All five new tests fail before the fix and pass afterward.

Validation: core library tests (3423 passed, 2 ignored), core all-targets Clippy with warnings denied, cargo fmt, and git diff --check.
Reject program termination before lowering can discard unreachable branches or expand loops, preserving UnsupportedFeature errors for nested scopes and included files.

Add regressions for top-level and nested end statements, unreachable code, file-loading aliases, includes, and non-statement uses of end. Document the restriction in Chinese and English APIs and guides.

Ignore the valid Unicode Nd regex category in typos to prevent the commit hook from rewriting it as And.

Validation: core library tests (3428 passed, 2 ignored), original audit regression, core all-targets Clippy with warnings denied, cargo fmt, and git diff --check.
Terminate every expanded X2P/X2M/Y2P/Y2M/XY2P/XY2M instruction and share QASM parameter formatting so decompositions emit ASCII pi.

Add regressions for individual gates, numeric and symbolic axes, entangled circuits, custom and unitary gate definitions, file aliases, parameter errors, conditional rejection, and all standard gates with an explicit phase policy.

Validation: QASM2 tests (121 passed), core library tests (3435 passed, 2 ignored), core all-targets Clippy with warnings denied, cargo fmt, and git diff --check.
Reject duplicate explicit qubit targets before mutation. Prepare remapped operations, parameter tables, and global phase before committing, preserving circuit identity, classical handles, and active control scopes.

Add core and binding regressions for duplicate mappings, failure atomicity, sparse permutations, phase semantics, and classical handle preservation. Document the composition contract.

Validation: core library tests (3439 passed, 2 ignored), Python circuit tests (263 passed), C circuit tests (15 passed), original audit reproduction, core and C all-targets Clippy, Rust formatting, Ruff, and git diff --check.
Add exact decomposition paths into U and RXY, bridge XY half-rotation
polarities, and lower U into RZ plus same-polarity X/Y half rotations.
Preserve symbolic parameters and global phase throughout lowering.

Cover registered rule equivalence, device capability overrides, bounded
planning under heterogeneous calibrations, and directed routing with
initial/final layout isometry. Correct the incomplete-basis negative test
to use the diagonal-only RZ/Z basis.

Validation: core library tests (3446 passed, 2 ignored), core all-targets
Clippy with warnings denied, cargo fmt, and git diff --check. Confirmed
the added native-basis and compact-decomposition regressions fail with
the original rules.
@jianjian01
jianjian01 merged commit 4447475 into cq-lib:release/2.0 Oct 29, 2026
4 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.

1 participant