Error raised when introducing device noise from IBMQ into the optimization of variationa quantum circuit in pennylane

Hi, I recently try to employ the device noise model from IBMQ into the variational quantum circuit, but it failed. Here is the toy code.

import pennylane as qml
from pennylane.optimize import GradientDescentOptimizer
from pennylane import numpy as np
import qiskit
import qiskit_aer.noise as noise

def circuit(param, n_qubit):
    for j in range(n_qubit):
        qml.RZ(param[j, 0], wires=j)
        qml.RY(param[j, 1], wires=j)
        qml.RZ(param[j, 2], wires=j)

    # CNOT
    for j in range(0, n_qubit, 2):
        if j+1 < n_qubit:
            qml.CNOT(wires=[j, j+1])

    for j in range(1, n_qubit, 2):
        if j+1 < n_qubit:
            qml.CNOT(wires=[j, j+1])
    return qml.expval(qml.PauliZ(n_qubit-1))

if __name__ == '__main__':
    n_qubit = 4
    provider = qiskit.IBMQ.providers(group='open')[0]
    backend = provider.get_backend('ibmq_quito')
    noise_model = noise.NoiseModel.from_backend(backend)
    dev = qml.device('qiskit.aer', wires=n_qubit, noise_model=noise_model)
    qnode = qml.QNode(circuit, dev)

    opt = GradientDescentOptimizer(0.1)

    param = 2*np.pi*np.random.random((n_qubit, 3))
    param = opt.step(lambda p: qnode(p, n_qubit), param)

The error information is as follows.

File "/usr/lib/python3.10/", line 79, in inner
    return func(*args, **kwds)
  File "/home/xxx/.local/lib/python3.10/site-packages/pennylane_qiskit/", line 467, in batch_execute
    res = self.statistics(circuit)
  File "/home/xxx/.local/lib/python3.10/site-packages/pennylane/", line 738, in statistics
    if obs.return_type is Expectation:
AttributeError: 'RZ' object has no attribute 'return_type'

The version of installed python package is


By the way, I can run the same code several months ago successfully. So I wonder whether there is a new style to implement device noise model in updated pennylane.

Thanks in advance!

Hi @Yang ,

Can you try upgrading your plugin version?

pip install -U pennylane-qiskit
1 Like

Hi @christina ,

Thank you for the reply. It works by upgrading both the pennylane and pennylane-qiskit.