Skip to main content

Qiskit Optimization: A library of quantum computing optimizations

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 Terra. 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. 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 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.

import networkx as nx
import numpy as np

from qiskit_optimization import QuadraticProgram
from qiskit_optimization.algorithms import MinimumEigenOptimizer

from qiskit.utils import algorithm_globals, QuantumInstance
from qiskit import BasicAer
from qiskit.algorithms import QAOA
from qiskit.algorithms.optimizers import SPSA

seed = 1234
algorithm_globals.random_seed = seed

# Generate a graph of 4 nodes
n = 4
graph = nx.Graph()
graph.add_nodes_from(np.arange(0, n, 1))
elist = [(0, 1, 1.0), (0, 2, 1.0), (0, 3, 1.0), (1, 2, 1.0), (2, 3, 1.0)]
graph.add_weighted_edges_from(elist)

# Compute the weight matrix from the graph
w = nx.adjacency_matrix(graph)

# Formulate the problem as quadratic program
problem = QuadraticProgram()
_ = [problem.binary_var(f"x{i}") for i in range(n)]  # create n binary variables
linear = w.dot(np.ones(n))
quadratic = -w
problem.maximize(linear=linear, quadratic=quadratic)

# Fix node 0 to be 1 to break the symmetry of the max-cut solution
problem.linear_constraint([1, 0, 0, 0], '==', 1)

# Run quantum algorithm QAOA on qasm simulator
spsa = SPSA(maxiter=250)
backend = BasicAer.get_backend('qasm_simulator')
q_i = QuantumInstance(backend=backend, seed_simulator=seed, seed_transpiler=seed)
qaoa = QAOA(optimizer=spsa, reps=5, quantum_instance=q_i)
algorithm = MinimumEigenOptimizer(qaoa)
result = algorithm.solve(problem)
print(result)  # 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.

Please note that if you do not like the way your name is cited in the BibTex file then consult the information found in the .mailmap 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.3.1.tar.gz (134.0 kB view details)

Uploaded Source

Built Distribution

qiskit_optimization-0.3.1-py3-none-any.whl (154.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qiskit-optimization-0.3.1.tar.gz
  • Upload date:
  • Size: 134.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for qiskit-optimization-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0c0b396b8e6abf0e201b41e0b3a0daddd2bdf9110a60794d538c9e678487dc30
MD5 40f7b1d3190bc717d7387c00af40998b
BLAKE2b-256 bc6bcae14b4aff5ec8a781747abc0155d70941220237ed7ae6d6180dd3a2985f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qiskit_optimization-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 154.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for qiskit_optimization-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6164578610d5e8e7f066db690ad508fd625294af2b3ffe0e7fea54eec0b08e80
MD5 a2509ba4748dfd21de757ddf4ef5214d
BLAKE2b-256 f42631f97a382285bd504494ac17e61a2c9469d00d034e82d901d4d1ea6f1ea5

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