0
from qiskit import Aer
from qiskit.utils import QuantumInstance
from qiskit.algorithms import Shor

N = 15
backend = Aer.get_backend('aer_simulator')
quantum_instance = QuantumInstance(backend, shots=1024)
shor = Shor(quantum_instance=quantum_instance)
result = shor.factor(N)
print(f"The list of factors of {N} as computed by the Shor's algorithm is {result.factors[0]}.")

When I am running code I am experiencing this error:

ImportError: cannot import name 'Shor' from 'qiskit.algorithms' (C:\Users\Prasann\anaconda3\lib\site-packages\qiskit\algorithms\__init__.py)

It should have imported it.

1 Answers1

1

Shors algorithm was deprecated in Qiskit Terra 0.22.0 and removed in 0.24.0. https://qiskit.org/documentation/release_notes.html#algorithms-upgrade-notes So if you have the latest version of qiskit-terra the Shor algorithm, that was there, no longer exists and will thus fail to import it.

The deprecated modules factorizers and linear_solvers, containing HHL and Shor have been removed from qiskit.algorithms. These functionalities were originally deprecated as part of the 0.22.0 release (released on October 13, 2022). You can access the code through the Qiskit Textbook instead: Linear Solvers (HHL) , Factorizers (Shor)

It links Shor to the code in the textbook here https://learn.qiskit.org/course/ch-algorithms/shors-algorithm

Steve Wood
  • 266
  • 1
  • 3