Quantum Computing · Part C — 10

Variational Circuits

Today’s machines are too noisy to run Shor on anything real. So the near-term strategy flips the script: keep the quantum circuit short, give it a few tunable knobs, and let an ordinary classical optimizer twist those knobs to minimize a cost. Quantum proposes, classical disposes — the hybrid loop.

↩ before you start · keep these handy
·From QC 01: a circuit is built from gates; a rotation gate Rẑ(θ) has a tunable angle.
·From QI Ch. 3: an expectation value ⟨H⟩ is the average of many measurements.
·From QI Ch. 9: real qubits decohere, so deep circuits accumulate error — keep them shallow.
🔑 symbol decoder · every new mark, in plain words
ansatza fixed circuit shape with adjustable angles — your guess at where the answer lives. (German for “starting form.”) θ (parameters)the tunable knobs — the rotation angles the optimizer is allowed to change. cost C(θ)a number you want to make small, measured from the circuit’s output — usually an energy ⟨H⟩. gradientthe slope of the cost — which way, and how steeply, C changes as you nudge θ. parameter-shifta trick to get the exact gradient from the hardware: C(θ+½π) − C(θ−½π), halved. NISQ“noisy intermediate-scale quantum” — today’s small, imperfect machines.
feel

A duet between two computers

The quantum chip does one thing it’s uniquely good at: prepare a complicated state and report a cost. It can’t decide what to try next — so a classical optimizer reads the cost, picks better angles, and sends them back. Round and round, the cost slides downhill. The quantum part stays shallow (noise-friendly); the thinking happens on the laptop.

🎵 everyday picture

Tuning a guitar by ear: you pluck a string (run the circuit), hear how far off it is (measure the cost), turn the peg a little (the optimizer adjusts θ), and pluck again. You don’t solve the physics of the string — you just keep nudging toward “in tune.” A variational algorithm tunes a quantum state the same way, peg by peg, until the cost can’t get any lower.

recapA shallow quantum circuit reports a cost; a classical optimizer tunes its angles to drive that cost down.
play

Run the optimization loop

One knob θ sets the state Rẑ(θ)|0⟩; the cost is the energy ⟨H⟩ for H = Z + ½X. Drag θ to feel the landscape, then hit step and watch the classical optimizer roll the ball downhill to the minimum.

▸ hybrid loopminimize C(θ) = ⟨H⟩
C θ
parameter θ = {{ thetaDeg }}°
iteration{{ iters }}
cost ⟨H⟩{{ energy }}
true minimum{{ minE }}
gradient{{ grad }}
{{ status }}
recapEach step moves θ downhill (θ ← θ − η·gradient); the ball settles at the lowest cost.
math

The loop, and how to get a gradient

The cost is an expectation value of the parameterized state, and the optimizer is plain gradient descent:

C(θ) = ⟨ψ(θ)| H |ψ(θ)⟩
θ ← θ − η · ∇C(θ)

But how do you get the gradient from a quantum computer, which only spits out measurements? The beautiful parameter-shift rule: evaluate the same circuit at two shifted angles — no finite-difference fudging, it’s exact:

∂C/∂θ = ½ [ C(θ + ½π) − C(θ − ½π) ]
✎ worked example · one-qubit VQE for H = Z
1.ansatz |ψ(θ)⟩ = Rẑ(θ)|0⟩, so ⟨Z⟩ = cosθ — that’s the cost C(θ)
2.parameter-shift: ½[cos(θ+½π) − cos(θ−½π)] = ½[−sinθ − sinθ] = −sinθ
3.which is exactly d(cosθ)/dθ — the rule nailed the true gradient ✓
4.descent drives θ → π, where C = cosπ = −1, the ground-state energy of Z
recapCost = ⟨H⟩; descend with θ←θ−η∇C; the parameter-shift rule gives the exact gradient from two circuit runs.
⚠ common misconceptions

“The quantum computer does the optimizing.” No — it only evaluates the cost (and gradients). The search over angles is run by a classical optimizer on a normal computer.

“It always finds the true minimum.” Like any gradient descent it can stall in a local minimum. Worse, large random circuits suffer barren plateaus — the landscape goes flat and gradients vanish, so a good ansatz really matters.

“Variational methods are proven to beat classical computers.” They’re a promising heuristic for the NISQ era, not a proven speed-up. Whether they give real quantum advantage is still an open research question.

✓ you can now
describe the hybrid loop: ansatz → measure cost → classical optimizer → new angles
write the cost C(θ) = ⟨H⟩ and the gradient-descent update
use the parameter-shift rule to get an exact gradient from circuit runs
name the pitfalls: local minima and barren plateaus, and why ansatz choice matters
← 09 Hamiltonian Simulation next · 11 VQE — Chemistry