6

enter image description here

when I try to run this code, it gives me and error that it was unable to import execute from qiskit (error pasted below).

2 get_ipython().system('pip install --upgrade qiskit qiskit-aer') 3 import qiskit ----> 4 from qiskit import QuantumCircuit, execute 5 from qiskit_aer import Aer 6 from qiskit.visualization import plot_histogram ImportError: cannot import name 'execute' from 'qiskit' (/usr/local/lib/python3.10/dist-packages/qiskit/__init__.py) 

I have tried upgrading qiskit which didn't work. I have also tried using transpile and the other functions but it changed my code too much and I didn't want that to happen.

1

5 Answers 5

7

The execute Function in qskit library is been removed from version 1.00 you can downgrade to version 0.46 and it will Run

Sign up to request clarification or add additional context in comments.

1 Comment

is not good idea because when you have higher version is raising the error
6

You can use transpile in newer version. Refer: qiskit v1.0 migration guide

Comments

3
# Import section from qiskit_aer import AerSimulator # For execution simulator = AerSimulator() compiled_circuit = transpile(qc, simulator) sim_result = simulator.run(compiled_circuit).result() counts = sim_result.get_counts() 

No need to downgrade to the older version. Use the above code for newer version of qiskit. They don't use Qasm_simulator anymore.

1 Comment

Add in # Import section: from qiskit import transpile
2

One of the great things about qiskit is also one of the challenges, in that it updates quite quickly. The execute function has been deprecated since version o.46.0 (see notice here) and it was removed in the 1.0 release.

If you need to use an older version, such as following along a tutorial or quickstart, you can rollback to earlier releases and use the syntax for that release. For example: https://docs.quantum.ibm.com/api/qiskit/0.24/execute

from qiskit import QuantumCircuit, execute, BasicAer backend = BasicAer.get_backend('qasm_simulator') qc = QuantumCircuit(5, 5) qc.h(0) qc.cx(0, range(1, 5)) qc.measure_all() job = execute(qc, backend, shots=4321) 

2 Comments

The issue was due to qiskit 1.0 removing execute from its library and I had to downgrade to version 0.46 version. I appreciate your input!
The note about being able to roll back to follow along with tutorials is important given how many of the existing guides for Qiskit have broken as a result of this change.
0

use this if you are not running as admi

pip uninstall qiskit qiskit-aer qiskit-ibmq-provider qiskit-terra -y pip install qiskit==0.46.0 

To sove it just I used this example to verify

from qiskit import QuantumCircuit from qiskit_aer import AerSimulator # Use AerSimulator instead of Aer from qiskit.visualization import plot_histogram import matplotlib.pyplot as plt # Define a simple quantum circuit qc = QuantumCircuit(2, 2) qc.h(0) qc.cx(0, 1) qc.measure([0, 1], [0, 1]) # Use the updated AerSimulator simulator = AerSimulator() # Run the circuit result = simulator.run(qc, shots=1000).result() counts = result.get_counts() # Display results print("Measurement results:", counts) plot_histogram(counts) plt.show() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.