A single QAOA layer is a rough approximation. Stacking p layers — each with its
own pair of angles (γk,βk) — gives the optimizer more freedom and
generally produces better solutions. This lesson builds the p=2 circuit from
scratch.
QAOA recap: one layer
For a problem graph with edges E, the cost Hamiltonian is
HC=21(i,j)∈E∑(I−ZiZj).
A single QAOA layer applies two unitaries in sequence:
UC(γ)=eiγHC,UB(β)=e−iβHB,
where HB=∑iXi is the mixing Hamiltonian. Starting from the uniform superposition
∣s⟩=H⊗n∣0⟩⊗n, one full layer reads
The 2p real parameters (γ1,…,γp,β1,…,βp) are tuned
by a classical optimizer to maximize ⟨HC⟩. As p→∞, the QAOA
state can exactly represent the true optimum; finite p trades circuit depth for
solution quality.
Building the circuit gates
For a graph with a single edge (0,1), the ZZ interaction e−iγZ0Z1/2
is compiled as three gates:
e−i(γ/2)Z0Z1=CX01⋅RZ(γ)1⋅CX01.
The factor of 1/2 in the Hamiltonian means the angle passed to RZ is
γ (one factor of 2 from the eigenvalue of Z0Z1, one from the exponent
convention of RZ).
The mixer e−iβXq on each qubit q is a single rotation gate:
e−iβXq=RX(2β)q.
The extra factor of 2 arises because RX(θ)=e−i(θ/2)X.
The superposition is prepared once; then each layer alternates the cost and mixer
unitaries with independent angles.
Try it
Complete the p=2 circuit using the fixed angles γ1=0.4, γ2=0.8,
β1=0.3, β2=0.6. The grader compares the full statevector, so every
gate placement matters.
Run your code to see the quantum state.
Sign in on the full site to ask questions and join the discussion.