ZKSF logo, a neon quantum brainZKSF
← All articles

VQE and the Hydrogen Molecule: Quantum Chemistry From Scratch

· 9 min read · ZKSF team

The first place a quantum computer is likely to earn its cost is chemistry, because molecules are quantum objects and simulating them on classical hardware gets exponentially harder with size. The Variational Quantum Eigensolver, VQE, is the near-term method of choice, and the hydrogen molecule is where everyone starts. In this walkthrough we run VQE live and land on the known ground-state energy of H2, and it is a one-click template in the ZKSF console.

The goal: a molecule's ground-state energy

Almost everything you want to know about a molecule, whether a reaction will happen, what shape it takes, how strongly it binds, follows from its ground-state energy, the lowest energy its electrons can occupy. Compute that energy across a range of geometries and you have mapped the molecule's behaviour. The trouble is that the energy is the lowest eigenvalue of a Hamiltonian whose size grows exponentially with the number of electrons, which is why classical methods run out of room.

For hydrogen in a minimal basis, that Hamiltonian reduces to just two qubits. It is written as a weighted sum of Pauli terms, the identity plus Z, ZZ, XX, and YY interactions, each with a coefficient fixed by the molecule's physics at its equilibrium bond length.

How VQE works: guess, measure, adjust

VQE is a partnership between a quantum computer and a classical optimizer. The quantum computer prepares a trial state from an ansatz, a circuit with tunable angles, and measures the energy of that state. The classical optimizer looks at the energy and adjusts the angles to make it lower. Repeat, and the energy slides downhill towards the true ground state. The variational principle guarantees the trick works: no trial state can ever have an energy below the real ground-state energy, so the lowest number you can reach is the answer.

Our ansatz is the standard single-excitation circuit for H2. One angle controls how much of the excited configuration mixes into the reference state.

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 diagram shows the ansatz. The single blue Rz rotation carries the variational angle. The basis-change gates around it, and the CNOT pair, arrange for that angle to rotate the state between the two electronic configurations that matter for hydrogen. Notice there is no measurement gate: instead of sampling bitstrings, we ask the platform for the expectation value of the Hamiltonian directly.

Running it live: the classical loop, on real infrastructure

We ran the ansatz on ZKSF's Pauli engine, which returns the exact expectation value of the Hamiltonian we pass as the observable. Then we swept the angle, the optimizer's job, and watched the energy fall:

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 at an angle of about 0.26 radians. That is the known ground-state energy of the hydrogen molecule at its equilibrium bond length, the number every quantum chemistry method is checked against. Because the engine propagates the observable exactly, the minimum-energy run carries a rigorous ZCC-v0.1 certificate with an error bound of zero: no Pauli terms were discarded, so the expectation value is exact up to floating point.

One honest detail: the coefficient on the identity term folds in the constant nuclear-repulsion energy of the two protons, so the number the platform returns is the full molecular energy you can compare against a textbook, not just the electronic part.

Why this matters

H2 is small enough to solve on paper, which is exactly why it is the right first test: if a method cannot reproduce -1.137 hartree, it is not to be trusted on anything larger. The same VQE recipe, a Hamiltonian written in Pauli terms, an ansatz, and a classical loop, scales to molecules that classical chemistry cannot reach, which is where a fault-tolerant quantum computer is expected to pay off first. The optimization loop itself is the same one behind QAOA.

Try it yourself

Choose VQE, H2 molecule in the console. The template loads the ansatz and the hydrogen Hamiltonian as the observable in one click. Run it, then change the angle by hand and watch the energy: you are doing, by eye, what a classical optimizer automates. This is quantum chemistry you can run in a minute, for a fraction of a cent.

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