# Problem with Pennylane-Qiskit

**URL:** <https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337>\
**Category:** PennyLane Qiskit\
**Created:** [August 17, 2023, 7:45am UTC](https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337 "2023-08-17T07:45:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kalyani](https://avatars.discourse-cdn.com/v4/letter/k/67e7ee/32.png) [@Kalyani](https://discuss.pennylane.ai/u/Kalyani)\
**Post date:** [August 17, 2023, 7:45am UTC](https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337/1 "2023-08-17T07:45:19Z")

</div>

Hello!

I’ve been trying to implement certain pennylane tutorials on qiskit backend. A week ago, i.e., when I had Pennylane v27, everything worked fine with just

```auto
dev = qml.device('qiskit.aer',wires=tot_qubits)
@qml.qnode(dev)

```

The tutorial I’m trying to implement is the VQLS tutorial. However, as I updated to v31 and tried to run this command again, I get a problem in the calculation of cost function ([Variational Quantum Linear Solver | PennyLane Demos](https://pennylane.ai/qml/demos/tutorial_vqls#variational-optimization)), the error originates at the calculation of cost and is an attribute error.

```auto
 w, cost = opt.step_and_cost(cost_loc, w)

 g, forward = self.compute_grad(objective_fn, args, kwargs, grad_fn=grad_fn)

AttributeError: 'list' object has no attribute 'measurements'

```

And, finally, here is the output of qml.about() :

```auto
Name: PennyLane
Version: 0.31.1
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /p/bv/bin/soft/Python-3.8.6/lib/python3.8/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning, PennyLane-qiskit

Platform info: Linux-3.10.0-1160.90.1.el7.x86_64-x86_64-with-glibc2.2.5
Python version: 3.8.6
Numpy version: 1.23.2
Scipy version: 1.9.3
Installed devices:
- default.gaussian (PennyLane-0.31.1)
- default.mixed (PennyLane-0.31.1)
- default.qubit (PennyLane-0.31.1)
- default.qubit.autograd (PennyLane-0.31.1)
- default.qubit.jax (PennyLane-0.31.1)
- default.qubit.tf (PennyLane-0.31.1)
- default.qubit.torch (PennyLane-0.31.1)
- default.qutrit (PennyLane-0.31.1)
- null.qubit (PennyLane-0.31.1)
- lightning.qubit (PennyLane-Lightning-0.31.0)
- qiskit.aer (PennyLane-qiskit-0.27.0)
- qiskit.basicaer (PennyLane-qiskit-0.27.0)
- qiskit.ibmq (PennyLane-qiskit-0.27.0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.27.0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.27.0)

```

Is it possible that the Pennylane-qiskit needs to go from v27 to v31 so this error is circumvented?

Thanks!

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [August 18, 2023, 2:01pm UTC](https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337/2 "2023-08-18T14:01:44Z")

</div>

Hey @Kalyani!

Can you post the full code example that replicates this behaviour? I know you said that you’re running the VQLS demo with the pennylane-qiskit backend, but it would help tremendously if we could see the exact code you’re running so that we can try to replicate the error 🙂

---

<div class="post-metadata">

**Author:** ![kevinkawchak](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/kevinkawchak/32/1801_2.png) [@kevinkawchak](https://discuss.pennylane.ai/u/kevinkawchak)\
**Post date:** [August 18, 2023, 4:36pm UTC](https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337/3 "2023-08-18T16:36:24Z")

</div>

Hello @Kalyani,

Perhaps defining a backend would help:  
dev = qml.device(‘qiskit.aer’,wires=tot\_qubits,backend=‘aer\_simulator\_statevector’)

There are more examples in documentation: [The Aer device — PennyLane-Qiskit 0.32.0-dev documentation](https://docs.pennylane.ai/projects/qiskit/en/latest/devices/aer.html)

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [August 18, 2023, 6:17pm UTC](https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337/4 "2023-08-18T18:17:09Z")

</div>

Hi @Kalyani,

I know that Qiskit made a release recently so your issue may be related to this. You could try updating your versions of the pennylane-qiskit plugin and qiskit-aer. Alternatively you could create a new virtual environment and `pip install pennylane pennylane-qiskit qiskit-aer`.

Here’s a small code example that works well on the latest version of these 3 packages.

```auto
import qiskit
import pennylane as qml
from pennylane import numpy as np

dev = qml.device('qiskit.aer',wires=2, shots=10)

@qml.qnode(dev)
def circuit(w):
    qml.Hadamard(wires=0)
    qml.RX(w,wires=0)
    return qml.expval(qml.PauliZ(0))

w=np.array(0.1,requires_grad=True)

opt = qml.GradientDescentOptimizer(stepsize=0.1)
w, cost = opt.step_and_cost(circuit, w)
print(cost)

```

If the example above works but your own example doesn’t, you could try installing the development version of the pennylane-qiskit plugin and check if this solves your issue.

Please feel free to add more details here if none of these options help.

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [August 18, 2023, 6:18pm UTC](https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337/5 "2023-08-18T18:18:16Z")

</div>

Thanks for your suggestion @kevinkawchak ! In this case you shouldn’t need to add the backend so it’s probably be something else causing the issue.

---

<div class="post-metadata">

**Author:** ![Kalyani](https://avatars.discourse-cdn.com/v4/letter/k/67e7ee/32.png) [@Kalyani](https://discuss.pennylane.ai/u/Kalyani)\
**Post date:** [August 22, 2023, 1:12pm UTC](https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337/6 "2023-08-22T13:12:11Z")

</div>

Hello!  
Thanks a lot! Seems like updating solved the problem 😃

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [August 22, 2023, 11:18pm UTC](https://discuss.pennylane.ai/t/problem-with-pennylane-qiskit/3337/7 "2023-08-22T23:18:23Z")

</div>

That’s great to hear @Kalyani !
