Curriculum / Real-World Quantum Python / QAOA for MaxCut
QAOA for MaxCut
Implement QAOA for the MaxCut combinatorial optimization problem and analyze solution quality vs circuit depth.
QAOA for MaxCut
The Quantum Approximate Optimization Algorithm (QAOA) tackles combinatorial optimization. MaxCut, partition vertices into two sets to maximize crossing edges, is the canonical benchmark.
MaxCut: An NP-Hard Problem
Given a graph G = (V, E), partition V into sets S and S̄ to maximize |{(u,v) ∈ E : u ∈ S, v ∈ S̄}|. For a triangle graph (3 vertices, 3 edges), the optimal cut is 2 (any single vertex vs the other two).
MaxCut is NP-hard in general. The best classical approximation algorithm (Goemans-Williamson, 1995) achieves 0.878 × OPT using semidefinite programming. QAOA with p layers achieves at least 0.6924 for p=1, with guarantees improving with p.
QAOA Circuit Structure
QAOA prepares the state:
where:
- •: uniform superposition, H applied to all n qubits
- •: cost unitary, encodes the MaxCut objective
- •: mixer unitary, explores the solution space
Parameters (γ₁,...,γₚ, β₁,...,βₚ) are optimized classically to maximize the expected cut value.
Cost Unitary: Encoding MaxCut
For each edge (i,j) in the graph, the contribution to the Hamiltonian is:
The unitary decomposes per edge as :
- •CX(i,j) → RZ(γ, j) → CX(i,j)
This implements per edge.
Mixer Unitary: Exploring Solutions
The mixer simply applies to every qubit. This drives transitions between different cut assignments, ensuring the optimization explores the full space.
Classical Optimization
After the quantum circuit measures the expected cut value, a classical optimizer (grid search for p=1, COBYLA or gradient descent for p>1) finds the optimal parameters. For p=1 on the triangle graph, an exhaustive grid search over (γ, β) ∈ [0,2π]² works well.
QAOA with p=1 layer offers weak approximation guarantees (~0.692 for MaxCut). With p→∞, QAOA converges to the exact optimum. But each layer adds ~3 two-qubit gates per edge: a 10-edge graph with p=3 requires 90 CX gates. On current NISQ devices with T2~100μs and CX~300ns, this circuit accumulates substantial noise before completing. The sweet spot is currently p=1 or p=2.
This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.
How this lesson works
A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.
Part of: Real-World Quantum Python
Write production-quality quantum Python, circuit optimization, hybrid algorithms, cloud backends, noise modeling, and software engineering patterns.
This lesson is part of Pro
Unlock Real-World Quantum Python and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.