Qiskit Optimization depends on the main Qiskit package which has its own Qiskit Getting Started detailing the installation options for Qiskit and its supported environments/platforms. You should refer to that first. Then the information here can be followed which focuses on the additional installation specific to Qiskit Optimization.
Qiskit Optimization has some functions that have been made optional where the dependent code and/or support program(s) are not (or cannot be) installed by default. Those are IBM CPLEX, CVXPY and Matplotlib. See Optional installs for more information.
The simplest way to get started is to follow the getting started ‘Start locally’ for Qiskit here Qiskit Getting Started
In your virtual environment where you installed Qiskit simply add
optimization to the
extra list in a similar manner to how the extra
visualization support is installed for
pip install qiskit[optimization]
It is worth pointing out that if you’re a zsh user (which is the default shell on newer
versions of macOS), you’ll need to put
qiskit[optimization] in quotes:
pip install 'qiskit[optimization]'
Installing Qiskit Optimization from source allows you to access the most recently updated version under development instead of using the version in the Python Package Index (PyPI) repository. This will give you the ability to inspect and extend the latest version of the Qiskit Optimization code more efficiently.
Since Qiskit Optimization depends on Qiskit, and its latest changes may require new or changed features of Qiskit, you should first follow Qiskit’s “Install from source” instructions here Qiskit Getting Started
Installing Qiskit Optimization from Source
Using the same development environment that you installed Qiskit in you are ready to install Qiskit Optimization.
Clone the Qiskit Optimization repository.
git clone https://github.com/Qiskit/qiskit-optimization.git
Cloning the repository creates a local folder called
If you want to run tests or linting checks, install the developer requirements.
pip install -r requirements-dev.txt
pip install .
If you want to install it in editable mode, meaning that code changes to the project don’t require a reinstall to be applied, you can do this with:
pip install -e .
IBM CPLEX may be installed using pip install ‘qiskit-optimization[cplex]’ to enable the reading of LP files and the usage of the CplexOptimizer, wrapper for
cplex.Cplex. Currently there is no python 3.9 version of CPLEX. In this case, the CPLEX install command will have no effect.
CVXPY, may be installed using command pip install ‘qiskit-optimization[cvx]’ to install the package. CVXPY being installed will enable the usage of the Goemans-Williamson algorithm as an optimizer GoemansWilliamsonOptimizer.
Matplotlib, may be installed using command pip install ‘qiskit-optimization[matplotlib]’ to install the package. Matplotlib being installed will enable the usage of the draw method in the graph optimization application classes.
Gurobipy may be installed using command pip install ‘qiskit-optimization[gurobi]’ to install the package. Gurobipy being installed will enable the usage of the GurobiOptimizer.