amazon-braket-sdk-python icon indicating copy to clipboard operation
amazon-braket-sdk-python copied to clipboard

Program class generates invalid OpenQASM (subroutine access to input variables)

Open ajberdy opened this issue 1 year ago • 0 comments

The following code is technically against the OpenQASM spec, as you can only close over global const variables (https://openqasm.com/language/scope.html#subroutine-and-gate-scope)

We may want to choose to interpret this as inputs allowed, since it's ambiguous whether those can change at runtime (be overwritten)

@aq.subroutine
def rx_alpha(qubit: int):
    rx(qubit, FreeParameter("alpha"))

@aq.main(num_qubits=3)
def parametric():
    rx_alpha(2)

expected = """OPENQASM 3.0;
def rx_alpha(int[32] qubit) {
    rx(alpha) __qubits__[qubit];
}
input float[64] alpha;
qubit[3] __qubits__;
rx_alpha(2);"""

ajberdy avatar Nov 28 '23 02:11 ajberdy