Skip to content

dynamic qubit allocation + subroutine + forloop fails #2263

@paul0403

Description

@paul0403
qml.capture.enable()

@subroutine
def flip(w1, w2, w3, theta):
    @qml.for_loop(0, 2, 1)
    def loop_rx(i, _theta):
        qml.X(w1)
        qml.Y(w2)
        qml.Z(w3)
        qml.ctrl(qml.RX, (w1, w2))(_theta, wires=0)
        return jnp.sin(_theta)
    _ = loop_rx(theta)

@qjit
@qml.qnode(qml.device("lightning.qubit", wires=1))
def circuit():
    with qml.allocate(2) as q1:
        with qml.allocate(3) as q2:
            flip(q1[0], q1[1], q2[2], 1.23)

    return qml.expval(qml.Z(0))

print(circuit())
RuntimeError: [/path/to/catalyst/runtime/lib/capi/RuntimeCAPI.cpp:1152][Function:__catalyst__rt__array_get_element_ptr_1d] Error in Catalyst Runtime: The qubit register does not contain the requested wire: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions