ZKSF logo, a neon quantum brainZKSF
← All articles

VQE and the Hydrogen Molecule: Quantum Chemistry From Scratch

Last updated · 12 min read · ZKSF team

Open in Colab

Run this one yourself. The notebook builds the circuit and reads the certificate for the run below, with no account and nothing to install.

The short version

  • The variational principle is what makes the method sound. Any trial state's energy is an upper bound on the true ground state, so the minimum found can never sit below it
  • The energy bottomed out at -1.137 hartree. That is the known ground-state energy of H2 at equilibrium bond length
  • Chemical accuracy is 1.6 millihartree. Most VQE results in the literature do not reach it beyond very small systems
  • H2 is the right first test because it is exactly solvable. A benchmark whose answer is unknown cannot detect a broken implementation

Quantum chemistry is the application most often cited as the first place a quantum computer will earn its cost, because molecules are quantum objects and the classical cost of describing them grows exponentially with electron count. The Variational Quantum Eigensolver is the leading near-term method, and the hydrogen molecule is the standard first test. This walkthrough states the method, runs the circuit, and reports a certified energy of -1.137 hartree.

The quantity being computed

Most chemical questions reduce to ground-state energy: whether a reaction proceeds, what geometry a molecule adopts, how strongly a ligand binds. Computing that energy across geometries maps the potential energy surface, from which reaction rates and structures follow.

The energy is the lowest eigenvalue of the electronic Hamiltonian. Written in second quantisation it is a sum of one- and two-electron terms over molecular orbitals, and the dimension of the space it acts on grows combinatorially with orbital and electron count. Exact diagonalisation, called full configuration interaction, is the reference method and becomes intractable beyond roughly 20 orbitals.

Mapping this to qubits uses a fermion-to-qubit transformation, most commonly Jordan-Wigner, which assigns one qubit per spin orbital and represents the fermionic anticommutation relations with strings of Z operators. The result is a Hamiltonian expressed as a weighted sum of Pauli strings, which is the form a quantum computer can measure term by term.

For hydrogen in a minimal STO-3G basis, symmetry reductions bring the problem to two qubits, with the Hamiltonian carrying identity, Z, ZZ, XX and YY terms whose coefficients are fixed by the molecular geometry.

The variational principle, which is what makes the method sound

VQE rests on a theorem rather than a heuristic. For any normalised trial state |psi>, the expectation value of the Hamiltonian is greater than or equal to the true ground-state energy, with equality only when |psi> is the ground state.

The consequence is that the method cannot silently return an answer that is too low. Every energy VQE reports is a rigorous upper bound on the truth, so minimising over trial states can only approach the correct value from above. This is a stronger guarantee than most numerical methods offer, and it is why the method survives noise: noise raises the measured energy, degrading the bound rather than invalidating it.

The procedure follows directly. A quantum processor prepares a trial state from an ansatz, a circuit with tunable angles, and measures the expectation of each Pauli term. A classical optimizer adjusts the angles to lower the total. The loop repeats until convergence.

The ansatz

The ansatz determines what states are reachable, and therefore how close the minimum can get. Ours is the standard single-excitation circuit for H2: one angle controls how much of the doubly-excited configuration mixes into the Hartree-Fock reference state. This is the two-qubit case of unitary coupled cluster with single and double excitations, which is chemically motivated rather than hardware-motivated.

OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];
x q[0];
rx(1.5708) q[0];
h q[1];
cx q[1],q[0];
rz(0.2618) q[0];        // the one variational angle
cx q[1],q[0];
rx(-1.5708) q[0];
h q[1];
VQE ansatz circuit diagram for the hydrogen molecule on two qubits: an X and basis-change gates around a single Rz rotation entangled with a CNOT pair
VQE ansatz circuit diagram for the hydrogen molecule on two qubits: an X and basis-change gates around a single Rz rotation entangled with a CNOT pair

The single blue Rz carries the variational angle. The basis-change gates around it and the CNOT pair arrange for that angle to rotate between the two electronic configurations that matter. There is no measurement gate: rather than sampling bitstrings, the platform is asked for the expectation value of the Hamiltonian directly.

The run

The ansatz was submitted to the Pauli engine, which returns the exact expectation value of the Hamiltonian passed as the observable. Sweeping the angle, which is the optimizer's task performed manually so the landscape is visible:

angle -1.57  ->  E = -0.156 Ha
angle -0.52  ->  E = -0.921 Ha
angle  0.00  ->  E = -1.117 Ha
angle  0.13  ->  E = -1.134 Ha
angle  0.26  ->  E = -1.137 Ha   <- minimum
angle  0.52  ->  E = -1.103 Ha
angle  1.57  ->  E = -0.520 Ha

The energy bottoms out at -1.137 hartree near 0.26 radians, which is the known ground-state energy of H2 at equilibrium bond length and the number every quantum chemistry method is checked against. Note that no point in the sweep falls below it, as the variational principle requires; a value below the true ground state would indicate the expectation was being computed incorrectly, and no error bound would repair that.

Because the engine propagates the observable exactly and no Pauli terms were discarded, the minimum-energy run carries a ZCC-v0.1 certificate with an error bound of zero, exact up to floating point.

One detail that is frequently mishandled: the coefficient on the identity term folds in the constant nuclear-repulsion energy of the two protons. The number reported is therefore the full molecular energy comparable against a textbook value, not the electronic contribution alone. Omitting that constant is a common source of energies that are wrong by several hartree.

Chemical accuracy, and why the bar is where it is

Chemistry has a specific accuracy target: 1.6 millihartree, or 1 kcal/mol, known as chemical accuracy. It is set by the precision needed to predict reaction rates usefully, since rates depend exponentially on energy differences and an error of a few millihartree changes a predicted rate by an order of magnitude.

This is a demanding target and it should be stated plainly that most VQE results in the literature do not reach it beyond very small systems. The obstacles are ansatz expressivity, optimiser performance in high-dimensional landscapes, shot noise in expectation estimation, and on hardware, gate error. H2 at two qubits is solvable; the difficulty grows sharply with system size, and claims about larger molecules should be read with the reported error against a reference method in hand.

Why H2 remains the right first test

The same recipe, a Hamiltonian in Pauli form, an ansatz, and a classical loop, extends to molecules beyond classical reach, which is where the eventual payoff is expected. The optimisation loop is the same one behind QAOA, and the cost of running that loop at scale is set out in What does it cost to rent a quantum computer?.

Running it

Select VQE, H2 molecule in the console. The template loads the ansatz and the hydrogen Hamiltonian as the observable. Run it, then vary the angle by hand and watch the energy. This is what a classical optimizer automates, and seeing the landscape once makes the optimizer's difficulty on larger problems considerably easier to understand.

Run your own 100-qubit circuit, with an error bar.

Share this articleLink copied