VQE for Molecules
The Variational Quantum Eigensolver (VQE) is the workhorse algorithm for near-term quantum chemistry. It estimates a molecule's ground-state energy by combining a quantum computer (which prepares trial states and measures energies) with a classical optimizer (which proposes better parameters). Here we apply it to the two-qubit Hamiltonian.
The variational principle
For any normalized trial state and Hamiltonian with ground-state energy ,
Equality holds only when is the true ground state. So minimizing over the parameters drives the energy down toward from above — never below it. VQE is exactly this minimization, with the quantum computer evaluating the cost function.
The VQE loop
- Prepare a parametrized trial state with an ansatz circuit, starting from the Hartree–Fock reference.
- Measure the energy by measuring each Pauli term of the Hamiltonian (grouping commuting terms).
- Optimize: a classical routine (gradient descent, COBYLA, SPSA, …) proposes new .
- Repeat until the energy converges.
The quantum computer only ever prepares states and reports expectation values; all the optimization intelligence is classical. This hybrid division is what makes VQE feasible on shallow, noisy hardware.
A one-parameter ansatz for H₂
For two-qubit a single parameter suffices. Starting from the Hartree–Fock state , a particle-number-preserving (Givens) rotation produces
This rotates the trial state inside the single-excitation subspace — exactly the two configurations the off-diagonal and terms couple. The optimizer's job is to find the that minimizes the energy; the small admixture of it introduces is the correlation energy that Hartree–Fock missed.
The Givens rotation is realized with CNOTs and a controlled :
// |psi(theta)> = cos(theta/2)|01> - sin(theta/2)|10>, starting from HF |01>.
const c = circuit(2);
c.x(1); // Hartree-Fock |01>
c.cx(1, 0);
c.ry(theta / 2, 1); // controlled-RY(theta) built from RY + CNOTs
c.cx(0, 1);
c.ry(-theta / 2, 1);
c.cx(0, 1);
c.cx(1, 0);
return c;
Why VQE rather than phase estimation
Quantum phase estimation can also find , and to higher precision, but it needs deep, coherent circuits well beyond today's hardware. VQE trades that depth for many shallow circuit repetitions plus classical optimization, fitting it to the noisy intermediate-scale (NISQ) era. Its weaknesses — measurement overhead from many Pauli terms, optimizer barren plateaus, and the variational bound only guaranteeing an upper estimate — are active research areas.
Try it
Prepare the VQE trial state for at the angle , giving the equal superposition . Use the Givens-rotation construction above. The grader checks the full statevector.
The statevector should show amplitude on and on , with and empty — a valid particle-number-conserving VQE trial state.
Sign in on the full site to ask questions and join the discussion.