Qiskit / qiskit-tutorials

A collection of Jupyter notebooks showing how to use the Qiskit SDK
Apache License 2.0
2.3k stars 1.29k forks source link

AttributeError: 'Estimator' object has no attribute 'draw' #1444

Closed sirgeorgesawcon closed 1 year ago

sirgeorgesawcon commented 1 year ago

Informations

What is the current behavior?

Following the qiskit tutorial exactly Tutorial , I'm getting the error AttributeError: 'Estimator' object has no attribute 'draw'

Steps to reproduce the problem

Just follow the tutorial as it is, no change in any code blocks

What is the expected behavior?

The code should run without any output.

Suggested solutions

The vqe.py file asks for if self.ansatz is not None: --> ret += "{}".format(self.ansatz.draw(output="text")) this draw is somehow not attributed in the Estimator class. issue

woodsp-ibm commented 1 year ago

The tutorial has this below to import VQE (this is the new Estimator based VQE)

from qiskit.algorithms.minimum_eigensolvers import VQE

your code above is

from qiskit.algorithms.minimum_eigen_solvers import VQE

which is importing an older VQE from minimum_eigen_solvers (which is being deprecated in the upcoming release) where there is an _ in eigen_solvers which the newly located VQE does not have. If you correct the import, so it matches the tutorial, then it will work.

If you look at the old VQE signature its,

class VQE(ansatz=None, optimizer=None, initial_point=None, gradient=None, expectation=None, include_custom=False, max_evals_grouped=1, callback=None, quantum_instance=None)

where you end up passing an estimator instance, where its expecting an ansatz circuit, and it seems the result is the issue you see.

woodsp-ibm commented 1 year ago

I will go ahead and close this in the absence of any feedback. The above should have solved your issue, in that you need to use the same VQE as the tutorial uses - there is the older legacy one, which I imagine you accidentally used, and the newer primitive based one that uses an Estimator.