Skip to content

Measurement inside box cannot access outer-scope classical register #302

@ryanhill1

Description

@ryanhill1

Description

When a QuantumMeasurementStatement is inside a box block, pyqasm cannot find the classical register that was declared in the outer scope.

Reproduction

from pyqasm import loads

qasm = """
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
box {
    h q[0];
    c[0] = measure q[0];
}
"""

m = loads(qasm)
m.unroll()
# Error: Missing clbit register declaration for 'c' in QuantumMeasurementStatement

Expected Behavior

The measurement inside the box should be able to reference the classical register c declared in the outer scope, since QASM 3 box blocks inherit the enclosing scope.

Actual Behavior

Error at line 5, column 14 in QASM file
 >>>>>> c[0] = measure q[0];
Missing clbit register declaration for 'c' in QuantumMeasurementStatement

Notes

Qubit registers declared in the outer scope ARE accessible from within boxes (e.g., h q[0] works). Only classical register lookups fail.

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