Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself

Introduction

The Max K-Vertex Cover problem [1] is a classical problem in graph theory and computer science, where we aim to find a set of vertices such that each edge of the graph is incident to at least one vertex in the set, and the size of the set does not exceed a given number kk.

Mathematical Formulation

The Max-k Vertex Cover problem can be formulated as an Integer Linear Program (ILP): Minimize: (i,j)E(1xi)(1xj)\sum_{(i,j) \in E} (1 - x_i)(1 - x_j) Subject to: iVxi=k\sum_{i \in V} x_i = k and xi{0,1}iVx_i \in \{0, 1\} \quad \forall i \in V Where:
  • xix_i is a binary variable that equals 1 if node ii is in the cover and 0 otherwise
  • EE is the set of edges in the graph
  • VV is the set of vertices in the graph
  • kk is the maximum number of vertices allowed in the cover

Solving with the Classiq Platform

We go through the steps of solving the problem with the Classiq platform, using QAOA algorithm [2]. The solution is based on defining a Pyomo model for the optimization problem we would like to solve.

Building the Pyomo Model from a Graph Input

We proceed by defining the Pyomo model that will be used on the Classiq platform, using the mathematical formulation defined above:
The model contains:
  • Index set declarations (model.Nodes, model.Arcs).
  • Binary variable declaration for each node (model.x) indicating whether the variable is chosen for the set.
  • Constraint rule - ensures that the set is of size k.
  • Objective rule - counts the number of edges not covered; i.e., both related variables are zero.
output
Output:

Setting Up the Classiq Problem Instance

In order to solve the Pyomo model defined above, we use the CombinatorialProblem python class. Under the hood it tranlates the Pyomo model to a quantum model of the QAOA algorithm, with cost hamiltonian translated from the Pyomo model. We can choose the number of layers for the QAOA ansatz using the argument num_layers, and the penalty_factor, which will be the coefficient of the constraints term in the cost hamiltonian.

Synthesizing the QAOA Circuit and Solving the Problem

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

Optimization Results

We can also examine the statistics of the algorithm. In order to get samples with the optimized parameters, we call the sample method:
We will also want to compare the optimized results to uniformly sampled results:
And compare the histograms:
output Let us plot the solution:
Output:
output

Comparison to a Classical Solver

Lastly, we can compare to the classical solution of the problem:
Output:
output

References

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