Skip to content

AutoQASM generates OpenQASM which assumes subroutine access to input variables #7

@ajberdy

Description

@ajberdy

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);"""

Note that the generated rx_alpha subroutine references the alpha input variable, which is defined only at global scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions