QAOA Tutorial: A Reproducible Workflow for Combinatorial Optimization
QAOAquantum optimizationvariational algorithmscombinatorial optimizationbenchmarking

QAOA Tutorial: A Reproducible Workflow for Combinatorial Optimization

QQbit Editorial Team
2026-12-03
8 min read

A reproducible QAOA workflow covering Ising formulation, circuit design, tuning, shot-based evaluation, baselines, and experiment logging.

This QAOA tutorial presents a reproducible workflow for turning a small combinatorial optimization problem into a quantum circuit, tuning its parameters, and judging the result against classical baselines. You will see how to formulate a cost function, map it to an Ising Hamiltonian, select a mixer, estimate sampling requirements, and record experiments so that results remain comparable when the graph, optimizer, simulator, or hardware changes.

Overview

The Quantum Approximate Optimization Algorithm, or QAOA, is a hybrid quantum-classical method for estimating good solutions to discrete optimization problems. A classical optimizer proposes circuit parameters, a quantum device or simulator evaluates the resulting circuit, and the measured objective value is returned to the optimizer. This loop repeats until the budget is exhausted or the objective stops improving.

QAOA is not a general replacement for classical optimization. Its practical value is that it gives developers a structured way to investigate whether a parameterized quantum circuit can represent useful solutions for a particular problem at a particular scale. A fair evaluation therefore needs more than the best bit string observed in one run. It should include the problem encoding, circuit depth, shot count, optimizer settings, objective values, feasibility checks, and comparable classical baselines.

This workflow is easiest to understand with a graph problem such as Max-Cut. Given a graph with vertices and edges, assign each vertex to one of two partitions and maximize the number of edges crossing between partitions. Represent each vertex with a binary variable x_i in {0, 1}. An edge (i, j) contributes one when x_i and x_j differ.

For small experiments, use a simulator first. A circuit visualizer can help verify the initial state, alternating cost and mixer layers, parameter placement, and measurement operations. The quantum circuit visualizers comparison is useful when inspecting these structural details before running shot-based experiments.

How to estimate

1. Define the classical objective

Start with a function that can be evaluated without quantum software. For Max-Cut, one convenient objective is:

C(x) = sum over edges (i, j) of w_ij [x_i is not equal to x_j]

Here, w_ij is the edge weight. If all edges are unweighted, set every weight to 1. Before constructing a circuit, enumerate all bit strings for a small graph and identify the optimal objective value. This exact result becomes the reference for the quantum experiment.

2. Convert the objective to an Ising form

QAOA commonly uses spin variables z_i in {+1, -1}, related to binary variables by z_i = 1 - 2x_i. For an unweighted Max-Cut edge, the cut contribution can be written as (1 - z_i z_j) / 2. The cost Hamiltonian is therefore built from terms proportional to Z_i Z_j, along with a constant offset. The offset changes the reported energy but not which bit string is best, so record whether your framework includes or removes it.

For weighted graphs, multiply each edge term by its weight. For other problems, such as a small scheduling or constraint-satisfaction instance, write the penalty model explicitly. A valid solution should receive a lower or higher energy according to your convention, and violated constraints should carry a penalty large enough to matter without overwhelming the actual objective.

3. Choose the mixer and circuit depth

The standard QAOA mixer is a sum of X operators, implemented with an X rotation on each qubit. It explores computational-basis states while preserving no hard constraints. The circuit begins with Hadamard gates to create an equal superposition, then alternates a cost unitary and a mixer unitary:

U(gamma, beta) = U_B(beta_p) U_C(gamma_p) ... U_B(beta_1) U_C(gamma_1)

The integer p is the number of QAOA layers. Start with p = 1 or p = 2. Increasing p adds parameters, gates, simulation cost, and exposure to hardware noise. A deeper circuit is not automatically better; compare depths under the same evaluation protocol.

4. Optimize and evaluate separately

During optimization, the objective may be estimated from a limited number of shots or from exact simulator probabilities. After selecting parameters, run a separate evaluation with a fixed shot budget and record both the expected objective and the best feasible bit string observed. This separation prevents a favorable optimization sample from being mistaken for a stable final result.

Useful optimizer candidates include COBYLA, SPSA, Nelder-Mead, and gradient-based methods when the chosen simulator and circuit support reliable gradients. There is no universally best optimizer. Run several seeds, keep the initial parameters controlled, and compare the distribution of outcomes rather than only the single best run.

Inputs and assumptions

A reproducible QAOA experiment should treat every changing input as part of the result. Record the following fields:

  • Problem instance: graph edges, weights, vertex order, constraints, and the exact classical objective.
  • Encoding: binary-to-spin convention, Hamiltonian coefficients, constant offsets, penalty weights, and feasibility rules.
  • Circuit: qubit count, layer count p, mixer type, gate decomposition, connectivity assumptions, and transpilation settings if applicable.
  • Optimization: framework and version, optimizer, stopping rule, maximum iterations, parameter initialization, random seed, and number of independent restarts.
  • Sampling: shots per objective evaluation, final evaluation shots, measurement grouping if used, and whether readout or other error mitigation is enabled.
  • Baselines: exact enumeration for small instances, a classical heuristic, and the best-known value obtained under the same problem definition.

Shot noise affects both the estimated objective and the optimizer trajectory. If an observable has an estimated probability p from N shots, its sampling uncertainty generally decreases as N increases, but the result still depends on the observable and estimator. Use a fixed shot budget when comparing configurations, and report uncertainty or repeated-run variation where practical. The guide to quantum measurement uncertainty provides a useful framework for interpreting shot-based estimates.

Noise should be introduced only after the noiseless workflow is validated. First confirm that the Hamiltonian, circuit, and classical objective agree on small instances. Then add a noise model or hardware execution and compare the same metrics. Error mitigation can change estimates and sampling costs, so document the method rather than presenting a mitigated value as directly comparable to an unmitigated one. See the error mitigation benchmarking guide for a structured comparison approach.

Worked examples

Example A: a triangle graph

Consider three vertices connected by three unit-weight edges. The exact Max-Cut optimum places one vertex in one partition and two in the other, cutting two edges. The optimum objective is therefore 2, while the all-zero and all-one strings cut no edges.

For a first QAOA implementation, use three qubits, p = 1, an X mixer, and a simulator with a fixed final shot count. Evaluate several parameter initializations. For each run, store the expectation value, the most frequent bit string, its cut value, and the frequency of optimal strings. Because Max-Cut is invariant under swapping the two partitions, complementary strings such as 001 and 110 represent equivalent cuts. Your post-processing should account for that symmetry when summarizing solutions.

Next, repeat with p = 2 using the same graph, shot count, optimizer iteration limit, and number of restarts. A useful comparison table contains one row per configuration and columns for mean objective, standard deviation, best feasible objective, optimal-string probability, circuit depth, and total objective evaluations. This makes it possible to tell whether a deeper circuit improved the average outcome or merely produced a better isolated sample.

Example B: a weighted four-vertex graph

For a four-vertex graph with edge weights, calculate the classical optimum by enumerating all 16 assignments. Keep the edge list in a stable order and include the weights in the experiment record. Build the weighted cost Hamiltonian, run p = 1 and p = 2, and compare against the exact optimum.

Suppose the quantum run frequently produces a feasible assignment whose value is close to the optimum but not equal to it. Do not label the experiment successful or unsuccessful from that observation alone. Report the approximation ratio, defined here as the returned objective divided by the exact optimum for a maximization problem, together with the probability of sampling the best-known assignment. Also report runtime or evaluation count using the measurement appropriate to your environment. A simulator may be limited by state-vector memory, while a hardware workflow may be limited by queueing, execution, or shot budgets.

If you implement the same experiment in Qiskit or PennyLane, keep the mathematical specification unchanged and treat the framework code as an interchangeable execution layer. This prevents an API change from silently changing the problem. For a broader hybrid workflow, consult the research-prototype-to-application checklist.

A compact experiment log can use this template:

instance_id:
objective_definition:
encoding_convention:
qubits:
layers_p:
mixer:
optimizer:
initialization_seed:
max_iterations:
shots_per_evaluation:
final_shots:
noise_model_or_backend:
mitigation:
baseline_value:
mean_objective:
best_feasible_value:
optimal_or_best_known_probability:
notes:

When to recalculate

Recalculate the experiment whenever an input changes enough to affect comparability. At minimum, repeat the workflow when you change the graph or constraint instance, edge weights, penalty coefficients, QAOA depth, mixer, optimizer, parameter initialization policy, shot budget, noise model, transpilation settings, or backend. A framework upgrade also warrants a validation run because circuit-construction and execution APIs may change even when the mathematical problem does not.

Use a two-stage refresh. First, run a small known instance with an exact classical answer to confirm that the encoding still matches the intended objective. Second, rerun the benchmark suite with fixed seeds and fixed reporting fields. Keep the previous results rather than overwriting them; the purpose of a reproducible workflow is to distinguish an algorithmic improvement from a change in implementation or measurement conditions.

Before moving to hardware, estimate qubit count, depth, two-qubit gate count, and measurement workload with a quantum circuit resource worksheet. Then choose a backend whose connectivity and noise characteristics are appropriate for the circuit, using the hardware platforms comparison as a planning reference. If the circuit is too deep or the result is unstable, reduce the instance, simplify the encoding, test a shallower depth, or improve the classical baseline before increasing the quantum workload.

The practical decision rule is simple: keep QAOA experiments only when the problem definition, baseline, and measurement conditions are explicit enough for someone else to reproduce the comparison. Treat the quantum result as one point in a hybrid quantum-classical investigation, not as a standalone claim about optimization advantage.

Related Topics

#QAOA#quantum optimization#variational algorithms#combinatorial optimization#benchmarking
Q

Qbit Editorial Team

Quantum Computing Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.