Make U honour its documented matrix and define the phase-gate family exactly - #616
Open
ciaranra wants to merge 1 commit into
Open
Make U honour its documented matrix and define the phase-gate family exactly#616ciaranra wants to merge 1 commit into
ciaranra wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #615 (which is stacked on #601); review those first.
Summary
The
ArbitraryRotationGateable::udoc comment states the standard OpenQASM matrix, but the default implementation wasrz(lambda).ry(theta).rz(phi), which differs from that matrix byexp(-i(phi+lambda)/2). The universal gate therefore executed phase-wrong on every amplitude-carrying simulator that inherited the default. Separately, both QASM includes loweredp,phase, andu1torz, which is wrong byexp(i*lambda/2): the standard definition isu1(lambda) = U(0,0,lambda) = diag(1, exp(i*lambda)).This PR makes
Uhonour its own documented matrix and defines the phase-gate family in terms of it, giving the exact identitieswith
RZ(theta) = exp(-i*theta/2) p(theta)documented as the bridge. The rotation family RX/RY/RZ is unchanged.Changes
Unow implementsexp(i(phi+lambda)/2) RZ(phi) RY(theta) RZ(lambda), with the scalar carried through amplitude representations. The four state-vector simulators with directUimplementations were verified phase-exact and left unchanged;StateVecSoA32, the GPU state vectors,CuStateVec,StabVec,StabMps, andMastreceived exact handling.p,phase, andu1lower toU(0,0,lambda)in both includes.cp,cu1, andcphasewere verified column-by-column as exactlydiag(1,1,1,exp(i*lambda))— controlled constructions are where these phases become observable, so this was checked rather than assumed.R1XYwas 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.StabVec, both fixed:CliffordFrame::is_diagonalaccepted frames that send Z to -Z (X and Y counted as diagonal), and reset did not clear frame state.Mutation evidence
Restoring the old
rz.ry.rzdefault fails all fourUguards:U(0,0,pi/4)carriesexp(-i*pi/8),U(0,0,pi/2)carriesexp(-i*pi/4),U(0,0,pi)carriesexp(-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. Restoringptorzfails all four QASM guards with a structural witness observing RZ instead of U.Verification
pecos-simulators,pecos-qasm,pecos-stab-tn; clippy--all-targets -D warningson all five touched crates;cargo fmt --check;git diff --check.