Skip to content
AI360Xpert
Beta

Variational Quantum Eigensolvers

VQE uses a quantum computer to prepare trial molecular wavefunctions and a classical computer to tune circuit angles until the measured energy reaches its lowest possible point.

The hybrid VQE loop: parameterized ansatz state preparation, Pauli Hamiltonian measurement, and classical energy minimization.
The hybrid VQE loop: parameterized ansatz state preparation, Pauli Hamiltonian measurement, and classical energy minimization.

Why Does This Exist?

In quantum chemistry and material science, determining the chemical reactivity, binding affinity, and thermal stability of molecules requires finding the ground state energy (the lowest eigenvalue) of the molecular electronic Hamiltonian H^\hat{H}. On classical supercomputers, the dimension of the electronic Hilbert space scales exponentially as (2MNe)\binom{2M}{N_e} with the number of spin orbitals MM and electrons NeN_e. For molecules larger than 50 electrons—such as the active iron-molybdenum cofactor in nitrogenase that fixes atmospheric nitrogen—exact classical diagonalization is computationally impossible.

The theoretical ideal quantum algorithm, Quantum Phase Estimation (QPE), provably extracts exact eigenvalues with polynomial quantum speedup. However, QPE requires deep quantum circuits with millions of fault-tolerant logic gates, far beyond modern Noisy Intermediate-Scale Quantum (NISQ) hardware.

Introduced by Alberto Peruzzo, Jarrod McClean, Peter O'Brien, and Alán Aspuru-Guzik in 2014, the Variational Quantum Eigensolver (VQE) circumvents hardware limitations by splitting the workload. Instead of executing long coherent circuits, VQE runs shallow, parameterized quantum circuits on a QPU to prepare trial molecular states, measures expectation values, and offloads the energy minimization loop to a classical optimizer.

Think of It Like This

A sound technician dialing out microphone feedback hum

Imagine a concert sound technician trying to eliminate a ringing acoustic feedback frequency created between an auditorium's stage microphone and loudspeakers.

Finding the exact resonance mode analytically by solving acoustic 3D wave differential equations across every wall, chair, and curtain reflection is mathematically intractable.

Instead, the technician twiddles the parametric equalizer frequency dials on the mixing console (variational parameters θ\boldsymbol{\theta}). With each slight knob adjustment, they listen to the overall sound pressure meter on the board (energy measurement E(θ)E(\boldsymbol{\theta})). Guided by the readout, they nudge the knobs in the direction that lowers the volume until the screeching feedback vanishes completely into a quiet hum (the lowest ground state energy E0E_0).

How It Actually Works

Rayleigh-Ritz Variational Principle and Pauli Decomposition

VQE is grounded in the Rayleigh-Ritz variational principle from quantum mechanics. For any valid quantum state ∣ψ(θ)⟩|\psi(\boldsymbol{\theta})\rangle and Hermitian Hamiltonian operator H^\hat{H}, the expectation value of energy is guaranteed to be greater than or equal to the true minimum ground state energy E0E_0:

E(θ)=⟨ψ(θ)∣H^∣ψ(θ)⟩⟨ψ(θ)∣ψ(θ)⟩≥E0E(\boldsymbol{\theta}) = \frac{\langle \psi(\boldsymbol{\theta}) | \hat{H} | \psi(\boldsymbol{\theta}) \rangle}{\langle \psi(\boldsymbol{\theta}) | \psi(\boldsymbol{\theta}) \rangle} \ge E_0

Equality holds if and only if ∣ψ(θ)⟩|\psi(\boldsymbol{\theta})\rangle is the exact ground state eigenstate. This converts an intractable matrix diagonalization problem into a continuous optimization problem: minimize E(θ)E(\boldsymbol{\theta}) by adjusting gate parameters θ\boldsymbol{\theta}.

1. Second Quantization and Jordan-Wigner Transformation

A molecular Hamiltonian in second quantization is expressed using fermionic creation (ap†a_p^\dagger) and annihilation (aqa_q) operators:

H^=∑pqhpqap†aq+12∑pqrshpqrsap†aq†asar\hat{H} = \sum_{pq} h_{pq} a_p^\dagger a_q + \frac{1}{2} \sum_{pqrs} h_{pqrs} a_p^\dagger a_q^\dagger a_s a_r

Using the Jordan-Wigner transformation (or Bravyi-Kitaev transformation), fermionic operators are mapped onto tensor products of Pauli spin operators ({I,X^,Y^,Z^}\{I, \hat{X}, \hat{Y}, \hat{Z}\}), decomposing H^\hat{H} into a linear sum of KK Pauli strings:

H^=∑k=1KckP^kwhere P^k∈{I,X^,Y^,Z^}⊗n,ck∈R\hat{H} = \sum_{k=1}^K c_k \hat{P}_k \quad \text{where } \hat{P}_k \in \{I, \hat{X}, \hat{Y}, \hat{Z}\}^{\otimes n}, \quad c_k \in \mathbb{R}

2. Measuring Energy on the QPU

By linearity of expectation values, the total system energy is the weighted sum of individual Pauli expectations:

E(θ)=∑k=1Kck⟨ψ(θ)∣P^k∣ψ(θ)⟩E(\boldsymbol{\theta}) = \sum_{k=1}^K c_k \langle \psi(\boldsymbol{\theta}) | \hat{P}_k | \psi(\boldsymbol{\theta}) \rangle

To measure a Pauli string like X^1Z^2\hat{X}_1 \hat{Z}_2:

  1. The QPU prepares trial state ∣ψ(θ)⟩=U(θ)∣ψref⟩|\psi(\boldsymbol{\theta})\rangle = U(\boldsymbol{\theta})|\psi_{\text{ref}}\rangle.
  2. Basis rotation gates are applied (e.g., a Hadamard gate rotates the X^\hat{X} basis into the computational Z^\hat{Z} basis).
  3. The qubits are measured in the computational basis for NshotsN_{\text{shots}} trials.
  4. The classical processor aggregates the sample averages, sums E(θ)E(\boldsymbol{\theta}), and executes an optimization step θ←θ−η∇E(θ)\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} - \eta \nabla E(\boldsymbol{\theta}).

Worked Example

Consider a 1-qubit Hamiltonian representing a magnetic spin system:

H^=0.5Z^+1.2X^\hat{H} = 0.5 \hat{Z} + 1.2 \hat{X}

Step 1: Compute Exact Analytical Ground Energy The Hamiltonian matrix is:

H^=[0.51.21.2−0.5]\hat{H} = \begin{bmatrix} 0.5 & 1.2 \\ 1.2 & -0.5 \end{bmatrix}

Its eigenvalues satisfy det⁡(H^−λI)=(0.5−λ)(−0.5−λ)−(1.2)2=λ2−0.25−1.44=λ2−1.69=0\det(\hat{H} - \lambda I) = (0.5 - \lambda)(-0.5 - \lambda) - (1.2)^2 = \lambda^2 - 0.25 - 1.44 = \lambda^2 - 1.69 = 0.

λ=±1.69=±1.30\lambda = \pm \sqrt{1.69} = \pm 1.30

The exact ground state energy is E0=−1.30 HartreeE_0 = -1.30\text{ Hartree}.

Step 2: Define Trial Wavefunction (Ansatz) Use a single-parameter rotation ansatz initialized from ground state ∣0⟩|0\rangle:

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

Step 3: Evaluate Pauli Expectation Values

  • For Z^\hat{Z}:
⟨Z^⟩=cos⁡2θ2(+1)+sin⁡2θ2(−1)=cos⁡θ\langle \hat{Z} \rangle = \cos^2\frac{\theta}{2} (+1) + \sin^2\frac{\theta}{2} (-1) = \cos\theta
  • For X^\hat{X}:
⟨X^⟩=2cos⁡θ2sin⁡θ2=sin⁡θ\langle \hat{X} \rangle = 2 \cos\frac{\theta}{2} \sin\frac{\theta}{2} = \sin\theta

Step 4: Formulate Energy Objective

E(θ)=0.5⟨Z^⟩+1.2⟨X^⟩=0.5cos⁡θ+1.2sin⁡θE(\theta) = 0.5 \langle \hat{Z} \rangle + 1.2 \langle \hat{X} \rangle = 0.5 \cos\theta + 1.2 \sin\theta

Step 5: Minimize Energy Analytically Find the critical angle by setting the derivative to zero:

dEdθ=−0.5sin⁡θ+1.2cos⁡θ=0  ⟹  tan⁡θ=1.20.5=2.40\frac{dE}{d\theta} = -0.5 \sin\theta + 1.2 \cos\theta = 0 \implies \tan\theta = \frac{1.2}{0.5} = 2.40

The minimum occurs in the third quadrant where both sine and cosine are negative:

θ∗=arctan⁡(2.40)+π≈1.1760+3.1416=4.3176 radians\theta^* = \arctan(2.40) + \pi \approx 1.1760 + 3.1416 = 4.3176\text{ radians}

Compute trigonometric values at θ∗\theta^*:

cos⁡(4.3176)=−0.3846,sin⁡(4.3176)=−0.9231\cos(4.3176) = -0.3846, \quad \sin(4.3176) = -0.9231

Substitute back into the energy equation:

E(θ∗)=0.5(−0.3846)+1.2(−0.9231)=−0.1923−1.1077=−1.3000 HartreeE(\theta^*) = 0.5(-0.3846) + 1.2(-0.9231) = -0.1923 - 1.1077 = -1.3000\text{ Hartree}

The variational expectation value matches the theoretical lowest eigenvalue E0=−1.30E_0 = -1.30 to 4 decimal places.

Code

Below is a pure Python script simulating the VQE hybrid optimization loop on this Hamiltonian:

import numpy as np

def ry(theta: float) -> np.ndarray:    half = theta / 2.0    return np.array([        [np.cos(half), -np.sin(half)],        [np.sin(half),  np.cos(half)]    ], dtype=np.complex128)

# Pauli Matricespauli_z = np.array([[1.0, 0.0], [0.0, -1.0]], dtype=np.complex128)pauli_x = np.array([[0.0, 1.0], [1.0, 0.0]], dtype=np.complex128)
# Hamiltonian Coefficients: H = 0.5*Z + 1.2*Xc_z, c_x = 0.5, 1.2

def measure_expectation(state: np.ndarray, observable: np.ndarray) -> float:    """Computes <psi|Observable|psi>."""    return float(np.real(np.conj(state).T @ observable @ state))

def vqe_energy(theta: float) -> float:    """Prepares trial state on QPU and evaluates energy."""    state = ry(theta) @ np.array([1.0, 0.0], dtype=np.complex128)    exp_z = measure_expectation(state, pauli_z)    exp_x = measure_expectation(state, pauli_x)    return c_z * exp_z + c_x * exp_x

# Classical Gradient Descent Looptheta = 0.0  # Initial parameterlearning_rate = 0.1shift = np.pi / 2.0
for step in range(50):    # Parameter-shift gradient: dE/dtheta = 0.5 * (E(theta + pi/2) - E(theta - pi/2))    grad = 0.5 * (vqe_energy(theta + shift) - vqe_energy(theta - shift))    theta -= learning_rate * grad
final_energy = vqe_energy(theta)exact_ground = -np.sqrt(c_z**2 + c_x**2)
print(f"Optimal angle theta: {theta:.4f} rad")# -> Optimal angle theta: -1.9656 rad (equivalent to 4.3176 rad mod 2pi)print(f"VQE Ground Energy: {final_energy:.4f}")# -> VQE Ground Energy: -1.3000print(f"Exact Ground Energy: {exact_ground:.4f}")# -> Exact Ground Energy: -1.3000

Watch Out For

Pauli term grouping overhead and shot budget explosion

When scaling VQE to multi-atom molecules (such as caffeine or lithium hydride), mapping the fermionic Hamiltonian via Jordan-Wigner yields O(N4)\mathcal{O}(N^4) individual Pauli strings. For a modest 20-qubit system, this produces over 10,000 distinct Pauli terms.

If every term is measured with Nshots=10,000N_{\text{shots}} = 10{,}000 to achieve chemical accuracy (1 kcal/mol≈1.6×10−3 Hartree1\text{ kcal/mol} \approx 1.6\times 10^{-3}\text{ Hartree}), each single energy evaluation requires over 10810^8 circuit executions, causing runtimes on real cloud QPUs to stretch into weeks for a single convergence run.

Fix: Group commuting Pauli operators into simultaneous measurement cliques using Qubit-Wise Commutativity (QWC) or Full Commutativity (FC) algorithms. Operators in the same commutative clique can be measured simultaneously in a single basis rotation circuit, collapsing tens of thousands of separate terms into a few dozen bundled circuit runs.

The Quick Version

  • Variational Quantum Eigensolvers solve molecular ground state energies using the Rayleigh-Ritz theorem: E(θ)≥E0E(\boldsymbol{\theta}) \ge E_0.
  • Second-quantized electronic Hamiltonians are decomposed into weighted sums of Pauli spin strings using the Jordan-Wigner transformation.
  • The QPU prepares trial wavefunctions and measures Pauli expectation values; the classical CPU sums terms and runs gradient updates.
  • Commutativity grouping algorithms are essential to condense O(N4)\mathcal{O}(N^4) Pauli terms into manageable measurement shot budgets.