Skip to main content

Qiskit Optimization: A library for optimization applications using quantum computing

Project description

Qiskit Optimization

License

Qiskit Optimization is an open-source framework that covers the whole range from high-level modeling of optimization problems, with automatic conversion of problems to different required representations, to a suite of easy-to-use quantum optimization algorithms that are ready to run on classical simulators, as well as on real quantum devices via Qiskit.

The Optimization module enables easy, efficient modeling of optimization problems using docplex. A uniform interface as well as automatic conversion between different problem representations allows users to solve problems using a large set of algorithms, from variational quantum algorithms, such as the Quantum Approximate Optimization Algorithm QAOA, to Grover Adaptive Search using the GroverOptimizer, leveraging fundamental algorithms provided by Qiskit Algorithms. Furthermore, the modular design of the optimization module allows it to be easily extended and facilitates rapid development and testing of new algorithms. Compatible classical optimizers are also provided for testing, validation, and benchmarking.

Installation

We encourage installing Qiskit Optimization via the pip tool (a python package manager).

pip install qiskit-optimization

pip will handle all dependencies automatically and you will always install the latest (and well-tested) version.

If you want to work on the very latest work-in-progress versions, either to try features ahead of their official release or if you want to contribute to Optimization, then you can install from source. To do this follow the instructions in the documentation.


Optional Installs

  • 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. CPLEX is a separate package and its support of Python versions is independent of Qiskit Optimization, where this CPLEX command will have no effect if there is no compatible version of CPLEX available (yet).

  • CVXPY may be installed using the command pip install 'qiskit-optimization[cvx]'. CVXPY being installed will enable the usage of the Goemans-Williamson algorithm as an optimizer GoemansWilliamsonOptimizer.

  • Matplotlib may be installed using the command pip install 'qiskit-optimization[matplotlib]'. Matplotlib being installed will enable the usage of the draw method in the graph optimization application classes.

  • Gurobipy may be installed using the command pip install 'qiskit-optimization[gurobi]'. Gurobipy being installed will enable the usage of the GurobiOptimizer.

Creating Your First Optimization Programming Experiment in Qiskit

Now that Qiskit Optimization is installed, it's time to begin working with the optimization module. Let's try an optimization experiment to compute the solution of a Max-Cut. The Max-Cut problem can be formulated as quadratic program, which can be solved using many several different algorithms in Qiskit. In this example, the MinimumEigenOptimizer is employed in combination with the Quantum Approximate Optimization Algorithm (QAOA) as minimum eigensolver routine.

from docplex.mp.model import Model

from qiskit_optimization.algorithms import MinimumEigenOptimizer
from qiskit_optimization.translators import from_docplex_mp

from qiskit.primitives import Sampler

from qiskit_algorithms.utils import algorithm_globals
from qiskit_algorithms import QAOA
from qiskit_algorithms.optimizers import SPSA

# Generate a graph of 4 nodes
n = 4
edges = [(0, 1, 1.0), (0, 2, 1.0), (0, 3, 1.0), (1, 2, 1.0), (2, 3, 1.0)]  # (node_i, node_j, weight)

# Formulate the problem as a Docplex model
model = Model()

# Create n binary variables
x = model.binary_var_list(n)

# Define the objective function to be maximized
model.maximize(model.sum(w * x[i] * (1 - x[j]) + w * (1 - x[i]) * x[j] for i, j, w in edges))

# Fix node 0 to be 1 to break the symmetry of the max-cut solution
model.add(x[0] == 1)

# Convert the Docplex model into a `QuadraticProgram` object
problem = from_docplex_mp(model)

# Run quantum algorithm QAOA on qasm simulator
seed = 1234
algorithm_globals.random_seed = seed

spsa = SPSA(maxiter=250)
sampler = Sampler()
qaoa = QAOA(sampler=sampler, optimizer=spsa, reps=5)
algorithm = MinimumEigenOptimizer(qaoa)
result = algorithm.solve(problem)
print(result.prettyprint())  # prints solution, x=[1, 0, 1, 0], the cost, fval=4

Further examples

Learning path notebooks may be found in the optimization tutorials section of the documentation and are a great place to start.


Contribution Guidelines

If you'd like to contribute to Qiskit, please take a look at our contribution guidelines. This project adheres to Qiskit's code of conduct. By participating, you are expected to uphold this code.

We use GitHub issues for tracking requests and bugs. Please join the Qiskit Slack community and for discussion and simple questions. For questions that are more suited for a forum, we use the Qiskit tag in Stack Overflow.

Authors and Citation

Optimization was inspired, authored and brought about by the collective work of a team of researchers. Optimization continues to grow with the help and work of many people, who contribute to the project at different levels. If you use Qiskit, please cite as per the provided BibTeX file.

License

This project uses the Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qiskit-optimization-0.6.1.tar.gz (156.9 kB view details)

Uploaded Source

Built Distribution

qiskit_optimization-0.6.1-py3-none-any.whl (167.6 kB view details)

Uploaded Python 3

File details

Details for the file qiskit-optimization-0.6.1.tar.gz.

File metadata

  • Download URL: qiskit-optimization-0.6.1.tar.gz
  • Upload date:
  • Size: 156.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for qiskit-optimization-0.6.1.tar.gz
Algorithm Hash digest
SHA256 0ad8c2bc83fe80657c788b5f282ce4055d0ec005c4876789e5069499ee3c00c0
MD5 bef7547ff3ba5a216e7b06271d63daf4
BLAKE2b-256 806330ae1aa61c407ccd7f2a1499884653cf6be87fd4a216013c226273796a8f

See more details on using hashes here.

File details

Details for the file qiskit_optimization-0.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for qiskit_optimization-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f09f31289dfef66bbbb03b782a94d88a4ba5681c728b4b8e96884de5fc83879
MD5 70a15c5d1bdf0bf4de64783f596340e8
BLAKE2b-256 a7677669e6ad0b41b1e4ab79b592a4f1de748cac946169f5409e7a9f4bafef10

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page