EstimatorV2.__init__() got an unexpected keyword argument 'session'

Hello,

I want to upgrade my code and use the 0.38 version of the Qiskit plugin. I ran the code from The Remote device — PennyLane-Qiskit 0.38.0 documentation

Code:

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime.fake_provider import FakeManilaV2
backend = FakeManilaV2()
dev = qml.device(
    "qiskit.remote",
    wires=5,
    backend=backend,
    resilience_level=1,
    optimization_level=1,
    seed_transpiler=42
)
@qml.qnode(dev)
def circuit(x, y, z):
    qml.RZ(z, wires=[0])
    qml.RY(y, wires=[0])
    qml.RX(x, wires=[0])
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(wires=1))
circuit(0.2, 0.1, 0.3)

And I got the error:

File ~/pennylane-qiskit/lib/python3.12/site-packages/pennylane_qiskit/qiskit_device.py:646, in QiskitDevice._execute_estimator(self, circuit, session)
    643 # the Estimator primitive takes care of diagonalization and measurements itself,
    644 # so diagonalizing gates and measurements are not included in the circuit
    645 qcirc = [circuit_to_qiskit(circuit, self.num_wires, diagonalize=False, measure=False)]
--> 646 estimator = Estimator(session=session)
    648 pauli_observables = [mp_to_pauli(mp, self.num_wires) for mp in circuit.measurements]
    649 compiled_circuits = self.compile_circuits(qcirc)

TypeError: EstimatorV2.__init__() got an unexpected keyword argument 'session'

It’s from the documentation so I don’t know what to do…

About qml.about():

Name: PennyLane
Version: 0.38.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: /Users/christophe_pere/pennylane-qiskit/lib/python3.12/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane-qiskit, PennyLane_Lightning

Platform info:           macOS-15.0-arm64-arm-64bit
Python version:          3.12.6
Numpy version:           1.26.4
Scipy version:           1.14.1
Installed devices:
- qiskit.aer (PennyLane-qiskit-0.38.0)
- qiskit.basicaer (PennyLane-qiskit-0.38.0)
- qiskit.basicsim (PennyLane-qiskit-0.38.0)
- qiskit.remote (PennyLane-qiskit-0.38.0)
- lightning.qubit (PennyLane_Lightning-0.38.0)
- default.clifford (PennyLane-0.38.0)
- default.gaussian (PennyLane-0.38.0)
- default.mixed (PennyLane-0.38.0)
- default.qubit (PennyLane-0.38.0)
- default.qubit.autograd (PennyLane-0.38.0)
- default.qubit.jax (PennyLane-0.38.0)
- default.qubit.legacy (PennyLane-0.38.0)
- default.qubit.tf (PennyLane-0.38.0)
- default.qubit.torch (PennyLane-0.38.0)
- default.qutrit (PennyLane-0.38.0)
- default.qutrit.mixed (PennyLane-0.38.0)
- default.tensor (PennyLane-0.38.0)
- null.qubit (PennyLane-0.38.0)

I also tried with my own code and I obtained the same error

  File "/Users/christophe_pere/pennylane-qiskit/lib/python3.12/site-packages/pennylane_qiskit/qiskit_device.py", line 646, in _execute_estimator
    estimator = Estimator(session=session)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: EstimatorV2.__init__() got an unexpected keyword argument 'session'

I can observe the creation of a session in the IBM Quantum Interface:

But the message is:

Status details
Status
Completed
completed icon
Session marked as not accepting new jobs and all jobs already in a terminal state.

Hi @Christophe_Pere ,

My colleague Austin helped me find the source of this issue.

It seems like it’s due to a difference in the version of qiskit_ibm_runtime . The latest 0.30.0 dev release seems to have broken this keyword. The documentation suggests that the keyword should still be useable but they may have broken it accidentally. You can switch to the stable release of qiskit_ibm_runtime using pip install qiskit_ibm_runtime==0.29.0 and the issue should resolve itself.

Let me know if this works for you!

Hi @CatalinaAlbornoz

Thanks, it’s working when downgrading to 0.29.

1 Like