Skip to content

Unexpected output from dynamic allocation with sample measurement process #2339

@sengthai

Description

@sengthai

qml.allocate registers new auxiliary qubits, which are then deallocated after use.
In this circuit, when we apply an operation to an auxiliary qubit, it seems affect the original qubits.
It is supposed to return [0,0] ten times.

We expect this error to be caused by the runtime.

import qml.capture.enable()
    
@qml.qjit
@qml.qnode(qml.device("lightning.qubit", wires=3, shots=10))
def circuit():
    with qml.allocate(2) as qs:
        qml.X(qs[1])

    return qml.sample(wires=[0, 1])

Output:

[[0 0]
 [0 1]
 [0 0]
 [1 0]
 [0 0]
 [0 0]
 [0 1]
 [0 0]
 [1 0]
 [0 0]]

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