Lesson 15 of 15

QAOA: Quantum Approximate Optimization

QAOA: Quantum Approximate Optimization Algorithm

The Quantum Approximate Optimization Algorithm (QAOA), introduced by Farhi, Goldstone, and Gutmann (2014), is a leading candidate for demonstrating quantum advantage on combinatorial optimization problems.

The MaxCut Problem

Given a graph G=(V,E)G = (V, E), MaxCut asks for a partition of vertices into two sets SS and Sˉ\bar{S} that maximizes the number of edges crossing between them.

MaxCut is NP-hard in general, but QAOA provides a systematic quantum approximation scheme that improves with the number of layers pp.

Cost Hamiltonian

For each edge (u,v)(u, v), the cost Hamiltonian encodes a +1 energy whenever the edge is cut:

C=(u,v)E1ZuZv2C = \sum_{(u,v) \in E} \frac{1 - Z_u Z_v}{2}

When qubits uu and vv are in different states (ZuZv=1Z_u Z_v = -1), this contributes 1; when in the same state (ZuZv=+1Z_u Z_v = +1), it contributes 0. So C\langle C \rangle is exactly the expected number of cut edges.

The QAOA Circuit

Starting from the uniform superposition +n|+\rangle^{\otimes n} (all vertices equally in both sets), QAOA applies pp alternating layers:

γ,β=eiβpBeiγpCeiβ1Beiγ1C+n|\gamma, \beta\rangle = e^{-i\beta_p B}\, e^{-i\gamma_p C} \cdots e^{-i\beta_1 B}\, e^{-i\gamma_1 C}\, |+\rangle^{\otimes n}

  • Phase separator eiγCe^{-i\gamma C}: applies phase eiγe^{-i\gamma} to basis states where edge (u,v)(u,v) is cut
  • Mixer eiβBe^{-i\beta B} where B=uXuB = \sum_u X_u: applies Rx(2β)R_x(2\beta) independently to each qubit, exploring the superposition

As pp \to \infty with optimal parameters, QAOA converges to the exact MaxCut solution.

2-Node Example (p=1)

For the simplest graph with one edge (0,1)(0, 1), the MaxCut optimum is 1 (the edge is always cut when the two nodes are in opposite sets).

The QAOA state-vector evolution for basis states 00,01,10,11|00\rangle, |01\rangle, |10\rangle, |11\rangle:

Initial: 12(00+01+10+11)\tfrac{1}{2}(|00\rangle + |01\rangle + |10\rangle + |11\rangle)

After phase separator (cost = 1 for 01|01\rangle and 10|10\rangle, cost = 0 for 00|00\rangle and 11|11\rangle):

12(00+eiγ01+eiγ10+11)\tfrac{1}{2}\bigl(|00\rangle + e^{-i\gamma}|01\rangle + e^{-i\gamma}|10\rangle + |11\rangle\bigr)

After mixer Rx(2β)Rx(2β)R_x(2\beta) \otimes R_x(2\beta): each qubit independently mixed via:

Rx(2β)=(cosβisinβisinβcosβ)R_x(2\beta) = \begin{pmatrix}\cos\beta & -i\sin\beta \\ -i\sin\beta & \cos\beta\end{pmatrix}

Optimal parameters: γ=π/2\gamma = \pi/2, β=π/8\beta = \pi/8 achieve C=1\langle C \rangle = 1 — the exact maximum cut!

Why QAOA Finds the Optimum Here

At γ=π/2\gamma = \pi/2 the phase separator applies eiπ/2=ie^{-i\pi/2} = -i to the cut states, creating destructive interference for the non-cut states 00|00\rangle and 11|11\rangle after the mixer. At β=π/8\beta = \pi/8 the mixer balances the interference precisely so that all probability flows into 01|01\rangle and 10|10\rangle.

Your Task

Implement:

  1. qaoa_maxcut(gamma, beta) — simulate the p=1 QAOA circuit on a 2-node graph with edge (0,1), returning the expected cut value C=P(01)+P(10)\langle C \rangle = P(|01\rangle) + P(|10\rangle)
  2. qaoa_optimize() — grid-search over γ[0,π)\gamma \in [0, \pi) and β[0,π/2)\beta \in [0, \pi/2) (20 steps each) to find the maximum C\langle C \rangle, returned rounded to 4 decimal places
Python runtime loading...
Loading...
Click "Run" to execute your code.