You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TwoQubitWeylDecomposition.circuit() has the wrong global phase for about half of all unitaries #17401
TwoQubitWeylDecomposition(U).circuit() reproduces U only up to a global phase, and the phase is wrong by exactly pi (the circuit equals -U) for roughly half of Haar-random 4x4 unitaries. The decomposition's own attributes (K1l, K1r, K2l, K2r, a, b, c, global_phase) reassemble U exactly, so only circuit() is affected.
How can we reproduce the issue?
importnumpyasnpfromqiskit.quantum_infoimportOperator, random_unitaryfromqiskit.synthesisimportTwoQubitWeylDecompositionbad=0forseedinrange(2000):
u=random_unitary(4, seed=seed).datav=Operator(TwoQubitWeylDecomposition(u).circuit()).databad+=np.abs(u-v).max() >1e-9print(bad, "of 2000") # 1017 of 2000# one failing caseu=random_unitary(4, seed=5).datav=Operator(TwoQubitWeylDecomposition(u).circuit()).dataprint(np.angle(np.trace(v.conj().T @ u))) # -3.14159... (u = -v)print(np.abs(u+v).max()) # ~1e-15
What should happen?
Operator(TwoQubitWeylDecomposition(U).circuit()) equals U including its global phase, as the attributes do.
Any suggestions?
In crates/synthesis/src/two_qubit_decompose/weyl_decomposition.rs, TwoQubitWeylDecomposition::circuit. The phase of each single-qubit Euler sequence is added to global_phase, but the code adds c2r.global_phase a second time where c1r.global_phase is meant (line ~1143), and c1l.global_phase is never added:
for gate in c1r.gates{ ...}global_phase += c2r.global_phase;// should be c1r.global_phase
...for gate in c1l.gates{ ... }
gate_sequence.set_global_phase_f64(global_phase);// c1l.global_phase is missing
Activity
ShellyGarion commentedon Nov 3, 2026
Ziqi (Adam) CHEN (@ChenziqiAdam) - thanks for reporting this bug and suggesting the solution. would you also like to open a PR to fix it?