The Variational Quantum Eigensolver
Quantum Computing
What you need to know first 12 concepts, 6 layers
The requisite-knowledge inventory for this page, bottom-up: the primitives at the base, combined upward until you reach what this page assumes. Skim the layers you already own; start wherever the ground gets unfamiliar.
- base
- Linear algebraconcept
- Quantum mechanics (states & operators)
- L1
- Functional derivatives
- Matrix eigenvalue problems
- Qubits, gates & measurementconcept
- Two-electron integrals (ERIs)
- L2
- Fermion-to-qubit mapping (Jordan-Wigner)concept
- Variational principle
- L3
- L4
- Electron correlationconcept
- SCF iteration
- L5
- ↳you are here
4 of these are concepts without a dedicated page yet — the grey chips. Following the linked ones first makes the rest land.
The variational quantum eigensolver finds a molecule's ground-state energy by running the variational principle on a quantum computer: prepare a trial state with a tunable circuit, measure its energy, and let a classical optimizer turn the knobs down. It solves the same H₂ you build from scratch — same integrals, same binding curve — by a completely different machine. Five ways in.
The whole thing rests on one inequality you already know: for any normalized trial state, , the true ground-state energy. So parametrize the trial state by some knobs , evaluate the energy, and minimize:
VQE changes exactly one thing about this familiar recipe: the state is prepared by a quantum circuit, and the energy is read off by measuring qubits. The minimization is still done by an ordinary classical optimizer. Watch it in the demo: the landscape never dips below the green floor , and the minimum sits exactly on it.
A quantum computer doesn't speak in electrons and orbitals; it speaks in qubits and Pauli operators. So the electronic Hamiltonian is rewritten — through a fermion-to-qubit map like Jordan–Wigner — as a weighted sum of Pauli strings:
For H₂ in the minimal basis this collapses, after using the molecule's symmetries, to a tiny two-qubit operator , whose coefficients are built from the same one- and two-electron integrals as Hartree–Fock. The energy is then — each a number you get by measuring the qubits.
The trial state is whatever a parametrized circuit produces, . The art is choosing rich enough to contain the true ground state but shallow enough to actually run. For H₂, the singlet ground state lives in a two-dimensional space spanned by the Hartree–Fock configuration and its double excitation , so one rotation angle suffices: .
That is the entire ansatz, and the demo's left panel is its energy landscape. The loop is hybrid: the quantum device prepares and reports ; a classical optimizer on your laptop proposes the next . Quantum where it helps, classical where it doesn't.
Why bother with a quantum computer at all? Because the trial state is the bottleneck. Classically, a general -orbital wavefunction has amplitudes — the same exponential wall that full configuration interaction hits and that DMRG tiptoes around. A quantum computer stores that state in qubits natively, and a few measurements estimate without ever writing the amplitudes down.
VQE is built for this trade. It keeps the circuit shallow and offloads the optimization to a classical computer, which is what makes it the leading candidate for near-term (noisy, few-qubit) hardware — you don't need a fault-tolerant machine to vary one angle and measure an energy.
Here is the physics payoff, in the demo's right panel. Slide the bond length out toward dissociation and watch restricted Hartree–Fock (orange) climb to the wrong energy — it cannot describe two atoms pulling apart, the textbook static-correlation failure that the RHF/UHF story is about.
VQE (the variational minimum, indigo) follows the correct curve, because its two-configuration ansatz can mix in the state that lets the bond break. Same molecule, same integrals as your from-scratch SCF — but by going one step past Hartree–Fock on a quantum circuit, you recover the correlation energy that makes the chemistry come out right.
Be the optimizer
Left: the variational landscape at the bond length you choose. Drag — you are the classical optimizer — and try to reach the green floor ; the orange dot is where Hartree–Fock sits (), and the gap between it and the floor is the correlation energy. Right: the H₂ binding curve, VQE versus Hartree–Fock, with your bond length marked. Everything is the validated STO-3G H₂ — the same molecule, three ways across this site.
At R = 1.38 bohr, your ansatz gives E(θ) = -1.1172 ≥ E₀ = -1.1373 Ha. Drag θ down to the floor, or press Minimize — the variational principle guarantees you can never go below E₀.
The whole optimizer, in code
With H₂ reduced to one angle, the entire VQE is a one-line energy function and a gradient walk. On real hardware the energy comes from measuring qubits and the optimizer is fancier, but the skeleton — evaluate , step downhill, repeat — is exactly this.
import numpy as np
# H2 / STO-3G reduced to its 2-configuration model (validated: HF -1.1167,
# FCI -1.1373 at R=1.4 bohr). The singlet ground state lives in span{|g^2>,|u^2>},
# so the whole VQE is one rotation angle θ: |ψ(θ)> = cos θ |g^2> - sin θ |u^2>.
def energy(theta, H00, H11, H01): # <ψ(θ)| H |ψ(θ)>
c, s = np.cos(theta), np.sin(theta)
return c*c*H00 + s*s*H11 + 2*c*s*H01
# The quantum-classical loop: the "quantum computer" returns energy(θ);
# a classical optimizer walks θ downhill. The variational principle guarantees
# energy(θ) >= E0 for every θ, so the minimum is an upper bound on the truth.
theta = 0.0 # start at the Hartree-Fock state
for _ in range(40):
g = (energy(theta+1e-5, *H) - energy(theta-1e-5, *H)) / 2e-5
theta -= 0.5 * g # gradient step
E_vqe = energy(theta, *H) # == lowest eigenvalue of the 2x2 H # Validated against the textbook H2/STO-3G numbers
R = 1.4 bohr: E_HF = -1.11671 E_VQE = -1.13728 (exact FCI -1.1373)
correlation recovered by VQE that Hartree-Fock misses: 0.0206 hartree
# dissociation (R = 4.5 bohr): HF = -0.7185 (wrong) VQE = -0.9375 (correct shape)
# the qubit Hamiltonian (parity-mapped) is H = c0 I + c1 Z0 + c2 Z1 + c3 Z0Z1 + c4 X0X1 Where this fits
VQE is the fourth way this site solves the same H₂: Hartree–Fock gives the mean-field answer, FCI diagonalizes exactly, DMRG compresses the wavefunction, and VQE hands the state to a quantum circuit and varies it — all four lower-bounded by the one variational principle, all four built from the same molecular integrals. The natural continuations: the UCC ansatz and why it is hard to run, measuring the Pauli terms with finite shots (where the noise lives), and the barren-plateau problem that makes deeper circuits hard to optimize.