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
[FEATURE] Decompose p, phaseshift and u1 as rz instead of h; rx; h #469
unroll decomposes p, phaseshift and u1 into three gates, h; rx(θ); h. A single rz(θ) gives the same gate up to a global phase. The longer form then grows during rebase, because each h expands again:
importpyqasmfrompyqasm.elementsimportBasisSetsrc='OPENQASM 3.0;\ninclude "stdgates.inc";\nqubit[1] q;\np(pi/4) q[0];\n'm=pyqasm.loads(src)
m.rebase(BasisSet.CLIFFORD_T)
print(pyqasm.dumps(m)) # h q[0]; h q[0]; t q[0]; h q[0]; h q[0];
OpenQASM 2 programs that use qelib1.inc unroll p and u1 the same way.
A related point: #468 adds a p rule to rebase. Unroll rewrites a p gate written by the user before rebase sees it, so that rule only applies to the p gates that pyqasm generates itself.
Done when:
A single p(θ), phaseshift(θ) or u1(θ) unrolls to one gate.
Under CLIFFORD_T, p(pi/4) rebases to t and p(pi/2) rebases to s.
The unitary of each changed decomposition, including csx and rccx, still matches the original up to a global phase.
Implementation (Optional)
One option is to make phaseshift_gate emit rz(θ). gate_decompositions.md documents the current form and needs the same update. rz(θ) and p(θ) differ only by a global phase. That should be safe here, because ctrl @ p resolves to cp before this decomposition runs. This reasoning is not verified against the full test suite.
Activity