Unable to perform mid-circuit measurements using the PennyLane-Qiskit plugin

Hello, I’m trying to perform mid-circuit measurements on IBM, but I encountered this error. I investigated the issue but couldn’t find the cause.

import pennylane as qml
from qiskit_ibm_runtime import QiskitRuntimeService

dev = qml.device("qiskit.remote", wires=3, shots=SHOTS,backend=backend)

def test_circuit():
    qml.Hadamard(0)
    m = qml.measure(0)
    qml.cond(m, qml.PauliX)(1)
    return qml.probs(wires=[0, 1])

print(qml.QNode(test_circuit, dev, mcm_method="one-shot")())

If you want help with diagnosing an error, please put the full error message below:

Cell In[9], line 10
      7     qml.cond(m, qml.PauliX)(1)
      8     return qml.probs(wires=[0, 1])
---> 10 print(qml.QNode(test_circuit, dev, mcm_method="one-shot")())

File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pennylane/workflow/qnode.py:905, in QNode.__call__(self, *args, **kwargs)
    903 if qml.capture.enabled():
    904     return capture_qnode(self, *args, **kwargs)
--> 905 return self._impl_call(*args, **kwargs)

File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pennylane/workflow/qnode.py:881, in QNode._impl_call(self, *args, **kwargs)
    878 # Calculate the classical jacobians if necessary
    879 self._transform_program.set_classical_component(self, args, kwargs)
--> 881 res = qml.execute(
    882     (tape,),
    883     device=self.device,
    884     diff_method=self.diff_method,
    885     interface=interface,
    886     transform_program=self._transform_program,
    887     gradient_kwargs=self.gradient_kwargs,
    888     **self.execute_kwargs,
    889 )
    890 res = res[0]
...
    398     # if isinstance(op, qml.MidMeasureMP):
    399     #     return [op]
--> 400     return op.decomposition()

AttributeError: 'MidMeasureMP' object has no attribute 'decomposition'
Name: PennyLane
Version: 0.40.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing-extensions
Required-by: PennyLane-qiskit, pennylane-snowflurry, PennyLane_Lightning

Platform info:           macOS-15.2-arm64-arm-64bit
Python version:          3.12.3
Numpy version:           1.26.4
Scipy version:           1.13.0
Installed devices:
- default.clifford (PennyLane-0.40.0)
- default.gaussian (PennyLane-0.40.0)
- default.mixed (PennyLane-0.40.0)
- default.qubit (PennyLane-0.40.0)
- default.qutrit (PennyLane-0.40.0)
- default.qutrit.mixed (PennyLane-0.40.0)
- default.tensor (PennyLane-0.40.0)
- null.qubit (PennyLane-0.40.0)
- reference.qubit (PennyLane-0.40.0)
- qiskit.aer (PennyLane-qiskit-0.40.0)
- qiskit.basicaer (PennyLane-qiskit-0.40.0)
- qiskit.basicsim (PennyLane-qiskit-0.40.0)
- qiskit.remote (PennyLane-qiskit-0.40.0)
- lightning.qubit (PennyLane_Lightning-0.40.0)

Hi @Antoine_Lemelin ,

It does look like there’s no logic at the moment to allow mid-circuit measurements to work with qiskit.remote.
From what I’ve found so far it looks like PennyLane is treating the MCM as a normal operator and trying to decompose it (which doesn’t work).
So I don’t think it should be too complicated to find a workaround for this, but I’m not entirely sure.
I’ve forwarded this to the team to take a look. I’ll get back to you with any additional info I get.

Thanks for making us aware of this!

Hi @Antoine_Lemelin ,

I’ve created a bug report for this issue. We don’t know yet how much work is required to get this working so we don’t know how long it will take to fix it. I’ll keep you updated. Feel free to add any additional ideas or thoughts on the GitHub bug report so that the team can see it.

Thanks again for reporting this issue!