Skip to content

Feat/block zxz unitary - #78

Merged
jianjian01 merged 73 commits into
cq-lib:developfrom
jianjian01:feat/block-zxz-unitary
Nov 26, 2026
Merged

jianjian01 merged 73 commits into
cq-lib:developfrom
jianjian01:feat/block-zxz-unitary

Conversation

@jianjian01

Copy link
Copy Markdown
Collaborator

No description provided.

 fix(compile): stabilize Euler rotation normalization at pi boundaries
The copy-swap circuit inserted uncontrolled SWAPs between copies. Since
S rho^⊗M S† = rho^⊗M, a bare permutation is a no-op on the product
state, so neither Tr(O rho^M) nor Tr(rho^M) was ever measured and the
mitigated estimate degenerated to <H>^copies (e.g. VD of <Z> on |1>
returned +1 instead of -1).

Replace it with the Hadamard-test circuit of Huggins et al. (PRX 11,
041036, App. C): copies preparations, one ancillary qubit prepared in
|+>, and a ladder of ancilla-controlled SWAPs between adjacent copies
realizing the derangement. The numerator observable is the original
Hamiltonian on the first copy tensored with X on the ancilla; the
denominator observable is X on the ancilla alone.

BREAKING CHANGE: estimators now receive a Hamiltonian on the
denominator call too (a single X on the ancilla) instead of None;
distinguish numerator and denominator by observable content. The
copy-swap circuit width grows from copies * base_width to
copies * base_width + 1.

Add exact density-matrix tests: |1> recovers <Z> = -1, pure states
Ry(theta) are invariant for copies 2 and 3, and depolarizing noise
matches the analytic Tr(Z rho^2)/Tr(rho^2). Update C/Python bindings
and the CN/EN docs to the new contract.
Device::line, bidirectional_line, ring, star, grid, from_edges, and
line_from_qubits previously accepted zero qubits and returned an empty
device. Add DeviceError::EmptyDevice and validate the two construction
entry points (line_from_qubits and from_u32_edges) so all factories
reject empty input.
fix(em): rebuild virtual distillation as Hadamard test; release 2.0.0-beta.2 / 0.1.0-beta.2
docs(whitepaper): add cqlib whitepaper pdf for release 2.0
docs(whitepaper): track PDF via Git LFS and link it in READMEs
Pair every is_*() predicate with an Option-returning payload accessor,
so callers can dispatch on the predicate and read the payload without
pattern matching or parsing instruction names:

- Instruction: mc_gate(), unitary_gate(), circuit_gate(),
  classical_data() and classical_control() return references,
  directive() returns the Copy payload by value
- ValueInstruction: mc_gate(), unitary_gate(), circuit_gate() and
  classical_data() delegate to the wrapped Instruction, and
  classical_control() returns the value-level control-flow payload
…calDataOp

- Add mc_gate / unitary_gate / circuit_gate / classical_data getters
  to Instruction and ValueInstruction, cloning the payload by value;
  gate parameters belong to the operation layer (ValueOperation.params)
- Register the new ClassicalDataOp class wrapping core classical data
  ops, with kind / target / value / result getters, its runtime module
  and type stubs
- List the new Instruction / ValueInstruction payload accessors in the
  Python and Rust API references (EN + CN)
- Add a ClassicalDataOp section to the classical data / control flow
  pages and to the circuit overview tables
feat(circuit): add instruction payload accessors and Python ClassicalDataOp
Validate state dimensions and finite inputs before constructing simulators. Respect original qubit labels and identity-gate noise during noisy simulation.

Stabilize Renyi entropy, validate real observable expectations and variance, retain small evolution coefficients, and preserve global phase during ZNE folding. Include regression tests and matching Rust, Python, and C API documentation.

Validation: 16 core regression tests, 4 C regression tests, and 1200 Python QIS tests passed against the staged source snapshot. Rust formatting and Python formatting checks passed.
Implement copy.copy and copy.deepcopy using the existing owned-value clone. Include type declarations, English and Chinese documentation, and tests for empty operators, independent terms, and alias preservation in nested deepcopy.

Validation: all 58 Hamiltonian Python tests passed against an extension built from the staged source snapshot.
Describe endian ordering, release workflow organization, gate-basis tests, and phase conventions directly in terms of CQLib behavior. Cite the original SABRE paper and retain the existing commutative-cancellation implementation reference.

Validation: all 99 compiler rewrite tests passed. Runtime behavior is unchanged.
Use a square-root machine-epsilon tolerance for rotated pure-state formation entropy, while checking finite results and physical bounds. Null-space eigenvalue roundoff is amplified by square roots and varies between eigensolver backends.

Extract the existing concurrence-to-entropy calculation into a private helper and directly test clamping above one, below zero, and an interior value. Preserve the public API and numerical algorithm.

Validation on macOS: 36 entropy unit tests, 16 core regression tests, and 1205 Python QIS tests passed against a freshly built extension. Formatting, Ruff, and Clippy checks passed. Windows and Linux CI verification remains pending.
Fix QIS numerical edge cases and support Hamiltonian copy protocols
chore: bump release versions to beta4
Preserve nonzero affine coefficients, near-unit scales and cancellation
residues in Parameter arithmetic and simplification. Divide coefficients
directly to retain representable quotients with subnormal divisors.

Evaluate constant expressions before approximate symbolic simplification
and retain small numeric phase and rotation residues in canonicalization.
Add regression tests for scaling, substitution, cancellation, division and
canonicalization idempotence.
Construct ordered, unit-weight i(T - T†) generators with index validation.
Verify fermionic signs, particle-number conservation, Jordan-Wigner mapping
and independent evolution blocks against Fock-space calculations.

Project accepted imaginary roundoff residuals during Hermitian normalization
while retaining every nonzero real coefficient. Add regression coverage for
zero projection and small-coefficient symbolic evolution.
Emit each defining circuit's global phase inside CircuitGate and
circuit-backed UnitaryGate definitions so round trips preserve the full
unitary, including phase.

Add Rust and Python regressions for fixed and symbolic phases, nested and
repeated calls, local parameters, and explicit GPhase operations alongside
phase metadata.
Validate distinct targets in the shared two-qubit and multi-qubit checks before
running gate kernels, clearing Kraus output, or applying noise. Reuse the existing
invalid-parameter error and include the duplicate index in the diagnostic.

Add Rust regressions for gate, custom-matrix, Kraus, and noisy paths that verify
rejection leaves the full density matrix unchanged, including middle-qubit targets.

Validation: 134 density-matrix-related Rust tests passed. The preceding full
workspace run passed 4080 tests; the production fix is unchanged since that run.
Verify Python raises ValueError and the C ABI returns -8 for duplicate targets,
with the complete density matrix unchanged. Compare valid ordered-target results
against independently constructed full-matrix expectations.

Include the standalone C host test in staged SDKs and register static and shared
CTest suites. Update the SDK documentation to describe the additional coverage.

Validation: 103 Python regressions passed; development and release SDK workflows
each passed all 6 CTests. Workspace Clippy and formatting checks passed.
…order

Share matrix evaluation between instruction and full-circuit paths, preserving global phase and gate-local argument ordering. Validate parameter arity and finite values without mutating frozen definitions.

Add Rust, Python, and C regression coverage for parameter binding, sparse and permuted qubits, nested and inverse gates, and commutation classification.
Generate MSB-first matrices at the instruction boundary while preserving the public definition matrix convention. Cover commutation, positional qubit order, parameter binding, global phase, and explicit matrix precedence.
fix: correct circuit and simulation semantics for beta6
Separate roundoff-scale boundary normalization from unitarity tolerance. Preserve local SU(2) factors and global phase when selecting the positive-c boundary representative, and accept signed c for valid interior coordinates.

Add regressions across synthesis backends, caches, device-aware compilation, control flow, and Python/C interfaces. Bump the synthesis algorithm revision.
fix(compile): canonicalize KAK Weyl boundary representatives
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.
fix: correct circuit state handling, QASM serialization, and gate semantics
fix(qasm2): preserve qubit order and define exported gates
chore(release): bump versions to beta 7
@jianjian01
jianjian01 merged commit cf850a9 into cq-lib:develop Nov 26, 2026
8 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