Skip to content

Fix QASM2 if conditions#713

Open
david-pl wants to merge 6 commits intomainfrom
david/707-qasm2-bugfix
Open

Fix QASM2 if conditions#713
david-pl wants to merge 6 commits intomainfrom
david/707-qasm2-bugfix

Conversation

@david-pl
Copy link
Collaborator

@david-pl david-pl commented Feb 25, 2026

Closes #707.

Changes:

  • Add a deprecation warning to qasm2.extended.
  • Properly handle more lenient syntax such as creg[0] == 1 when running PyQrack.
  • Disallow anything but creg: Creg == x: int when trying to emit QASM2.
  • Allow only x == y if both x and y are int | Bit | Creg anywhere using QASM2.

The issue with the more extensive syntax for emitting is that we don't have the runtime values. So you can't coerce e.g. creg[0] == 1 into a creg == x where x is an appropriate integer. This generally begs the question whether we want to support this kind of syntax since it is now support in some places, which might be confusing to users.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 25, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11254 9935 88% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/bloqade/pyqrack/device.py 80% 🟢
src/bloqade/pyqrack/qasm2/core.py 85% 🟢
src/bloqade/qasm2/analysis/_init_.py 100% 🟢
src/bloqade/qasm2/analysis/validation/analysis.py 90% 🟢
src/bloqade/qasm2/dialects/indexing.py 85% 🟢
src/bloqade/qasm2/emit/target.py 81% 🟢
src/bloqade/qasm2/groups.py 98% 🟢
src/bloqade/qasm2/parse/lowering.py 76% 🟢
TOTAL 87% 🟢

updated for commit: c553a1c by action🐍

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 88.73239% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/bloqade/pyqrack/qasm2/core.py 80.00% 5 Missing ⚠️
src/bloqade/qasm2/analysis/validation/analysis.py 91.89% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Roger-luo
Copy link
Collaborator

maybe to add some context - originalnly I supported the syntax creg[0] etc. because this is quite natural and convenient to use but this is not strictly the QASM2 specification, which is why this PR have to address the mismatch. As a side note, we are trying to support these convenient syntax for now but maybe we should just remove the support in the future if most usage goes to python kernel eventually.

@david-pl david-pl marked this pull request as ready for review February 26, 2026 09:04
@david-pl david-pl requested a review from Roger-luo February 26, 2026 09:04
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.

PyQrack simulator does not support classical control flow

2 participants