View on GitHub
Open this notebook in GitHub to run it yourself
Mathematical Formulation
Given a graph , an independent set is a set of vertices such that no two vertices in are adjacent. The Maximum Independent Set Problem is the problem of finding the independent set with maximum cardinality. In binary form, each vertex is represented as being in or out of the independent set by a binary variable , with if , and otherwise. The problem can then be formulated as Maximize subject to where each .Solving with the Classiq Platform
Go through the steps of solving the problem with the Classiq platform, using the Quantum Approximate Optimization Algorithm (QAOA) [2]. The solution is based on defining a Pyomo model for the optimization problem to solve:Building the Pyomo Model from Graph Input
Define the Pyomo model to use on the Classiq platform, with the mathematical formulation defined above:- Index set declarations (
model.Nodes,model.Arcs). - Binary variable declaration for each node (
model.x) indicating whether that node is included in the set. - Constraint rule - for each edge, at least one of the corresponding node variables is
- Objective rule – the sum of the variables equals the set size.

Output:
Setting Up the Classiq Problem Instance
To solve the Pyomo model defined above, use theCombinatorialProblem Python class.
Under the hood, it translates the Pyomo model to a quantum model of QAOA, with a cost Hamiltonian translated from the Pyomo model.
Choose the number of layers for the QAOA ansatz using the num_layers argument:
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 the QAOA algorithm, 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 Pyomo-to-Qmod translator changes the positive maximization objective to negative minimization. To get samples with the optimized parameters, call thesample method:
| solution | probability | cost | |
|---|---|---|---|
| 0 | {‘x’: [0, 1, 0, 1, 0, 0, 0, 1]} | 0.025391 | -3 |
| 8 | {‘x’: [0, 0, 0, 0, 1, 1, 0, 1]} | 0.017578 | -3 |
| 35 | {‘x’: [1, 1, 0, 1, 0, 0, 0, 0]} | 0.007812 | -3 |
| 79 | {‘x’: [0, 1, 0, 0, 0, 0, 1, 1]} | 0.004395 | -3 |
| 108 | {‘x’: [0, 0, 1, 1, 0, 0, 0, 1]} | 0.002930 | -3 |

Output:

Output:
