|q⟩ Bad Qubits

advanced · Programming · Quantum Chemistry on Quantum Computers

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 H2\text{H}_2 Hamiltonian.

The variational principle

For any normalized trial state ψ(θ)|\psi(\boldsymbol\theta)\rangle and Hamiltonian H^\hat H with ground-state energy E0E_0,

E(θ)=ψ(θ)H^ψ(θ)    E0.E(\boldsymbol\theta) = \langle \psi(\boldsymbol\theta)|\hat H|\psi(\boldsymbol\theta)\rangle \;\geq\; E_0.

Equality holds only when ψ|\psi\rangle is the true ground state. So minimizing E(θ)E(\boldsymbol\theta) over the parameters drives the energy down toward E0E_0 from above — never below it. VQE is exactly this minimization, with the quantum computer evaluating the cost function.

The VQE loop

  1. Prepare a parametrized trial state ψ(θ)|\psi(\boldsymbol\theta)\rangle with an ansatz circuit, starting from the Hartree–Fock reference.
  2. Measure the energy E(θ)=kckPkE(\boldsymbol\theta) = \sum_k c_k \langle P_k\rangle by measuring each Pauli term of the Hamiltonian (grouping commuting terms).
  3. Optimize: a classical routine (gradient descent, COBYLA, SPSA, …) proposes new θ\boldsymbol\theta.
  4. 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 H2\text{H}_2 a single parameter suffices. Starting from the Hartree–Fock state 01|01\rangle, a particle-number-preserving (Givens) rotation produces

ψ(θ)=cosθ201sinθ210.|\psi(\theta)\rangle = \cos\tfrac{\theta}{2}\,|01\rangle - \sin\tfrac{\theta}{2}\,|10\rangle.

This rotates the trial state inside the single-excitation subspace {01,10}\{|01\rangle, |10\rangle\} — exactly the two configurations the off-diagonal X0X1X_0X_1 and Y0Y1Y_0Y_1 terms couple. The optimizer's job is to find the θ\theta^\star that minimizes the energy; the small admixture of 10|10\rangle it introduces is the correlation energy that Hartree–Fock missed.

The Givens rotation is realized with CNOTs and a controlled RYR_Y:

// |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 E0E_0, 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 H2\text{H}_2 at the angle θ=π/2\theta = \pi/2, giving the equal superposition 12(0110)\tfrac{1}{\sqrt2}(|01\rangle - |10\rangle). Use the Givens-rotation construction above. The grader checks the full statevector.

Run your code to see the quantum state.

The statevector should show amplitude +1/2+1/\sqrt2 on 01|01\rangle and 1/2-1/\sqrt2 on 10|10\rangle, with 00|00\rangle and 11|11\rangle empty — a valid particle-number-conserving VQE trial state.

Sign in on the full site to ask questions and join the discussion.