View on GitHub
Open this notebook in GitHub to run it yourself
Mathematical Formulation
The ILP problem can be formulated as follows: given an -dimensional vector , an matrix with and , and an -dimensional vector , find an -dimensional vector with integer entries that maximizes (or minimizes) the cost function: subject to these constraints: 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 theCombinatorialProblem 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:
optimize method of the CombinatorialProblem object.
For the classical optimization part of QAOA, define the maximum number of classical iterations (maxiter) and the -parameter (quantile) for running CVaR-QAOA, an improved variation of QAOA [3]:
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 thesample method:
| solution | probability | cost | |
|---|---|---|---|
| 12 | {‘x’: [0, 0, 1], ‘monotone_rule_1_slack_var’: … | 0.012207 | -3.0 |
| 223 | {‘x’: [0, 1, 0], ‘monotone_rule_1_slack_var’: … | 0.000488 | -2.0 |
| 146 | {‘x’: [1, 0, 0], ‘monotone_rule_1_slack_var’: … | 0.001953 | -1.0 |
| 15 | {‘x’: [0, 0, 0], ‘monotone_rule_1_slack_var’: … | 0.011719 | 0.0 |
| 224 | {‘x’: [0, 0, 1], ‘monotone_rule_1_slack_var’: … | 0.000488 | 7.0 |

Output:
Comparing to a Classical Solver
Compare to the classical solution of the problem:Output: