I am trying to understand how to do mid circuit measurements in pennylane. As an example here is a simple preperation of a bell state:
import pennylane as qml dev = qml.device('default.qubit', wires=2) @qml.qnode(device=dev): def func(x): qml.Hadamard(0) qml.CNOT(wires=[0, 1]) return qml.state()
I would like to perform a measurement of qubit 0 for example, save that measurement and then continue operating on my circuit. I have tried using the
qml.measure method, also together with the conditional method
qml.cond(qml.measure(0), qml.Identity)(1), but apparently, although the conditional gate is shown in the circuit, the
qml.state() that is returned is still in the bell state and not a collapsed state, as it should be due to the measurement.
I have also tried using
qml.Projector in order to avoid measuring but that also didn't Project the qubit into the state I desired.
I would really appreciate if someone could explain me how I can measure a qubit in the middle of a circuit and store the measured value in pennylane. As said the methods I found didn't seem to collapse the wavefunction, so I believe they didn't really measure the qubit.
Thank you very much