Limitation
The classical instructions chapter defines: "The statement
end; immediately terminates the program, no matter what scope it appears in."
pyqasm has no handler for openqasm3.ast.EndStatement and falls through to the generic
unsupported-statement error.
Example QASM failure
OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
h q[0];
end;
ValidationError: Unsupported statement of type <class 'openqasm3.ast.EndStatement'>
Inside a branch, which is the form that carries real meaning:
OPENQASM 3.0;
int[8] i = 0;
if (i == 0) { end; }
// ValidationError: Unsupported statement of type <class 'openqasm3.ast.EndStatement'>
Change Requested
- Accept
end; wherever a statement is allowed — global scope, loop bodies, if/else
blocks, switch cases, box bodies, and subroutine bodies.
- At global scope, stop visiting subsequent statements: everything after
end; is
unreachable and must not appear in the unrolled output.
- Preserve
end; through dumps().
- Inside a conditional block whose condition depends on a runtime value,
end; cannot be
resolved at analysis time. Emit it into the unrolled output as-is rather than attempting to
truncate the program.
Implementation Details
- Add an
EndStatement branch to the statement dispatch in src/pyqasm/visitor.py; the
current fallback that raises is at visitor.py:3492.
- The unconditional global-scope case is the simple one: set a flag and stop consuming
statements at that level.
- Consider whether
QasmModule should expose that the program contains a terminating end; —
it is the kind of fact the existing has_measurements() / has_barriers() helpers report,
and downstream consumers may want it.
- Sanity-check the depth and qubit-count bookkeeping: statements after a global
end; must
not contribute, since they are unreachable.
- Tests:
tests/qasm3/test_statements.py — end; at global scope with trailing statements
that must be dropped, end; inside if, inside a for body, inside a subroutine, and a
dumps() round-trip.
Limitation
The classical instructions chapter defines: "The statement
end;immediately terminates the program, no matter what scope it appears in."pyqasmhas no handler foropenqasm3.ast.EndStatementand falls through to the genericunsupported-statement error.
Example QASM failure
Inside a branch, which is the form that carries real meaning:
Change Requested
end;wherever a statement is allowed — global scope, loop bodies,if/elseblocks,
switchcases,boxbodies, and subroutine bodies.end;isunreachable and must not appear in the unrolled output.
end;throughdumps().end;cannot beresolved at analysis time. Emit it into the unrolled output as-is rather than attempting to
truncate the program.
Implementation Details
EndStatementbranch to the statement dispatch insrc/pyqasm/visitor.py; thecurrent fallback that raises is at
visitor.py:3492.statements at that level.
QasmModuleshould expose that the program contains a terminatingend;—it is the kind of fact the existing
has_measurements()/has_barriers()helpers report,and downstream consumers may want it.
end;mustnot contribute, since they are unreachable.
tests/qasm3/test_statements.py—end;at global scope with trailing statementsthat must be dropped,
end;insideif, inside aforbody, inside a subroutine, and adumps()round-trip.