MaxCut and what "approximation ratio" means
Given a graph with vertices, a cut assigns each vertex to one of two sides, and its value is the number of edges whose endpoints lie on different sides. MaxCut asks for the largest cut value, . Deciding whether a cut of a given size exists is NP-complete, so no polynomial-time exact algorithm is expected, and practical work focuses on approximation.
Two different numbers are both called an approximation ratio, and mixing them up is the most common error in QAOA claims.
- Instance ratio. For one graph and one algorithm, the (expected) value found divided by . Measuring it requires knowing , which for small graphs means brute force.
- Worst-case guarantee. A number such that the algorithm achieves at least (in expectation) on every graph. This is a theorem about an algorithm.
A ratio of 0.94 on a six-vertex graph says nothing about a guarantee.
MaxCut as an Ising Hamiltonian
Encode an assignment as a bit string . An edge is cut when . With , the operator has eigenvalue 1 on cut edges and 0 otherwise, so
is diagonal: every computational basis state is an eigenstate, and its eigenvalue is the cut value. MaxCut is the problem of finding the largest eigenvalue of , or equivalently the ground state of the Ising Hamiltonian , an antiferromagnet on .
In this lesson's exercise, vertex is bit of the integer counted from the least
significant end, so vertex 0 is the rightmost character of a bit string. That is the opposite of the
course's usual qubit order, chosen so that assignments can be compared with the KetQat SDK's
qaoa-maxcut product directly; for a cut value only consistency matters.
The QAOA ansatz
The Quantum Approximate Optimization Algorithm of Farhi, Goldstone and Gutmann prepares
with angles, and chooses them to maximise (Farhi, Goldstone and Gutmann 2014). Measuring the final state gives assignments whose average cut is . The paper shows that the best value of cannot decrease with and approaches as , through a connection with adiabatic evolution; how fast it does so is instance-dependent.
Compiling a layer. The cost layer factorises over edges, since all terms commute: . Because , each edge needs two CNOTs and one . The mixer is on every vertex. One layer on a triangle:
So one layer costs CNOTs plus rotations before routing on real hardware.
Symmetries of the landscape
The search space is smaller than it looks. Because cut values are integers, , so each has period . Because and (flipping every vertex) commutes with and fixes , each has period for MaxCut. And because and are real, conjugates the state and leaves unchanged. The exercise checks all three on the prism graph below: at , , and the expectation is every time. The SDK's grid uses and , which covers every distinct point twice over in ; that costs time, not correctness.
The p = 1 expectation in closed form
At depth one, is a sum of edge terms, and each edge term depends only on the edge's neighbourhood, because gates far from the edge cancel in . Wang, Hadfield, Jiang and Rieffel derived the closed form for an arbitrary graph (Wang et al. 2018). With , and the number of triangles containing the edge, in the conventions above,
Conventions matter here: papers differ in the sign of , in whether the mixer is or , and in whether counts cut or uncut edges. Before trusting any closed form, compare it with a simulation at random angles; the exercise does this on graphs with and without triangles, and the agreement is at the level of .
Triangle-free -regular graphs. With and the formula reduces to , the case treated by Farhi, Goldstone and Gutmann. It is maximised at and .
- For (rings), the maximum of is , so each edge is cut with probability . For an even ring every edge can be cut, so the instance ratio is exactly . For the six-vertex ring, against .
- For , the maximum of is , so each edge is cut with probability . For a bipartite 3-regular graph such as the three-dimensional cube () the ratio is therefore . Farhi, Goldstone and Gutmann proved that on every 3-regular graph QAOA at achieves at least times the optimal cut: that is a worst-case guarantee, and the cube shows it is essentially tight.
A worked example: the prism graph
The triangular prism has six vertices, two triangles and , and three rungs , , : nine edges, 3-regular, but not triangle-free. Each triangle can have at most two of its three edges cut, so , and brute force confirms . All the numbers below were computed with the exercise's reference solution.
| method | expected or found cut | ratio to |
|---|---|---|
| uniformly random assignment | 4.5 | 0.643 |
| QAOA , grid | 5.90625 | 0.844 |
| QAOA , local optimisation of the closed form | 5.93922 | 0.848 |
| QAOA , -point grid | 6.35999 | 0.909 |
| QAOA , BFGS from 40 seeded random starts | 6.60295 | 0.943 |
| 1-flip local search, one random start | 7 | 1 |
At the continuous optimum, , measuring the QAOA state returns an optimal cut with probability , so a handful of shots finds the optimum on this instance. The coarse landscape at , from the closed form (rows , columns ):
| \ | 0 | ||||
|---|---|---|---|---|---|
| 0 | 4.500 | 4.500 | 4.500 | 4.500 | 4.500 |
| 4.500 | 5.484 | 5.782 | 5.219 | 4.125 | |
| 4.500 | 5.515 | 5.716 | 4.985 | 3.750 | |
| 4.500 | 4.876 | 4.921 | 4.610 | 4.125 | |
| 4.500 | 4.500 | 4.500 | 4.500 | 4.500 |
The row is flat at because is an eigenstate of the mixer, and the column is flat because without mixing the cost layer only adds phases to basis states. The row is also flat here because removes every term of the closed form for the prism's edges; that is not true for every graph (on a lone triangle it fails). These flat directions are why random initialisation can stall, and why grid search, although exponential in , is the honest choice at : at its resolution it is exhaustive, so the reported value is a lower bound on what QAOA can reach, not where an optimiser happened to stop. The two rows of the table show the price of resolution: the grid per layer misses about 0.24 of expected cut that local optimisation finds.
Classical baselines, stated precisely
A fair comparison needs the right classical numbers.
- Random assignment cuts each edge with probability : expected value .
- 1-flip local search moves single vertices while that increases the cut. At a local optimum every vertex has at least half of its edges cut (otherwise flipping it would help), and summing over vertices gives a cut of at least . That is a deterministic guarantee of , and on small graphs local search with a few restarts is usually optimal, as on the prism.
- Goemans–Williamson. Semidefinite programming followed by random-hyperplane rounding achieves an expected cut of at least with on every graph (Goemans and Williamson 1995). This is a worst-case guarantee.
- Hardness. Approximating MaxCut better than is NP-hard (Håstad 2001). If the Unique Games Conjecture holds, beating by any constant is NP-hard (Khot, Kindler, Mossel and O'Donnell 2007).
Against these, the proven worst-case guarantee for QAOA at on 3-regular graphs is , below Goemans–Williamson. There are also proven limitations at low depth: Bravyi, Kliesch, Koenig and Tang showed that on families of regular bipartite graphs, QAOA whose depth grows more slowly than logarithmically in the number of vertices has approximation ratios bounded away from 1, on graphs whose optimal cut a classical algorithm finds trivially (Bravyi et al. 2020). Whether QAOA at larger depth beats the best classical algorithms on instances of practical interest is an open, empirical question. A correct statement of the prism result is: "on this six-vertex instance, QAOA with optimised angles has an expected cut of , ratio ; local search finds the optimum with one restart." It is not evidence of a quantum advantage.
Using the SDK product
The SDK runs the same grid search with its own simulator and reports the closed form beside the simulation where it applies (KetQat SDK):
from ketqat_runner import catalog
edges = ["0-1", "1-2", "2-0", "3-4", "4-5", "5-3", "0-3", "1-4", "2-5"]
record = catalog.run("[email protected]", seed=7, graph="custom", n_vertices=6, edges=edges,
layers=1, grid=24, shots=1000)
r = record.result
print(r["max_cut"], round(r["best_expectation"], 6), round(r["approximation_ratio"], 6),
r["analytic_p1_applies"])
This prints 7 5.90625 0.84375 False: the same grid optimum as the table. The SDK evaluates its
closed form only for triangle-free regular graphs, where the Farhi–Goldstone–Gutmann formula holds,
so for the prism it reports that the formula does not apply; your exercise implements the general
formula.
Exercise: a QAOA study
In qaoa-maxcut-study you implement cut values, the QAOA state and expectation, the general
closed form, grid search, brute force and 1-flip local search. The checks compare the closed form with
simulation on five graphs (including , the prism and a seeded random graph with triangles),
recover the ring's and the cube's from the formula, check that local search returns a
genuine local optimum with at least , and compare your grid optimum and brute-force optimum
with the SDK product on three instances, one at .
Common mistakes
- Calling an instance ratio a guarantee. A ratio measured on one small graph is an observation.
- Comparing with random guessing only. The baselines that matter are local search, Goemans–Williamson and specialised heuristics.
- Trusting a closed form without checking its conventions. Sign of , factor 2 in the mixer, and cut versus uncut edges all change the formula.
- Searching over . For MaxCut the period is ; extra range only wastes evaluations.
- Reporting the best sampled cut as QAOA's performance without the number of shots. With enough samples even random assignments find the optimum of a small graph.
Summary
MaxCut becomes the diagonal Hamiltonian , and QAOA alternates (two CNOTs and an per edge) with the mixer . The landscape has period in , in and a reflection symmetry. At the expectation has a closed form for any graph, which gives exactly on even rings and on bipartite 3-regular graphs, consistent with the proven guarantee on 3-regular graphs. On the prism graph, optimised QAOA reaches an instance ratio of , while 1-flip local search solves the instance outright. Goemans–Williamson guarantees on every graph, and beating it is NP-hard under the Unique Games Conjecture, so any QAOA advantage claim must be made against that bar, on instances large enough to matter. The next lesson applies the same scrutiny to quantum machine learning.