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]]