dumps() prints the original program when unroll() leaves at most one statement

Open Beginner friendly
#493 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ShiveshDragon is already working on this.

Since Nov 26, 2026.

  • #495 by @ShiveshDragon — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Read modules/base.py, especially QasmModule.__str__ and its handling of _unrolled_ast; the issue includes a minimal reproducer using loads(), unroll(), and dumps(). Check how the string output behaves when the unrolled AST has one statement, then verify that it preserves the unrolled result without restoring custom gate definitions or calls.

Written by the indexing model from the issue text.

Description

dumps() (through QasmModule.__str__) prints the unrolled AST only when it has more than one statement (if len(self._unrolled_ast.statements) > 1, modules/base.py). A program that unrolls down to just its register declaration therefore comes back as the original source, custom gate definitions and all.

from pyqasm import loads, dumps
m = loads("OPENQASM 3.0;\ngate g a { }\nqubit[1] q;\ng q[0];")
m.unroll()
[type(s).__name__ for s in m.unrolled_ast.statements]  # ['QubitDeclaration']
dumps(m)  # 'OPENQASM 3.0;\ngate g a {\n}\nqubit[1] q;\ng q[0];\n'

The caller asked for the unrolled program and gets output that still has gate definitions and calls to them. With #459, ctrl @ x on a custom identity x hits the same thing. A tool that unrolls first so that every custom gate is gone, and then imports the result into Qiskit, gets the custom x back, and Qiskit's ctrl @ turns it into a real CX.

__str__ could track whether unroll() has run instead of counting statements.

Dominant language
Python
Stars
29
Forks
33
Avg merge
1d 20h
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from qBraid/pyqasm

All issues in qBraid/pyqasm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.