Skip to content

Make U honour its documented matrix and define the phase-gate family exactly - #616

Open
ciaranra wants to merge 1 commit into
t-matrix-convention-fixesfrom
u-phase-gate-exactness
Open

Make U honour its documented matrix and define the phase-gate family exactly#616
ciaranra wants to merge 1 commit into
t-matrix-convention-fixesfrom
u-phase-gate-exactness

Conversation

@ciaranra

Copy link
Copy Markdown
Member

Stacked on #615 (which is stacked on #601); review those first.

Summary

The ArbitraryRotationGateable::u doc comment states the standard OpenQASM matrix, but the default implementation was rz(lambda).ry(theta).rz(phi), which differs from that matrix by exp(-i(phi+lambda)/2). The universal gate therefore executed phase-wrong on every amplitude-carrying simulator that inherited the default. Separately, both QASM includes lowered p, phase, and u1 to rz, which is wrong by exp(i*lambda/2): the standard definition is u1(lambda) = U(0,0,lambda) = diag(1, exp(i*lambda)).

This PR makes U honour its own documented matrix and defines the phase-gate family in terms of it, giving the exact identities

p(0) = I,  p(pi/4) = T,  p(pi/2) = SZ,  p(pi) = Z

with RZ(theta) = exp(-i*theta/2) p(theta) documented as the bridge. The rotation family RX/RY/RZ is unchanged.

Changes

  • Default U now implements exp(i(phi+lambda)/2) RZ(phi) RY(theta) RZ(lambda), with the scalar carried through amplitude representations. The four state-vector simulators with direct U implementations were verified phase-exact and left unchanged; StateVecSoA32, the GPU state vectors, CuStateVec, StabVec, StabMps, and Mast received exact handling.
  • p, phase, and u1 lower to U(0,0,lambda) in both includes. cp, cu1, and cphase were verified column-by-column as exactly diag(1,1,1,exp(i*lambda)) — controlled constructions are where these phases become observable, so this was checked rather than assumed.
  • R1XY was audited for the same defect and does not have it: its outer RZ angles sum to zero, so the composition equals its documented matrix exactly. A column-exact test now locks that in.
  • Exact testing exposed two stale-cache defects in StabVec, both fixed: CliffordFrame::is_diagonal accepted frames that send Z to -Z (X and Y counted as diagonal), and reset did not clear frame state.
  • Phase-blind representations (tableau, density-matrix, propagation, compile-only) are unchanged, as is the rotation family.

Mutation evidence

Restoring the old rz.ry.rz default fails all four U guards: U(0,0,pi/4) carries exp(-i*pi/8), U(0,0,pi/2) carries exp(-i*pi/4), U(0,0,pi) carries exp(-i*pi/2), and the zero-angle case is caught by a scalar-hook witness (call count 0 against expected 1), since the matrices coincide at zero. Restoring p to rz fails all four QASM guards with a structural witness observing RZ instead of U.

Verification

  • Full debug and release suites for pecos-simulators, pecos-qasm, pecos-stab-tn; clippy --all-targets -D warnings on all five touched crates; cargo fmt --check; git diff --check.
  • Python suite: 4,677 passed. The 50 failures are all Selene TCP-stream, multiprocessing, and network-dependent doc-build tests denied sockets by the sandbox; the failure list was inspected and none touch simulator or phase paths.
  • GPU/CUDA suites compile in both profiles; runtime failures are the pre-existing no-hardware results (llvmpipe rejected, CUDA error 100), unchanged in count.
  • No trajectory, golden, or snapshot hash changed.

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