Delayed measurement condition judgment problem

I have encountered the following problem when applying delayed measurements:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_24286/1312210225.py in <module>
      1 pars = np.array([0.643, 0.246], requires_grad=True)
----> 2 my_quantum_function(*pars)

/opt/conda/lib/python3.9/site-packages/pennylane/qnode.py in __call__(self, *args, **kwargs)
    972 
    973         # construct the tape
--> 974         self.construct(args, kwargs)
    975 
    976         cache = self.execute_kwargs.get("cache", False)

/opt/conda/lib/python3.9/site-packages/pennylane/qnode.py in construct(self, args, kwargs)
    870             self.interface = qml.math.get_interface(*args, *list(kwargs.values()))
    871 
--> 872         self._tape = make_qscript(self.func, shots)(*args, **kwargs)
    873         self._qfunc_output = self.tape._qfunc_output
    874 

/opt/conda/lib/python3.9/site-packages/pennylane/tape/qscript.py in wrapper(*args, **kwargs)
   1529     def wrapper(*args, **kwargs):
   1530         with AnnotatedQueue() as q:
-> 1531             result = fn(*args, **kwargs)
   1532 
   1533         qscript = QuantumScript.from_queue(q, shots)

/opt/conda/lib/python3.9/site-packages/pennylane/transforms/qfunc_transforms.py in internal_wrapper(*args, **kwargs)
    178     @functools.wraps(fn)
    179     def internal_wrapper(*args, **kwargs):
--> 180         tape = make_qscript(fn)(*args, **kwargs)
    181         tape = tape_transform(tape, *transform_args, **transform_kwargs)
    182 

/opt/conda/lib/python3.9/site-packages/pennylane/tape/qscript.py in wrapper(*args, **kwargs)
   1529     def wrapper(*args, **kwargs):
   1530         with AnnotatedQueue() as q:
-> 1531             result = fn(*args, **kwargs)
   1532 
   1533         qscript = QuantumScript.from_queue(q, shots)

/tmp/ipykernel_24286/202903335.py in my_quantum_function(x, y)
      8     m_0 = qml.probs(wires=[1])
      9 
---> 10     qml.cond(m_0 > 0.5, qml.RY)(y, wires=0)
     11     return qml.probs(wires=[0])

TypeError: '>' not supported between instances of 'ProbabilityMP' and 'float'

​qml.measure β€” PennyLane 0.36.0 documentation

Hello @RX1

As you can see in the documentation, the argument m_0 of qml.cond needs to be the output of a mid-circuit measurement, performed through qml.measure. This is a measurement in the computational basis that gives 0 or 1. The argument of qml.cond cannot be a probability (i.e. the output of qml.probs). This is a use case we haven’t implemented yet.

This question is very useful for us to know what our users need! We will keep working on improving our mid circuit measurement capabilities.

Cheers,

Alvaro

1 Like