Skip to content

fix(unroll): keep nop when inverting a custom gate body - #485

Merged
TheGupta2012 merged 4 commits into
mainfrom
bugfix-477-inv-nop
Nov 19, 2026
Merged

TheGupta2012 merged 4 commits into
mainfrom
bugfix-477-inv-nop

Conversation

@TheGupta2012

Copy link
Copy Markdown
Member

Why

unroll() raised Unsupported / undeclared QASM operation: nop on inv @ g when the body of g contains nop. The inverse gate map had no entry for nop. A nop is its own inverse, so the inverted body should keep each nop.

What changed

  • nop joins SELF_INVERTING_ONE_QUBIT_OP_SET, so inv @ maps it to itself.
  • The visitor now reverses an inverted gate body before it splits a multi-operand nop. With openqasm3 1.0.2 the split came first, so the nops came out in the opposite order from 1.0.1.

Scope

  • Covers nop inside custom gate bodies under inv @, and pow(-n) @, which uses the same path.
  • ctrl @ on a gate whose body has nop still raises, as on main. A bare inv @ nop q; is a parse error with openqasm3 1.0.2, because its grammar treats nop as a statement.

Blast Radius

Only inputs that used to raise change. Every ctrl, inv @ ctrl and plain gate input gives the same output as on main.

Verification

  • New cases in test_nop_unrolls_per_operand fail on main and pass here, with openqasm3 1.0.1 and 1.0.2.
  • Full suite: 1221 passed with 1.0.2 and 1222 passed with 1.0.1. tox -e format-check passes.

Closes #477

@argus-eye

argus-eye Bot commented Nov 19, 2026

Copy link
Copy Markdown

Argus review

Auto-review is off for this repo. Tick the box below to run a review on this PR.

  • Trigger Argus review

Estimated cost

  • Files changed: 4
  • Diff lines (±): 19
  • Historical avg: ~337.1k tokens · ~$1.17 · across last 18 review(s)

Tip: you can also comment @argus-eye review at any time.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

TheGupta2012 and others added 4 commits November 19, 2026 12:35
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
map_qasm_inv_op_to_callable had no entry for nop, so inv @ on a custom
gate whose body contains nop raised ValidationError. nop is its own
inverse, so add it to SELF_INVERTING_ONE_QUBIT_OP_SET.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
openqasm3 1.0.2 parses nop as a statement, which the visitor split per
operand before reversing an inverted body. That put the nops of
inv @ g in the opposite order from 1.0.1. Reverse first, then split.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TheGupta2012
TheGupta2012 merged commit 95747c7 into main Nov 19, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unroll() rejects inv @ on a gate whose body contains nop

2 participants