View on GitHub
Open this notebook in GitHub to run it yourself
Defining the Optimization Problem
Encode each node as a binary variable:
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 the Quantum Approximate Optimization Algorithm (QAOA) [1], 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 the QAOA algorithm [2]:
Output:
Output:

Viewing the 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:
Compare the optimized results to uniformly sampled results:

Output:

Comparing to a Classical Solver
Lastly, compare to the classical solution of the problem:Output:
