pythongoogle-colaboratoryqiskit

Unable to import Qiskit Aqua and terra Algorithm QSVM as per the documentation mentioned on Qiskit site


I am using google colab. I tried installing qiskit library using the following line

!pip install qiskit

i also tried this

!pip install qiskit-aqua

I am trying to work on quantum computing SVM model using the following line of code

from qiskit.aqua.algorithms import QSVM

Its giving me this error

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-26-72fec39648aa> in <cell line: 1>()
----> 1 from qiskit.aqua.algorithms import QSVM

ModuleNotFoundError: No module named 'qiskit.aqua'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

I read through the documentation on this link https://qiskit.org/documentation/stable/0.32/stubs/qiskit.aqua.algorithms.QSVM.html it says which says i have installed and used it correctly but still its giving me the error. Can u please help

Upon research I also found that qiskit.aqua is depricated. but i am not able to use qiskit terra as well.

i tried the similar installations step above but getting the same error as mentioned below

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-38-5d584079ae18> in <cell line: 10>()
      8 from qiskit import Aer
      9 from qiskit.circuit.library import ZZFeatureMap
---> 10 from qiskit.terra.algorithms import QSVM

ModuleNotFoundError: No module named 'qiskit.terra'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Solution

  • Qiskit Aqua was deprecated, as you have seen, over two years ago and is no longer supported. A migration guide linked there did list the changes, but the link supplied there is no longer working, however the original migration notebook source of that is still there, if you should want to look at it, but I will explain below.

    As part of that QSVM was moved/refactored over to Qiskit Machine Learning where it now exists as QSVC (and it derives from scikit-learn SVC for compatibility with that library). I would highly recommend looking to this rather than the now unsupported old QSVM. There is a tutorial here including QSVC where you can learn more.