|q⟩ Bad Qubits

intermediate · Programming · QAOA & Combinatorial Optimization

Classical Optimization of Angles

QAOA circuits contain free parameters — the angle vectors γ\vec\gamma and β\vec\beta — that control how well the quantum state concentrates on high-quality solutions. Picking good parameters is not a quantum task; it is a classical optimization problem that sits in a feedback loop around the quantum circuit.

The expectation-value landscape

After running the QAOA circuit and measuring, you can estimate

C(γ,β)=ψ(γ,β)HCψ(γ,β),\langle C(\vec\gamma,\vec\beta)\rangle = \langle\psi(\vec\gamma,\vec\beta)|\,H_C\,|\psi(\vec\gamma,\vec\beta)\rangle,

the average cost over many shots. This number is a smooth function of the 2p2p real parameters, and the classical optimizer's job is to find the angles that maximize it.

For p=1p = 1 Max-Cut on a single edge (q0,q1)(q_0, q_1) the expectation value has a closed form. Starting from ++=H200|{+}{+}\rangle = H^{\otimes 2}|00\rangle and applying the cost unitary UC(γ)U_C(\gamma) followed by the mixer UB(β)U_B(\beta) gives a state whose overlap with the cut subspace can be computed analytically. The result is

C(γ,β)=12+14sin(2γ)sin(2β).\langle C(\gamma,\beta)\rangle = \tfrac{1}{2} + \tfrac{1}{4}\sin(2\gamma)\sin(2\beta).

You can verify this by expanding the state in the Bell basis or by direct matrix multiplication; the derivation follows Appendix B of Farhi et al. (2014).

Finding the optimal angles

The formula shows that C\langle C \rangle is maximised when both sine factors equal +1+1:

sin(2γ)=1    2γ=π2    γ=π4,\sin(2\gamma^*) = 1 \implies 2\gamma^* = \tfrac{\pi}{2} \implies \gamma^* = \tfrac{\pi}{4}, sin(2β)=1    β=π4.\sin(2\beta^*) = 1 \implies \beta^* = \tfrac{\pi}{4}.

Substituting back:

Cmax=12+1411=34.\langle C \rangle_{\max} = \tfrac{1}{2} + \tfrac{1}{4}\cdot 1 \cdot 1 = \tfrac{3}{4}.

The approximation ratio is Cmax/Cmax=(3/4)/1=3/4\langle C \rangle_{\max} / C_{\max} = (3/4) / 1 = 3/4, confirming that p=1p = 1 QAOA beats the trivial random-guess bound of 1/21/2 for this instance.

Classical optimizers in practice

In production QAOA implementations the loop looks like this:

  1. Propose a candidate (γ,β)(\gamma, \beta) — either analytically (as above for p=1p = 1) or via a gradient-free method.
  2. Execute the parameterized circuit on a quantum backend (or simulator).
  3. Estimate C\langle C \rangle by averaging the shot outcomes.
  4. Update the parameters using the optimizer's rule.
  5. Repeat until convergence.

The quantum computer is treated as a black-box function evaluator; the intelligence about which angles to try lives entirely in the classical optimizer.

For real devices, noise and shot sampling add stochastic error to each C\langle C \rangle estimate, so the optimizer must be robust to noisy gradients. Gradient-based methods can use the parameter-shift rule:

Cγk=C ⁣γk+π/4C ⁣γkπ/4.\frac{\partial \langle C \rangle}{\partial \gamma_k} = \langle C \rangle\!\big|_{\gamma_k + \pi/4} - \langle C \rangle\!\big|_{\gamma_k - \pi/4}.

This exact identity holds because each QAOA cost layer applies eiγkZjZke^{-i\gamma_k Z_j Z_k} (generator eigenvalues ±1\pm 1, shift =π/(41)=π/4= \pi/(4\cdot 1) = \pi/4, coefficient =1= 1). It requires two extra circuit evaluations per parameter but avoids finite-difference noise amplification.

Try it

Use the closed-form formula to compute the maximum achievable C\langle C \rangle for p=1p = 1 single-edge Max-Cut, and return it. No circuit needed — this is a purely classical calculation.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.