catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Qrack cannot return catalyst mid-circuit measurements

Open yorgossot opened this issue 6 months ago • 3 comments

The following code

import pennylane as qml
from catalyst import qjit, measure


dev = qml.device("qrack.simulator", wires=3, shots=5)

@qjit()
@qml.qnode(dev, mcm_method="one-shot")
def circuit():
    qml.X(0)
    m_res = [measure(0), measure(1)]

    return [qml.sample(m) for m in m_res]

print(circuit())

gives:

[Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], dtype=int64), Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], dtype=int64)]

It created:

  • 2 IDENTICAL arrays (as many as the elements sampled)
  • each array containing the results of ALL 3 of the qubits reversed and then stacked for every shot. i.e. 1st shot (0, 0, 1,) 2nd shot(0, 0, 1) 3rd shot(0, 0, 1) 4th shot(0, 0, 1) 5th shot(0, 0, 1) gives Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], dtype=int64)

These values though are the result of some final measurement happening on all qubits at the end of the execution as resetting the qubit in state "1" gives:

import pennylane as qml
from catalyst import qjit, measure


dev = qml.device("qrack.simulator", wires=3, shots=5)

@qjit()
@qml.qnode(dev, mcm_method="one-shot")
def circuit():
    qml.X(0)
    m_res = [measure(0,True), measure(1)]

    return [qml.sample(m) for m in m_res]

print(circuit())

gives:

[Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int64), Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int64)]

tagging @josh146 related issue #1626

yorgossot avatar Apr 09 '25 15:04 yorgossot