Preserve exact rotations in Clifford+T rebasing - #429
Conversation
Signed-off-by: Daniel Gaskins <danielgaskins99@gmail.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 ⚙️ Run configurationConfiguration used: Repository: qBraid/pyqasm/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Thanks for this — I checked the decompositions numerically: rx/ry/rz across n = -16..16 quarter-turns all match the exact rotation up to global phase, and crx/cry stay correct through the controlled path, where that global phase would otherwise become a relative one. Suite, pylint, mypy, black and isort green locally; CI green.
Two notes. N1 is inline.
N2 — please add a CHANGELOG entry under Fixed, referencing #428. It's user-visible in both directions: gates that were silently dropped now decompose, and angles that previously produced output now raise RebaseError — anyone upgrading needs the second half.
| if normalized_turns == 0: | ||
| return [] | ||
|
|
||
| if normalized_turns <= 4: |
There was a problem hiding this comment.
N1 — the two-gate branches here are never exercised.
I instrumented _get_clifford_t_rotation and ran the suite: normalized_turns only ever takes 0, 1, 2 and 7. That leaves 3, 4, 5 and 6 untested — including both composite sequences, n=3 -> s; t; and n=5 -> sdg; tdg;, which is exactly where an off-by-one in the // 2 / % 2 split would hide. Every currently tested case is single-gate or empty. Could you add rz(3*pi/4) and rz(5*pi/4)?
Separately, the tests assert gate strings rather than equivalence — swap s for sdg in the ry sequence and the suite still passes once the expected string is edited to match. One test that reconstructs the unitary and compares it to the exact rotation up to global phase would guard the whole table at once, and numpy is already a dependency. I verified the table is correct today (99/99 over n = -16..16, plus crx/cry through the controlled path), so this is about keeping it that way rather than anything being wrong now.
|
Thanks for checking this. I added the |
ryanhill1
left a comment
There was a problem hiding this comment.
Looks good from my end. I'll let @TheGupta2012 give final sign off before merge.
v1.2.1 shipped on 23 September 2026 carrying five Unreleased entries: three under Added (#370, #368, #427) and two under Other (#419). Those are removed and v1.2.1 joins the Past Release Notes list. Two entries stay, because they merged after the v1.2.1 tag and have not shipped: the `end;` statement support from #424 under Added, and the Clifford+T rotation fix from #429 under Fixed. They belong to the next release. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Closes #428
Summary of changes
rx,ry, andrzrotations at multiples of π/4 into exact Clifford+T sequencesRebaseErrorfor unsupported angles instead of silently dropping the gate