Cost Hamiltonians
In the Quantum Approximate Optimization Algorithm (QAOA), finding a good solution to a combinatorial problem requires encoding that problem's objective function as a Hamiltonian. The circuit then applies this Hamiltonian as a phase gate, so that basis states representing cheaper solutions accumulate more phase — which interference amplifies into higher probability. This lesson shows exactly how that encoding works.
From cost function to Hamiltonian
Consider the MaxCut problem: given a graph, partition its vertices into two sets so that the number of edges crossing the partition is as large as possible. Each vertex is assigned a binary variable .
An edge contributes to the cut when . The contribution of a single edge can be written as
The Pauli operator has eigenvalues on and on , so is exactly the eigenvalue of . Replacing classical bits by Pauli operators gives the quantum operator for one edge:
The full cost Hamiltonian is the sum over all edges:
Because is diagonal in the computational basis, its eigenvalues are exactly the integer cut values of each bitstring. A bitstring that cuts edges is an eigenstate of with eigenvalue .
The phase-encoding unitary
QAOA does not apply as a measurement; it applies it as a time evolution with variational angle :
Because each commutes with every other (they share the same diagonal basis), the product factorizes edge by edge:
The global phase from the identity part is unobservable, so only the term matters. For one edge the essential unitary is
Circuit for
To implement in terms of standard gates, use the identity
which follows from mapping and from how Pauli operators transform under conjugation. Inserting this decomposition yields
where is the standard rotation. For a single edge with the angle is and the argument is .
The three-gate sequence has depth 3 (two CNOTs and one ) and applies one edge's cost Hamiltonian exactly, without approximation.
Try it
Complete the circuit that starts in the uniform superposition and applies — the cost unitary for a single-edge MaxCut instance with . The grader checks the full statevector, so the correct three-gate insertion is required to pass.
Sign in on the full site to ask questions and join the discussion.