Repository navigation
Decompose ccx, id and p when rebasing to ROTATIONAL_CX / CLIFFORD_T - #468
Conversation
rebase() raised RebaseError for ccx (kept as a single gate by unroll), for id, and for the p gates that the qelib1 c3x expands into. - add a 6-CNOT Toffoli rule for both basis sets, addressing the third operand through a new AppliedQubit.QUBIT3 - drop id in both basis sets - map p to rz (equal up to global phase); for Clifford+T reuse the exact rotation path, which still rejects non pi/4 multiples - pick rule qubits by AppliedQubit value instead of a two-qubit if/else Signed-off-by: Tony Coder <407243179@qq.com>
Argus reviewAuto-review is off for this repo. Tick the box below to run a review on this PR.
Estimated cost
Tip: you can also comment |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TheGupta2012
left a comment
There was a problem hiding this comment.
Thanks @tonycoder-hub for working on this, lgtm!
Summary of changes
rebase(BasisSet.ROTATIONAL_CX)andrebase(BasisSet.CLIFFORD_T)failed on a plainccx, because unroll keeps it as a single gate and neither basis had a rule for it. The same happened forid, and for the qelib1c3xunderROTATIONAL_CX, which unrolls intop(...)gates that weren't handled.Fixes #467
Changes:
h/t/tdgfor Clifford+T, thery/rx/rzequivalents for rotational-CX). Rules can now address a third operand through a newAppliedQubit.QUBIT3, and_get_qubits_for_gatepicks qubits by the enum value instead of the two-qubit if/else. Existing two-qubit rules behave the same.idis dropped in both basis sets.p(theta)isrz(theta)up to a global phase, soROTATIONAL_CXemitsrzwith the same argument. ForCLIFFORD_Tit goes through the existing exact rotation path, so multiples of pi/4 work and anything else still raisesRebaseError(soc3x-> Clifford+T is still rejected, as it should be with its pi/8 phases).Test plan
New tests in
tests/qasm3/test_rebase.py, checked numerically with the existing unitary helpers (equal up to global phase):ccxin both basis sets, in default order and with the target on a middle qubit, againstmcx_unitaryidin both basis sets leaves no gatesc3xrebased toROTATIONAL_CXagainstmcx_unitary(4)All 7 new cases fail on
mainwithRebaseErrorand pass with this change.pytest tests: 1022 passed, 3 skippedblack --check,isort --check-only: cleanpylint src/pyqasm tests/qasm3/test_rebase.py: 10.00/10mypy src/pyqasm: same single pre-existing error as onmain, nothing new