Skip to content

Support OpenQASM end statements - #424

Merged
TheGupta2012 merged 3 commits into
qBraid:mainfrom
danielgaskins:fix/end-statement-support
Sep 24, 2026
Merged

TheGupta2012 merged 3 commits into
qBraid:mainfrom
danielgaskins:fix/end-statement-support

Conversation

@danielgaskins

Copy link
Copy Markdown
Contributor

Summary

  • accept OpenQASM 3 end; statements during validation and unrolling
  • stop statically unrolled blocks after an unconditional terminator
  • preserve conditional terminators inside runtime-dependent branches
  • cover global, branch, loop, switch, box, and subroutine behavior

Testing

  • pytest -q tests/qasm3/test_end.py
  • pytest -q tests
  • pytest -q --cov=pyqasm --cov-config=pyproject.toml --cov-report=term --cov-report=xml tests
  • pylint src tests bin examples
  • isort --check-only src tests bin examples
  • black --check --target-version py310 src tests bin examples
  • mypy src examples
  • qbraid admin headers src tests bin examples --skip=src/pyqasm/_version.py --type=apache
  • sphinx-build -W -b html docs/ <output-directory>

Fixes #396

Signed-off-by: Daniel Gaskins <danielgaskins99@gmail.com>
@argus-eye

argus-eye Bot commented Sep 10, 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: 2
  • Diff lines (±): 243
  • Historical avg: ~317.3k tokens · ~$0.95 · across last 12 review(s)

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

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: qBraid/pyqasm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 7806b2d1-f597-4acf-a989-725a5a957b49

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

Comment thread tests/qasm3/test_end.py Outdated
module.unroll()
output = dumps(module)

assert output.count("h q[0];") == 1

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.

Can you use already built test validators in our utilities? It seems like we already have a pretty extensive utility module built for these assertions.

Comment thread src/pyqasm/visitor.py Outdated
return [statement]

@classmethod
def _ends_with_end_statement(cls, statements: Sequence[qasm3_ast.Statement]) -> bool:

@TheGupta2012 TheGupta2012 Sep 21, 2026 •

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.

Why do you need all statements in this method as a parameter? I think we can just isolate the processing inside the analyser.py and refactor

@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.

Hi @danielgaskins , thanks for extending pyqasm with this contribution! I just gave a couple of comments but otherwise looks good. Can you also add a CHANGELOG entry besides these changes?

@danielgaskins

Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. I moved the termination check into Qasm3Analyzer and now pass it the last emitted statement. The end tests use check_unrolled_qasm, and I added a changelog entry for #396. I updated the branch from main too. The full suite passes with 869 tests and 3 skips, and lint and typing checks are clean.

@TheGupta2012
TheGupta2012 self-requested a review September 24, 2026 06:39

@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 @danielgaskins for the changes, they lgtm!

@TheGupta2012
TheGupta2012 merged commit e293994 into qBraid:main Sep 24, 2026
14 checks passed
TheGupta2012 added a commit that referenced this pull request Sep 25, 2026
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>
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.

end; statement is unsupported

3 participants