Lesson 14 of 15

Variational Quantum Eigensolver (VQE)

Variational Quantum Eigensolver (VQE)

The Variational Quantum Eigensolver is the prototypical hybrid quantum-classical algorithm. It uses a quantum computer to evaluate an energy function and a classical optimizer to minimize it, finding the ground state of a Hamiltonian.

The Variational Principle

The key mathematical foundation is the Rayleigh–Ritz variational principle: for any normalized trial state ψ(θ)|\psi(\theta)\rangle,

E(θ)=ψ(θ)Hψ(θ)E0E(\theta) = \langle\psi(\theta)|\, H\, |\psi(\theta)\rangle \geq E_0

where E0E_0 is the true ground state energy. Minimizing E(θ)E(\theta) over the parameters θ\theta gives the best approximation within the ansatz family.

The Ansatz

For the simplest case H=ZH = Z, we use the single-parameter ansatz:

ψ(θ)=Ry(θ)0=cosθ20+sinθ21|\psi(\theta)\rangle = R_y(\theta)|0\rangle = \cos\frac{\theta}{2}|0\rangle + \sin\frac{\theta}{2}|1\rangle

The RyR_y gate rotates the Bloch vector within the XZXZ-plane, covering all real-amplitude states from 0|0\rangle (at θ=0\theta=0) to 1|1\rangle (at θ=π\theta=\pi).

Energy Landscape

Substituting into the ZZ expectation value formula from the previous lesson:

E(θ)=ψ(θ)Zψ(θ)=cos2θ2sin2θ2=cosθE(\theta) = \langle\psi(\theta)|Z|\psi(\theta)\rangle = \cos^2\frac{\theta}{2} - \sin^2\frac{\theta}{2} = \cos\theta

The energy landscape is a simple cosine:

  • Maximum at θ=0\theta = 0: E=+1E = +1 (state 0|0\rangle, eigenvalue +1+1 of ZZ)
  • Minimum at θ=π\theta = \pi: E=1E = -1 (state 1|1\rangle, eigenvalue 1-1 of ZZ, the ground state)

Gradient Descent Optimization

The classical optimizer computes the gradient:

dEdθ=sinθ\frac{dE}{d\theta} = -\sin\theta

and updates:

θθηdEdθ=θ+ηsinθ\theta \leftarrow \theta - \eta \cdot \frac{dE}{d\theta} = \theta + \eta\sin\theta

Starting near θ=0\theta = 0 and running gradient descent converges to θ=π\theta = \pi.

Note: On a real quantum computer, the gradient is estimated using the parameter shift rule: dEdθ=12[E(θ+π/2)E(θπ/2)]\frac{dE}{d\theta} = \frac{1}{2}[E(\theta + \pi/2) - E(\theta - \pi/2)], which requires only two extra circuit evaluations.

VQE Workflow

Initialize θ randomly
Repeat:
  1. Prepare |ψ(θ)⟩ on quantum hardware
  2. Measure ⟨H⟩ = E(θ)         ← quantum step
  3. Compute gradient classically
  4. Update θ ← θ - η·∇E        ← classical step
Until convergence

Scaling to Real Problems

For molecular Hamiltonians like H2H_2, VQE expresses HH as a sum of Pauli strings (e.g., H=c0I+c1Z0+c2Z1+c3Z0Z1+c4X0X1H = c_0 I + c_1 Z_0 + c_2 Z_1 + c_3 Z_0 Z_1 + c_4 X_0 X_1) and measures each term separately. The ansatz uses chemically motivated circuits (UCCSD). VQE is expected to show quantum advantage for strongly correlated molecules beyond the reach of classical methods.

Your Task

Implement:

  1. energy(theta) — return E(θ)=cosθE(\theta) = \cos\theta
  2. vqe_minimize() — run gradient descent for 100 steps with learning rate 0.3 starting at θ=0.1\theta = 0.1, and return the minimized energy rounded to 4 decimal places
Python runtime loading...
Loading...
Click "Run" to execute your code.