I am trying to save probability(to use it to calculate expectation value) after measuring one out of three qubits in a circuit and then performing some other operations on remaining two qubits. But can’t do that. Every time getting error message.
Example of the code that I tried is as follows:
import pennylane as qml
from pennylane import numpy as np
dev = qml.device("default.qubit", wires=3)
@qml.qnode(dev)
def func(theta):
qml.Y(0)
qml.RX(theta,wires=1)
qml.RZ(theta,wires=2)
m_0 = qml.measure([2])
s2=qml.probs(wires=[2])
m_1 = qml.measure([1], reset=True)
return s2
print(func(0.8))
Error message:
ValueError: ops operation measure(wires=[1]) must occur prior to measurements. Please place earlier in the queue.
Is it not possible to measure some of the qubits in a circuit(say n out of m with n<m), use the expectation value of those measurements(on n qubits) and using rest of the qubits(m-n) for some other operations?
I came across some qml.cond command in the documentation where one can perform some operations on one qubit(say 2nd qubit) conditioned on measurement outcome of the measured qubit(say 1st qubit). But as per my requirement the operations that I need to perform on 2nd qubit do not depend on the measurement outcome from 1st qubit.
Version of Pennylane used:0.37.0(as seen after running qml.about()).
It will be really helpful if I can get some way out to resolve my issue.
Thanks in advance.