This checkpoint asks you to assemble a complete QAOA circuit for a new graph — from blank starter
code — and verify that the output distribution concentrates on the optimal cuts. No scaffolding
is provided: you apply every gate yourself.
The problem graph
Three nodes connected in a line (a path graphP3):
0−1−2
Edge set E={(0,1),(1,2)}. Each qubit represents a vertex; ∣0⟩ places a vertex in
partition S and ∣1⟩ places it in Sˉ. An edge contributes 1 to the cut value when
its endpoints are in opposite partitions.
Optimal cuts
The maximum cut value for P3 is 2 (both edges are cut). The two bitstrings that achieve
this are 010 (vertex 1 alone in Sˉ) and 101 (vertices 0 and 2 alone in Sˉ). Every
other assignment cuts at most one edge.
QAOA p=1 recipe
The p=1 QAOA ansatz is
∣γ,β⟩=UB(β)UC(γ)H⊗3∣000⟩,
where
UC(γ)=e−iγHC,HC=(i,j)∈E∑21(I−ZiZj),
and the transverse-field mixer is
UB(β)=e−iβHB,HB=X0+X1+X2.
Compiling the cost unitary
The ZZ rotation for one edge (i,j) decomposes as
e−i(γ/2)ZiZj=CXij⋅Rz(γ)j⋅CXij.
Because HC contains a factor of 21 and Rz(θ)=e−i(θ/2)Z, the
angle you pass to Rz is 2γ.
Apply the CNOT-RZ-CNOT block for edge (0,1) and then for edge (1,2).
Compiling the mixer
Each term e−iβXq is a single rotation:
e−iβXq=Rx(2β)q.
The factor of 2 arises from the convention Rx(θ)=e−i(θ/2)X.
Decoding the result
After measurement, the most frequent bitstrings tell you the best cut found. Bitstring b0b1b2 encodes the partition: vertex q goes to Sˉ if bq=1. For 010 the
partition is {0,2}∣{1}; for 101 it is {1}∣{0,2} — the same cut by
symmetry.
The approximation ratioα for a single run is Cbest/Cmax. Here
Cmax=2, and if the QAOA output is one of the optimal strings then α=1.
Try it
Build the complete QAOA circuit for P3 with the fixed angles γ=3π/4,
β=π/8. The grader checks the output distribution, so an empty or
incomplete circuit will fail — the angles must actually shift probability onto
∣010⟩ and ∣101⟩.
Run your code to see the quantum state.
Sign in on the full site to ask questions and join the discussion.