Repository navigation
fix(unroll): invert any standard gate exactly under inv @ - #492
Open
TheGupta2012 wants to merge 4 commits into
Open
TheGupta2012 wants to merge 4 commits into
TheGupta2012 wants to merge 4 commits into
Conversation
Parametrize over every gate in the unroll maps and compare the unitary of `inv @ g` with the adjoint of `g`, plus `inv @ inv @ g`, `pow(-1) @ g`, the literal repros from issues #473 and #476, and `inv @` on a custom gate whose body uses decomposed gates. The test simulator learns `swap`, `sxdg` and `nop` so `xy` and `xx_plus_yy` can be checked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`map_qasm_inv_op_to_callable` returned the forward decomposition for every two- and three-qubit gate, so `inv @ pswap`, `iswap`, `ms`, `ryy`, `xy`, `xx_plus_yy` and the `cp00`/`cp01`/`cp10` family silently unrolled to the gate itself (#473). It raised on every gate outside its small inverse tables, including `sx`, `sxdg`, `p`, `u`, `prx`, `gpi` and `gpi2` (#476), and `inv @ rxx` / `rzz` crashed on the `gphase` their decompositions emit. `inv @ g` now takes g's own decomposition, reverses it and inverts each emitted gate: self-inverse gates stay, `s`/`t`/`sx` swap with their dagger, and `rx`/`ry`/`rz`/`p`/`gphase` negate their angle. The U-form path from #459 still handles `inv @` on controlled gates, so `inv @ ctrl @ g` unrolls exactly as before for every gate. Self-inverse composites such as `c3x`, `cswap` and `ecr` now emit their decomposition reversed; the unitary is unchanged. Fixes #473, fixes #476. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…laces `u3_inv_gate`, `u2_inv_gate`, `U_INV_ROTATION_MAP`, `MULTI_CONTROLLED_X_INV_MAP` and `InversionOp` are dead now that `inv @` inverts the forward decomposition. `_rc3x_dg_gate` was that same reversal written out by hand, so `c4x` now calls `inverse_gate_list(rc3x_gate(...))` instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This branch has not been deployed
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.
Why
inv @gave a wrong circuit, with no error, for 13 standard gates such aspswap,iswapandcp00. It raised on 19 more, such assx,p,uandrxx. The inverse path kept hand-written tables per gate: two-qubit and three-qubit gates mapped back to their forward form, and gates outside the tables raised.What changed
inverse_gate_listinverts any decomposition: it reverses the gate list and inverts each primitive (negated angles forrx,ry,rz,pandgphase, daggers fors,tandsx). It raisesValidationErroron a primitive it cannot invert.inv @andpow(-n) @now invert the forward decomposition. The hand-written inverse tables andInversionOpare gone.inv @ ctrl @path from fix: support ctrl @ on any single-qubit standard gate #459 is unchanged.Scope
inv @,inv @ inv @andpow(-1) @.inv @ ctrl @still raises on the 21 gates with no U-form base, as onmain.nopas self-inverse. Whichever PR merges second drops the duplicate.Blast Radius
Unrolled text changes only for the gates that were wrong or raised, plus
ecr,cswap,c3x,c4xandrccx. Those five now emit the reversed decomposition, which is still exact, but their depth next to other gates can differ. qbraid and qbraid-qir import none of the removed names, and theirinv @test programs unroll byte-identical.Verification
main, 48 of 80 gates were exact. On this branch, all 80 are exact forinv @,inv @ inv @andpow(-1) @.inv @ ctrl @output is byte-identical tomainfor all 80.main. Full suite: 1386 passed with openqasm3 1.0.2, and 1387 passed with 1.0.1.tox -e format-checkpasses.inverse_gate_list, and float angles ininv @ u2.Closes #473
Closes #476