QAOA

QAOA

Similar to VQE, QAOA in Divi operates in multiple modes: a single-instance mode and a partitioning mode. The single-instance mode can be used to find a solution to a single graph-based or QUBO-based optimization problem. The partitioning mode is more specialized, focusing on solving larger, less tractable problems through a divide-and-conquer approach.

Single-instance QAOA

A QAOA constructor expects a problem. The form of input triggers a different execution pathway under the hood. However, there are some common arguments that one must pay attention to.

A user can optionally override the initial state by passing an InitialState instance (e.g., ZerosState(), SuperpositionState()). By default, each problem class provides its own recommended initial state. In addition, a user can determine how many layers of the QAOA ansatz to apply.

ℹ️
Whenever in doubt, inspect the initial_state variable after initializing a QAOA object to determine the resolved initial state.

The solution of the QAOA problem can be accessed through the solution variable, which, based on the problem at hand, would have different formats. For a graph problem, it will contain a set of node IDs that correspond to one of the partitions of the solution. For QUBO optimization, it will return the solution bitstring as a list of 1’s and 0’s.

Graph Problems

Divi includes built-in support for several common graph-based optimization problems via concrete problem classes in divi.qprog.problems:

Problem Class Description
MaxCliqueProblem Finds the largest complete subgraph where every node is connected to every other.
MaxIndependentSetProblem Finds the largest set of vertices with no edges between them.
MaxWeightCycleProblem Identifies a cycle with the maximum total edge weight in a weighted graph.
MaxCutProblem Divides a graph into two subsets to maximize the sum of edge weights between them.
MinVertexCoverProblem Finds the smallest set of vertices such that every edge is incident to at least one selected vertex.

For all problems with the exception of MaxCut, the constrained version of the Hamiltonian is available by passing the keyword argument is_constrained=True to the problem constructor. Refer to the PennyLane documentation for more details.

Divi also provides a visualization function for computed solutions:

QAOA Max-Clique

QAOA Max-Clique Solution on the Bull Graph

QUBO-based Problems

Divi’s QAOA solver can also take a QUBO (Quadratic Unconstrained Binary Optimization) formulated problem instead of a graph. Divi supports the following QUBO input formats:

  • NumPy array: A dense N×N matrix
  • SciPy sparse matrix: For large, sparse QUBOs
  • D-Wave’s BinaryQuadraticModel: From the dimod library

In contrast to graph-based QAOA instances, the solution format for QUBO-based QAOA instances is a binary numpy array representing the value for each variable in the original QUBO.

QDrift Integration

QAOA supports QDrift as a trotterization strategy, which can reduce circuit depth for problems with many Hamiltonian terms. Pass a TrotterizationStrategy to enable it.

Partitioning QAOA

GraphPartitioningQAOA solves optimization problems like MaxCut on large graphs. Instead of executing a single large QAOA circuit, the graph is partitioned into smaller subgraphs (clusters), and individual QAOA instances are executed in parallel across these subgraphs, before aggregating the results, in a divide-and-conquer manner.

This enables scalable quantum optimization, even for graphs that exceed the size limits of a single quantum backend.

Configuring the Partitioning

The partitioning strategy is configured using the GraphPartitioningConfig class (passed to the problem constructor), which offers the following options:

  • max_n_nodes_per_cluster: This specifies the maximum number of nodes allowed in each subgraph or cluster. This is crucial for ensuring that each subproblem fits within the constraints of a single quantum backend.

  • minimum_n_clusters: This parameter sets the minimum number of clusters to be created.

  • partitioning_algorithm: A parameter that determines the algorithm used to partition the graph. The available options are:

    • spectral: This refers to spectral clustering 1, an algorithm that uses the eigenvectors of the graph’s Laplacian matrix to partition the vertices. It’s known for producing high-quality partitions by minimizing the number of edges cut between the subgraphs. However, it might lead to unevenly sized partitions, based on the input graph.
    • metis: Employs the popular METIS program 2 through py-metis. This algorithm generally generates more evenly sized partitions compared to spectral clustering.
    • kernighan_lin Iteratively applies the classical Kernighan-Lin 3 bipartitioning algorithm until the desired number of clusters is achieved.

At least one of max_n_nodes_per_cluster and minimum_n_clusters must be provided to the class. In case both are provided, the partitioning logic would first attempt creating the minimum number of desired partitions first, before breaking down any oversized partitions further to meet the constraint on the number of nodes.

Execution Flow

Step Description
partitioning_config=config The graph is partitioned into subgraphs using the selected algorithm.
optimizer=MonteCarloOptimizer() A lightweight Monte Carlo optimizer is used to minimize circuit evaluation cost.
create_programs() Decomposes the problem and initializes a QAOA program for each partition.
run() Executes all generated circuits — possibly in parallel across multiple quantum backends.
aggregate_results() The final MaxCut solution is formed by combining partition-wise results via beam search.

The partitions can also be visualized through the function draw_partitions:

Partitioned Graph

Generated Partitions for a 30-Node Graph with Max Nodes set to 10

QUBO Partitioning Example

For QUBO problems that are too large to solve directly, QUBOPartitioningQAOA applies a similar partitioning strategy, but operates on the QUBO matrix structure rather than graph topology.

Why Partition?

Quantum hardware is limited in the number of qubits and circuit depth. For large problems:

  • Full QAOA is intractable.
  • Partitioned QAOA trades global optimality for scalability and parallel execution.
  • It enables fast, approximate solutions using many small quantum jobs rather than one large one.

📖 For code examples and detailed API usage, visit the Divi Documentation.


  1. Fiedler, M. (1973). Algebraic connectivity of graphs. Czechoslovak Mathematical Journal, 23(2), 298-305. ↩︎

  2. Karypis, G., & Kumar, V. (1997). METIS: A software package for partitioning unstructured graphs, partitioning meshes, and computing fill-reducing orderings of sparse matrices. Department of Computer Science and Engineering, University of Minnesota↩︎

  3. Kernighan, B. W., & Lin, S. (1970). An efficient heuristic procedure for partitioning graphs. The Bell System Technical Journal, 49(2), 291-307. ↩︎