Closed JohnyMarley closed 3 months ago
BaseBackend
was deprecated and removed from Qiskit a long time ago (0.21.0). The above optimization code does not even reference that class. I would check whether you can import anything from qiskit like QuantumCircuit with getting the same error. If I do the same - though I did it in a Python command line not a notebook - it works fine. You should also check what environment your notebook is using.
I will also note that only the very latest version of Qiskit supports Python 3.12. None of the rest of the above do. I would check what your installation as to what is actually there. For now 3.11 is the newest version consistent with all those packages.
I can confirm that I can reproduce the error after following the same steps for python3.12. What happened in my environment is that pip install 'qiskit-optimization[cplex]'
downgrades the qiskit-optimization
back to 0.3.2
Installing collected packages: qiskit-optimization
Attempting uninstall: qiskit-optimization
Found existing installation: qiskit-optimization 0.6.0
Uninstalling qiskit-optimization-0.6.0:
Successfully uninstalled qiskit-optimization-0.6.0
Successfully installed qiskit-optimization-0.3.2
There is no cplex for 3.12 (again latest version supported is 3.11). In optimization 0.3.2 it has to install cplex if Python < 3.10, so I guess it was able to figure it could satisfy that request for the optional install by dropping back to 0.3.2 whereupon it does nothing in essence as far as cplex is concerned.
Thanks for the reply and help! :+1:
Environment
What is happening?
I am trying to run the quiskit optimization example from: https://qiskit.org/ecosystem/optimization/tutorials/02_converters_for_quadratic_programs.html
And get the following import error:
ImportError: cannot import name 'BaseBackend' from 'qiskit.providers' (/home/jdara/anaconda3/envs/quant4/lib/python3.12/site-packages/qiskit/providers/init.py)
How can we reproduce the issue?
First run these pip commands:
pip install qiskit pip install qiskit-ibm-runtime pip install qiskit[visualization] pip install qiskit-optimization pip install 'qiskit-optimization[cplex]' pip install 'qiskit-optimization[cvx]' pip install 'qiskit-optimization[matplotlib]'
Then run in a jupyternotebook:
from qiskit_optimization.algorithms import CplexOptimizer cplex_optimizer = CplexOptimizer()
This results in this error:
ImportError: cannot import name 'BaseBackend' from 'qiskit.providers' (/home/jdara/anaconda3/envs/quant4/lib/python3.12/site-packages/qiskit/providers/init.py)
I am running in a anaconda environment if this should be relevant
What should happen?
I would expect the import not to go wrong
Any suggestions?
No response