Max-Cut with QAOA
Previous lessons built the cost unitary and the mixing unitary in isolation. This lesson assembles them into a working p = 1 QAOA circuit and runs it on a concrete example: a three-node triangle graph.
The triangle instance
Let the graph have vertices and edges . Each vertex becomes one qubit: places a vertex in partition and places it in . An edge contributes to the cut value when the two endpoints land in different partitions, i.e. when .
The cost function for a bitstring is
For the triangle, the maximum cut value is 2 (any single vertex alone on one side, the other two on the other side). The six optimal bitstrings are . The two all-same strings and give cut value 0.
QAOA p = 1 structure
A single QAOA layer has three stages.
Stage 1: Initialisation. Apply to every qubit to create the uniform superposition over all bitstrings:
Stage 2: Cost unitary. For each edge apply the two-qubit entangling block that implements (up to a global phase from the full ):
The derivation uses the conjugation identity and the fact that (since , so ). Applying this block for every edge implements (up to global phase) where
The eigenvalue of on bitstring is exactly , so states with more cut edges acquire a larger phase rotation — this is how QAOA encodes the objective.
Stage 3: Mixer. Apply to each qubit:
The mixer moves amplitude between bitstrings in a controlled way, amplifying the high-cut states through interference.
What to expect from the output
With the angles above the simulator produces a distribution where all six bitstrings with cut value 2 share the probability mass equally (by the symmetry of the triangle), and the zero-cut strings and are strongly suppressed. A classical random partition achieves only 75% probability of a near-optimal assignment in the same setup, so QAOA already does better with a single layer.
Try it
Complete the cost-unitary block by adding the CNOT-RZ-CNOT pattern for each of the three edges. The mixer and measurement are already in place. The grader checks the output distribution, so leaving the cost-unitary lines empty will fail — the circuit must actually phase-encode the cut objective before the mixer can do its job.
Sign in on the full site to ask questions and join the discussion.