Skip to content

Move QASM 2 printing into its own module - #454

Merged
TheGupta2012 merged 2 commits into
qBraid:mainfrom
danielgaskins:refactor/qasm2-printer
Nov 2, 2026
Merged

TheGupta2012 merged 2 commits into
qBraid:mainfrom
danielgaskins:refactor/qasm2-printer

Conversation

@danielgaskins

@danielgaskins danielgaskins commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary of changes

Moves Qasm2Printer and conditional-branch normalization into pyqasm/printer.py, leaving qasm2.py focused on program handling. Validation and printing share the same normalization, and normalized branches have named fields.

The drawing-module rename from #461 is now on main. Drawing stays in pyqasm.visualization, with pyqasm.draw unchanged. This PR adds a changelog entry for the QASM printer refactor; the drawing API entry is already upstream.

Closes #447.

All 1,033 tests pass with three existing skips. Before/after comparisons match exactly for output and error messages across 16 branch and transformation cases. Black, isort, Pylint, mypy, license headers and the Sphinx build with warnings treated as errors pass. Wheel and source-archive contents are checked, and a wheel smoke check covers imports, conditional validation and printing.

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

argus-eye Bot commented Oct 14, 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 (±): 723
  • Historical avg: ~350.7k tokens · ~$1.38 · across last 13 review(s)

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

@coderabbitai

coderabbitai Bot commented Oct 14, 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
  • Source mode: Auto
  • Repository: qBraid/pyqasm
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 7fd5e7e
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c701c639-74d2-4567-aecb-ad5327352b06

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
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@codecov-commenter

codecov-commenter commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.83673% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyqasm/printer.py 91.42% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@TheGupta2012

Copy link
Copy Markdown
Member

Thanks for the refactor @danielgaskins! While the idea is correct, I personally think that keeping modules/ limited to just QASM2 and QASM3 will help in maintaining clarity.

Can you please move all the code that you have developed in qasm2_printer.py into printer.py inside the base pyqasm directory? We can then rename printer.py to visualization.py as it only contains the code for drawing out circuits.

You will also need to update the references to the printer.py module inside the pyqasm directory. I recommend opening a PR for just refactoring that module to visualization.py and then moving current printer utilities into printer.py. This will ensure that scope for this PR is limited and that we are keeping the code maintainable going ahead .

@danielgaskins

Copy link
Copy Markdown
Contributor Author

Opened the drawing-module rename separately, as requested. Once it lands, I'll move the QASM printer into pyqasm/printer.py here. Both steps pass the full test suite locally.

@TheGupta2012

Copy link
Copy Markdown
Member

@danielgaskins I have approved your pull request for moving the printer into visualization. Can you please edit this PR accordingly? Thanks!

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

Copy link
Copy Markdown
Contributor Author

Moved the QASM printer to pyqasm/printer.py on top of current main. The drawing API changelog entry is already there; I added one for the printer refactor. All 1,033 tests pass with the same three skips, and output/error comparisons are unchanged across 16 cases. Style, type, header and docs checks pass too.

@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 your work on this! The changes lgtm.

@TheGupta2012
TheGupta2012 merged commit f7bbdee into qBraid:main Nov 2, 2026
14 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.

Move the QASM 2 printer and its branch pre-processing out of qasm2.py

3 participants