Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself
Integer Linear Programming (ILP) seeks a vector of integer numbers that maximizes (or minimizes) a linear cost function under a set of linear equality or inequality constraints [1]. In other words, it is an optimization problem where the cost function to optimize and all the constraints are linear and the decision variables are integers.

Mathematical Formulation

The ILP problem can be formulated as follows: given an nn-dimensional vector c=(c1,c2,,cn)\vec{c} = (c_1, c_2, \ldots, c_n), an m×nm \times n matrix A=(aij)A = (a_{ij}) with i=1,,mi=1,\ldots,m and j=1,,nj=1,\ldots,n, and an mm-dimensional vector b=(b1,b2,,bm)\vec{b} = (b_1, b_2, \ldots, b_m), find an nn-dimensional vector x=(x1,x2,,xn)\vec{x} = (x_1, x_2, \ldots, x_n) with integer entries that maximizes (or minimizes) the cost function: cx=c1x1+c2x2++cnxn\begin{aligned} \vec{c} \cdot \vec{x} = c_1x_1 + c_2x_2 + \ldots + c_nx_n \end{aligned} subject to these constraints: Axbxj0,j=1,2,,nxjZ,j=1,2,,n\begin{aligned} A \vec{x} & \leq \vec{b} \\ x_j & \geq 0, \quad j = 1, 2, \ldots, n \\ x_j & \in \mathbb{Z}, \quad j = 1, 2, \ldots, n \end{aligned} This tutorial guides you through the steps of solving the problem with the Classiq platform, using QAOA [2]. The solution is based on defining a Pyomo model for the optimization problem to solve.

Building the Pyomo Model from a Graph Input

Define the Pyomo model to use on the Classiq platform, using the mathematical formulation defined above:
Output:

Setting Up the Classiq Problem Instance

To solve the Pyomo model defined above, use the CombinatorialProblem quantum object. Under the hood it translates the Pyomo model to a quantum model of QAOA, with the cost Hamiltonian translated from the Pyomo model. Choose the number of layers for the QAOA ansatz using the num_layers argument. The penalty_factor is the coefficient of the constraints term in the cost Hamiltonian.

Synthesizing the QAOA Circuit and Solving the Problem

Synthesize and view the QAOA circuit (ansatz) used to solve the optimization problem:
Output:
Output:
Solve the problem by calling the optimize method of the CombinatorialProblem object. For the classical optimization part of QAOA, define the maximum number of classical iterations (maxiter) and the α\alpha-parameter (quantile) for running CVaR-QAOA, an improved variation of QAOA [3]:
Output:
Check the convergence of the run:
Output:
output

Optimization Results

Examine the statistics of the algorithm. The optimization is always defined as a minimization problem, so the positive maximization objective is translated to negative minimization by the Pyomo-to-Qmod translator. To get samples with the optimized parameters, call the sample method:
Compare the optimized results to uniformly sampled results:
And compare the histograms:
output Plot the solution:
Output:

Comparing to a Classical Solver

Compare to the classical solution of the problem:
Output:

References

[1] Integer Programming (Wikipedia). [2] Farhi, Edward, Jeffrey Goldstone, and Sam Gutmann. (2014). “A quantum approximate optimization algorithm.” arXiv preprint arXiv:1411.4028. [3] Barkoutsos, Panagiotis Kl, et al. (2020). “Improving variational quantum optimization using CVaR.” Quantum 4: 256.