Variational Quantum Eigensolver (VQE)
The VQE is a hybrid quantum-classical algorithm for finding the ground state energy of a Hamiltonian . It uses the variational principle:
where is a parameterized quantum state and is the true ground state energy. The algorithm minimizes using classical optimization while evaluating the energy on a quantum computer.
The loop is cheap to state and expensive to run correctly, so the two-qubit hydrogen example below is best read as a template. The Hamiltonian is six Pauli terms; each expectation value is estimated from shots; the classical optimizer calls the quantum device once per iteration, typically tens to hundreds of iterations of a few thousand shots each. Producing a dissociation curve means repeating that for 20 to 40 bond lengths between 0.3 and 2.5 Γ₯ngstrΓΆm, and chemical accuracy demands every point sit within 1.6 millihartree of the exact answer.
Measurement, not gate count, usually dominates the wall-clock time. The six Pauli terms of the hydrogen Hamiltonian group by measurement basis: the identity and the three -type terms all read out in the computational basis in one pass, needs a basis rotation first, and needs a different rotation. Three settings rather than six, each with its own shot budget, so one energy evaluation on this tiny system is three batches of shots. At hundreds of terms β the regime of any real molecule β basis grouping and the ordering of commuting measurements become their own optimisation problem on top of the classical loop.
Parameterized Quantum Circuits (PQCs)
A parameterized quantum circuit applies gates with tunable parameters :
where are parameterized rotations and are fixed entangling gates.
Common architectures:
- Hardware-efficient ansatz: native gate set, low depth
- UCCSD (Unitary Coupled Cluster): chemistry-inspired, systematic
- ADAPT-VQE: grows the circuit dynamically
The key challenge is avoiding barren plateaus β exponentially vanishing gradients in high-dimensional parameter spaces.
QAOA (Quantum Approximate Optimization Algorithm)
QAOA solves combinatorial optimization problems by alternating between problem and mixer Hamiltonians:
where:
- is the problem (cost) Hamiltonian
- is the mixer Hamiltonian
- is the QAOA depth
As , QAOA converges to the optimal solution. For MaxCut on 3-regular graphs, already gives a 0.6924 approximation ratio.
The honest comparison is against the classical baselines, and it changes how the algorithm should be positioned:
| Method | Approximation ratio | Cost |
|---|---|---|
| Random assignment | 0.500 guarantee | none |
| QAOA at , 3-regular | 0.6924 | parameters, very shallow circuit |
| Goemans-Williamson | 0.878 | polynomial-time SDP plus rounding |
| QAOA at large | approaches about 0.93 | depth and parameters grow with |
| Exact enumeration | 1.0 | evaluations |
Two conclusions follow. At low depth QAOA does not beat the best classical approximation for MaxCut, so the case for running it rests on instances where the SDP itself becomes too large, or on cost functions whose classical analogue is intractable. And raising closes the gap slowly: each layer adds two parameters and another round of entangling gates, and the optimizer must search a larger space each time, so the return per added layer diminishes even as it stays positive.
The Cost Function
For a combinatorial optimization problem with objective function , the cost Hamiltonian is:
The expectation value is estimated by sampling and averaged over many shots.
The optimization landscape can have local minima and saddle points, making classical optimizer choice critical.
Barren Plateaus
Barren plateaus are a fundamental challenge for variational algorithms. For random PQCs with qubits:
This means gradients vanish exponentially with system size.
Work the numbers through, because the abstract bound hides the practical cliff. The standard deviation of a gradient scales as , so at 20 qubits a typical gradient is about in magnitude. A single Pauli expectation estimated from 1000 shots carries shot noise of order β roughly thirty times larger than the signal being measured. To push the noise floor below needs of order shots per parameter-shift evaluation, and every added qubit doubles that requirement. Training stalls long before the optimizer gets stuck; the landscape simply stops being resolvable.
Mitigation strategies follow directly from that arithmetic:
- Layerwise training: start shallow, where the effective is small, and grow deeper
- Local cost functions: use local rather than global observables, whose variance scales with the volume of the region touched instead of the whole register
- Symmetry-preserving ansΓ€tze: tie parameters together so the searchable dimension stays far below the gate count
- Noise-aware training: treat the shot-noise floor as a hard limit and keep gradients above it
Python: VQE for H2 Molecule
import numpy as np
def vqe_h2():
# Simplified VQE for H2 molecule (minimal basis).
coeffs = {
'I': -0.4804, 'Z0': 0.3435, 'Z1': -0.4347,
'Z0Z1': 0.5716, 'X0X1': 0.0910, 'Y0Y1': 0.0910
}
def energy(theta):
e = coeffs['I']
e += coeffs['Z0'] * np.cos(2*theta)
e += coeffs['Z1'] * np.cos(2*theta)
e += coeffs['Z0Z1'] + coeffs['X0X1'] + coeffs['Y0Y1']
return e
from scipy.optimize import minimize
result = minimize(energy, 0.0, method='COBYLA')
print(f"Ground state energy: {result.fun:.6f} Ha")
print(f"Exact FCI energy: -1.1372 Ha")
vqe_h2()
This demonstrates the core VQE loop: prepare state, measure energy, optimize classically.
Python: QAOA on a Six-Qubit MaxCut
The same pattern applied to combinatorial optimisation, with the statevector standing in for the device so the approximation ratio can be checked against the exact optimum:
import numpy as np
from scipy.optimize import minimize
def cut_values(adj):
"""Cut size for every basis state, which is also the cost operator."""
n = len(adj)
idx = np.arange(2 ** n)
vals = np.zeros(2 ** n)
for i in range(n):
for j in range(i + 1, n):
if adj[i][j]:
vals += ((idx >> i) & 1) ^ ((idx >> j) & 1)
return vals
def apply_rx(state, q, beta):
"""Rx(2*beta) on qubit q, written directly on the amplitude vector."""
c, s = np.cos(beta), -1j * np.sin(beta)
out = state.astype(complex).copy()
bit = 1 << q
mask = (np.arange(out.size) & bit) == 0
v0, v1 = out[mask].copy(), out[~mask].copy()
out[mask] = c * v0 + s * v1
out[~mask] = s * v0 + c * v1
return out
def qaoa_objective(params, adj, vals, p):
"""Negative expected cut, since the optimizer minimises."""
n = len(adj)
state = np.ones(2 ** n, dtype=complex) / np.sqrt(2 ** n)
for g, b in zip(params[:p], params[p:]):
state = state * np.exp(-1j * g * vals) # problem Hamiltonian
for q in range(n):
state = apply_rx(state, q, b) # mixer Hamiltonian
return -float((np.abs(state) ** 2) @ vals)
def run(adj, p, seed=0, restarts=12):
vals = cut_values(adj)
rng = np.random.default_rng(seed)
best = 0.0
for _ in range(restarts):
x0 = rng.uniform(0, np.pi, 2 * p)
res = minimize(qaoa_objective, x0, args=(adj, vals, p),
method="COBYLA", options={"maxiter": 400})
best = max(best, -res.fun)
return vals.max(), best
adj = [[0] * 6 for _ in range(6)]
for u, v in [(0, 1), (1, 2), (2, 0), (3, 4), (4, 5), (5, 3),
(0, 3), (1, 4), (2, 5)]:
adj[u][v] = adj[v][u] = 1 # prism graph, 3-regular
optimal, _ = run(adj, p=1)
for p in (1, 2, 3):
_, value = run(adj, p=p)
print(f"p={p}: cut={value:.4f} ratio={value / optimal:.4f}")
The prism graph has an optimal cut of 7. Random assignment would average 4.5 here β a ratio of 0.64 on this instance, against the usual 0.5 guarantee in general; the run above reaches 0.849 at , 0.943 at and 0.983 at . On six qubits the optimizer finds those angles in a fraction of a second, but the trend is the same one that governs larger instances: each extra layer buys a smaller increment, requires two more angles, and adds another round of entangling gates that real hardware pays for in error.
Circuit Ansatz Design
The choice of ansatz circuit is critical for VQE performance:
Hardware-efficient ansatz: uses native gate set with minimal depth. Pros: fast execution. Cons: may not represent ground state well.
UCCSD (Unitary Coupled Cluster Singles and Doubles): chemistry-inspired ansatz that systematically includes excitations. Pros: physically motivated. Cons: deep circuits.
ADAPT-VQE: dynamically grows the circuit by selecting the most impactful operator at each step. Pros: optimal circuit depth. Cons: requires adaptive circuit compilation.
Parameter Optimization Landscape
The VQE energy landscape can have:
- Local minima: suboptimal parameter configurations
- Saddle points: flat directions in parameter space
- Barren plateaus: exponentially vanishing gradients
- Noise-induced local minima: hardware errors create artificial minima
Strategies to handle these challenges:
- Multiple random initializations
- Layerwise training (start shallow, grow deeper)
- Gradient-free optimizers (COBYLA, Nelder-Mead)
- Noise-aware training
Common Mistakes
Counting gates and ignoring the shot budget when estimating an energy
Fix: Group Pauli terms by measurement basis first β the six-term hydrogen Hamiltonian needs three settings rather than six, and grouping sets the run time
Reporting a QAOA ratio without the classical baseline beside it
Fix: Quote random assignment, the 0.878 Goemans-Williamson guarantee and the exact optimum together, so a 0.6924 result is read in the right frame
Raising ansatz depth to escape a flat optimizer landscape
Fix: Deeper random circuits make the barren plateau worse; grow layerwise, tie parameters, or switch to a local cost function instead
Taking a single VQE run as the ground-state energy
Fix: Restart from several random initializations and compare against a classical exact result on a small instance, since local minima sit arbitrarily close to the optimum
Key Takeaways
- VQE minimises a parameterised state's energy with a classical loop while the quantum device only ever evaluates expectation values, in a handful of measurement bases per call
- QAOA alternates problem and mixer unitaries, and at P equals 1 reaches 0.6924 on 3-regular MaxCut β below the 0.878 classical Goemans-Williamson guarantee
- Barren plateaus make gradient variance fall as two to the minus n, so at 20 qubits shot noise exceeds the signal and roughly a million shots per evaluation becomes necessary
- Ansatz choice is a trade-off between expressibility and depth: hardware-efficient ansΓ€tze run fast but flatten the landscape, while chemistry-inspired ones are deep but structured