Package: qiskit-optimization
Qiskit OptimizationQiskit Optimizationis 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 usingdocplex.
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 byQiskit 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.InstallationWe encourage installing Qiskit Optimization via the pip tool (a python package manager).pipinstallqiskit-optimizationpipwill 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 thedocumentation.Optional InstallsIBM CPLEXmay be installed usingpip install 'qiskit-optimization[cplex]'to enable the reading ofLPfiles and the usage of
theCplexOptimizer, wrapper forcplex.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).CVXPYmay be installed using the commandpip install 'qiskit-optimization[cvx]'.
CVXPY being installed will enable the usage of the Goemans-Williamson algorithm as an optimizerGoemansWilliamsonOptimizer.Matplotlibmay be installed using the commandpip install 'qiskit-optimization[matplotlib]'.
Matplotlib being installed will enable the usage of thedrawmethod in the graph optimization application classes.Gurobipymay be installed using the commandpip install 'qiskit-optimization[gurobi]'.
Gurobipy being installed will enable the usage of the GurobiOptimizer.Creating Your First Optimization Programming Experiment in QiskitNow 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 aMax-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.fromdocplex.mp.modelimportModelfromqiskit_optimization.algorithmsimportMinimumEigenOptimizerfromqiskit_optimization.translatorsimportfrom_docplex_mpfromqiskit.primitivesimportSamplerfromqiskit_algorithms.utilsimportalgorithm_globalsfromqiskit_algorithmsimportQAOAfromqiskit_algorithms.optimizersimportSPSA# Generate a graph of 4 nodesn=4edges=[(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 modelmodel=Model()# Create n binary variablesx=model.binary_var_list(n)# Define the objective function to be maximizedmodel.maximize(model.sum(w*x[i]*(1-x[j])+w*(1-x[i])*x[j]fori,j,winedges))# Fix node 0 to be 1 to break the symmetry of the max-cut solutionmodel.add(x[0]==1)# Convert the Docplex model into a `QuadraticProgram` objectproblem=from_docplex_mp(model)# Run quantum algorithm QAOA on qasm simulatorseed=1234algorithm_globals.random_seed=seedspsa=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=4Further examplesLearning path notebooks may be found in theoptimization tutorialssection
of the documentation and are a great place to start.Contribution GuidelinesIf you'd like to contribute to Qiskit, please take a look at ourcontribution guidelines.
This project adheres to Qiskit'scode of conduct.
By participating, you are expected to uphold this code.We useGitHub issuesfor tracking requests and bugs. Pleasejoin the Qiskit Slack communityand for discussion and simple questions.
For questions that are more suited for a forum, we use theQiskittag inStack Overflow.Authors and CitationOptimization was inspired, authored and brought about by the collective work of a team of researchers.
Optimization continues to grow with the help and work ofmany people, who contribute
to the project at different levels.
If you use Qiskit, please cite as per the providedBibTeX file.LicenseThis project uses theApache License 2.0.