Skip to content

fix: support openqasm3 1.0.2 alongside 1.0.1 - #475

Merged
TheGupta2012 merged 6 commits into
qBraid:mainfrom
HVSharma12:bugfix-openqasm3-1.0.2
Nov 19, 2026
Merged

TheGupta2012 merged 6 commits into
qBraid:mainfrom
HVSharma12:bugfix-openqasm3-1.0.2

Conversation

@HVSharma12

@HVSharma12 HVSharma12 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary of changes

openqasm3 1.0.2 broke loads() in a few ways. This makes pyqasm work with it, and 1.0.1 keeps working. Fixes #472.

  • OpenQASM 2 programs load again. loads() passes ignore_version=True when openqasm3.parse accepts it, as Ryan Hill suggested in loads() fails on every OpenQASM 2 program with openqasm3 1.0.2 #472, and pyqasm still checks the version itself. I check the signature instead of raising the minimum to 1.0.2. With 1.0.2, openpulse 1.0.1 cannot parse assignments in cal blocks, and qbraid-runtime-api pins 1.0.1 for now. A floor can follow once a fixed openpulse is out.
  • Syntax errors name the offending token again. 1.0.2 raises QASM3ParsingError("parse failed"), so describe_parse_error now looks for the ANTLR token first. The test that built the error without a message now passes one.
  • nop is its own statement in 1.0.2. pyqasm unrolls it to one nop per operand qubit through the same gate path as before, so the output is unchanged, also inside gate definitions, and nop; with no operands unrolls to nothing.
  • openqasm3 1.0.2 now parses a measurement call such as measure_iq q[0]. pyqasm raises a ValidationError for it instead of an AttributeError.
  • With openpulse 1.0.1 and openqasm3 1.0.2, an assignment in a cal or defcal block now raises a ValidationError that names the version mismatch instead of a raw AttributeError from inside openqasm3.
  • The code-coverage job runs the suite a second time on openqasm3 1.0.1, installed from a hash-locked file in .github/requirements/, so the 1.0.1 code paths stay tested until pyqasm requires 1.0.2.

Four OpenPulse tests fail with 1.0.2 because openpulse 1.0.1 bundles an older copy of the qasm3 grammar (openqasm/openpulse-python#42). They are marked xfail only while the installed openpulse cannot parse an assignment in a cal block, so they run again as soon as a fixed openpulse is installed. I sent the grammar update to openpulse in openqasm/openpulse-python#44.

On a fresh install with openqasm3 1.0.2, tox -e format-check passes and the suite has 1055 passed, 3 skipped and 4 xfailed. With 1.0.1, 1056 pass and 6 skip.

@argus-eye

argus-eye Bot commented Nov 17, 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: 16
  • Diff lines (±): 246
  • 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

codecov-commenter commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.91837% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyqasm/transformer.py 94.73% 1 Missing ⚠️
src/pyqasm/visitor.py 95.23% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@TheGupta2012 TheGupta2012 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested

The openqasm3 1.0.2 fixes work, and the suite passes on both 1.0.1 and 1.0.2. Three items remain before merge.

Findings

All findings are posted inline on the relevant lines. Checklist:

  • M1 — Drop commit 8dee03a and its CHANGELOG line; the change now lives in #479
  • M2 — CI runs only openqasm3 1.0.2, so nothing guards the 1.0.1 branches
  • M3 — pyqasm[pulse] on openqasm3 1.0.2 leaks a raw AttributeError from cal blocks

How it was tested

  • Two Python 3.12 venvs with pip install -e ".[test,pulse,cli,visualization]", openqasm3 pinned to 1.0.1 or 1.0.2, openpulse 1.0.1 in both.
  • PR head 725e2ff with openqasm3 1.0.1: pytest tests gives 1054 passed, 6 skipped.
  • PR head with openqasm3 1.0.2: 1053 passed, 3 skipped, 4 xfailed.
  • Base d8680f7 with openqasm3 1.0.2: 126 failed, 921 passed. Base with 1.0.1: 1047 passed.
  • black, isort and pylint (10.00/10) pass. mypy passes under both versions.
  • Probes under both versions gave the same output wherever both parse: QASM 2 load, 3.2 and 4.0 rejection, syntax, EOF and lexer error messages, nop in box/for/if/def/gate bodies, nop $0, measurement calls, and depth(), remove_idle_qubits() and reverse_qubit_order() on a program with nop.

Next steps

Drop 8dee03a now and rebase on main after #479 merges (M1). Address M2 and M3 before merge.

Comment thread CHANGELOG.md Resolved
Comment thread src/pyqasm/entrypoint.py Resolved
Comment thread tests/utils.py Resolved
@HVSharma12
HVSharma12 force-pushed the bugfix-openqasm3-1.0.2 branch from f31697b to 3baf28d Compare November 18, 2026 06:38
@HVSharma12

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review! I dropped the runner commit, added a test run on openqasm3 1.0.1 and the cal block case now gives a proper ValidationError that explains the version mismatch. I used a hash-locked requirements file for the 1.0.1 install so Scorecard stays happy, but happy to switch to a plain pin if you prefer. I'll rebase once #479 is in.

Pass ignore_version when parse() accepts it so OpenQASM 2 loads again, find the syntax error token
behind 1.0.2's "parse failed", unroll the new nop statement as before and reject measurement calls.
Fixes qBraid#472.

Suggested-by: Ryan Hill <ryanjh88@gmail.com>
Signed-off-by: HVSharma12 <harshvardhan.sharma@suse.com>
Signed-off-by: HVSharma12 <harshvardhan.sharma@suse.com>
The coverage job resolves openqasm3 1.0.2, so nothing ran the 1.0.1 code paths. The new step
installs 1.0.1 from a hash-locked file, like the other workflow tools, and runs the suite again.

Signed-off-by: HVSharma12 <harshvardhan.sharma@suse.com>
openpulse 1.0.1 with openqasm3 1.0.2 raised a raw AttributeError for any assignment in a cal or
defcal block. Both parse calls now raise a ValidationError that names the version mismatch.

Signed-off-by: HVSharma12 <harshvardhan.sharma@suse.com>
@TheGupta2012

TheGupta2012 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Hi @HVSharma12 , can you rebase? The PR #479 just merged and with your change, CI should pass now

@HVSharma12
HVSharma12 force-pushed the bugfix-openqasm3-1.0.2 branch from 3baf28d to 57453d1 Compare November 18, 2026 08:08
@HVSharma12

Copy link
Copy Markdown
Contributor Author

Rebased on main now that #479 is in. I ran the full CI on my fork with this exact commit and everything passes, including the new 1.0.1 step on macos-15.

Comment thread src/pyqasm/visitor.py Resolved
Comment thread src/pyqasm/visitor.py Resolved
Comment thread src/pyqasm/visitor.py Resolved

@TheGupta2012 TheGupta2012 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some more comments @HVSharma12 , could you please take a look and change accordingly? I think we should be good to merge post this.

I have also added #481 as a follow up once the openpulse change merges so that we can cleanly upgrade the version and remove the openqasm3==1.0.1 backward compatibility code.

nop_as_gate_calls and expand_nop_statements read no visitor state, so they are static
methods of Qasm3Transformer now. The visitor keeps _visit_nop and calls them.

Signed-off-by: HVSharma12 <harshvardhan.sharma@suse.com>
The message is written at the two raise sites instead of in a module constant.

Signed-off-by: HVSharma12 <harshvardhan.sharma@suse.com>
@HVSharma12

Copy link
Copy Markdown
Contributor Author

Done, both nop helpers are now static methods on Qasm3Transformer and the openpulse message is written inline where it is raised. Thanks for opening #481 as the follow up.

@TheGupta2012 TheGupta2012 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @HVSharma12 for working on this, lgtm!

@TheGupta2012
TheGupta2012 merged commit 6fc83a2 into qBraid:main Nov 19, 2026
13 checks passed
TheGupta2012 added a commit that referenced this pull request Nov 19, 2026
Correct the #462 broadcast example, which showed the old output as the
new one. List cphaseshift and cv under the #459 inverse fix, link #481
from the #475 known issue, say drawer instead of printer in the #458
entry, and put each period after its PR link.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

loads() fails on every OpenQASM 2 program with openqasm3 1.0.2

3 participants