Skip to content

qasm2 serializer emits OpenQASM 3-style braced if-blocks (invalid QASM 2) #337

Description

@rryoung98

Found while capability-testing the Quantinuum Nexus runtime integration.

Round-tripping a valid OpenQASM 2 program containing a classical conditional through pyqasm rewrites the conditional into OpenQASM 3 syntax while still declaring OPENQASM 2.0:

import pyqasm
qasm = '''OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg m[1];
creg c[2];
h q[0];
measure q[0] -> m[0];
if(m==1) x q[1];
measure q -> c;
'''
print(pyqasm.dumps(pyqasm.loads(qasm)))

emits:

...
if (m == 1) {
  x q[1];
}
...

Braced if-blocks are OpenQASM 3 grammar; QASM 2 only allows if(creg==int) <single statement>;. Downstream parsers (e.g. pytket's lark-based qasm2 reader used by the qBraid transpiler) reject the output: UnexpectedToken: Token('LBRACE', '{').

Impact: the qBraid SDK's device-run normalization pass uses pyqasm, so any user submitting a feed-forward (classically conditioned) qasm2 circuit to a qasm2-spec device has their valid program corrupted client-side and rejected server-side. Mid-circuit measurement + reset survives fine — only the conditional syntax breaks.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions