VQE Suite / Physics

Hamiltonian & Ansatz

The H2 Hamiltonian used by the live VQE Suite playground, and a from-scratch derivation of why its single-parameter ansatz circuit is exact — not just a convenient guess.

The H2 electronic Hamiltonian

In second quantization, a molecule's electronic Hamiltonian in a finite orbital basis is

H^=pqhpqapaq+12pqrshpqrsapaqaras\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_r a_s

where the one- and two-electron integrals hpqh_{pq} and hpqrsh_{pqrs} come from the molecular orbitals, and the Jordan-Wigner transform maps each fermionic operator to a string of Pauli operators (each apa_p^\dagger becomes a weighted Pauli string acting on qubit pp and a ZZ-string over all lower-indexed qubits, so that the fermionic anticommutation relations survive the mapping onto qubits).

For H2 in a minimal (STO-3G) basis, applying Jordan-Wigner to the 4 spin-orbitals and then a symmetry (parity) reduction — using that the ground state has fixed particle number and SzS_z — collapses the problem onto 2 qubits. This site uses the reduced 2-qubit Hamiltonian exactly as published, rather than re-deriving the parity-tapering step:

H^elec=g0I+g1Z0+g2Z1+g3Z0Z1+g4Y0Y1+g5X0X1\hat{H}_{\text{elec}} = g_0 I + g_1 Z_0 + g_2 Z_1 + g_3 Z_0 Z_1 + g_4 Y_0 Y_1 + g_5 X_0 X_1
Coefficients g0,,g5g_0,\ldots,g_5 at bond length R=0.75R = 0.75 Å, from O'Malley et al., "Scalable Quantum Simulation of Molecular Energies," Phys. Rev. X 6, 031007 (2016), cross-checked against an independent secondary source before use (see verification note below).
1export const H2_COEFFICIENTS = {
2 g0: -0.4804, g1: 0.3435, g2: -0.4347,
3 g3: 0.5716, g4: 0.091, g5: 0.091,
4};
5 
6export function h2PauliSum(): PauliSum {
7 const { g0, g1, g2, g3, g4, g5 } = H2_COEFFICIENTS;
8 return [
9 { coefficient: g0, paulis: ["I", "I"] },
10 { coefficient: g1, paulis: ["I", "Z"] },
11 { coefficient: g2, paulis: ["Z", "I"] },
12 { coefficient: g3, paulis: ["Z", "Z"] },
13 { coefficient: g4, paulis: ["Y", "Y"] },
14 { coefficient: g5, paulis: ["X", "X"] },
15 ];
16}

Nuclear repulsion is added as a classical constant, computed live rather than folded into a lookup table:

Enn=Z1Z2R=1RBohr HartreeE_{nn} = \frac{Z_1 Z_2}{R} = \frac{1}{R_{\text{Bohr}}}\ \text{Hartree}

with RBohr=R/a0R_{\text{Bohr}} = R / a_0 and a0=0.529177210903a_0 = 0.529177210903 Å (CODATA Bohr radius). At R=0.75R = 0.75 Å this gives Enn0.70557E_{nn} \approx 0.70557 Hartree — see nuclearRepulsion() in src/lib/physics/h2Hamiltonian.ts.

Why the ground state lives in a 2-dimensional subspace

Write basis states as q0q1|q_0 q_1\rangle. II, Z0Z_0, Z1Z_1, and Z0Z1Z_0 Z_1 are all diagonal in this basis, so they never mix different computational-basis states. Y0Y1Y_0 Y_1 and X0X1X_0 X_1 each flip both qubits at once, so they only connect 0011|00\rangle \leftrightarrow |11\rangle and 0110|01\rangle \leftrightarrow |10\rangle — the Hamiltonian splits into two independent 2×2 blocks and never mixes them.

Evaluating both diagonals: 00H^00=g0+g1+g2+g3=0\langle 00|\hat H|00\rangle = g_0+g_1+g_2+g_3 = 0 and 11H^11=g0g1g2+g30.1824\langle 11|\hat H|11\rangle = g_0-g_1-g_2+g_3 \approx 0.1824 — both non-negative, so that block cannot contain the ground state. The other block, in the {01,10}\{|01\rangle, |10\rangle\} basis, is

M=(g0g1+g2g3g4+g5g4+g5g0+g1g2g3)(1.83020.18200.18200.2738)M = \begin{pmatrix} g_0-g_1+g_2-g_3 & g_4+g_5 \\ g_4+g_5 & g_0+g_1-g_2-g_3 \end{pmatrix} \approx \begin{pmatrix} -1.8302 & 0.1820 \\ 0.1820 & -0.2738 \end{pmatrix}

with closed-form eigenvalues (see eigen2x2Symmetric() in src/lib/physics/linalg.ts, used directly — not a general iterative solver, since a 2×2 symmetric matrix has an exact quadratic-formula solution):

λ±=tr(M)±tr(M)24det(M)2\lambda_\pm = \frac{\operatorname{tr}(M) \pm \sqrt{\operatorname{tr}(M)^2 - 4\det(M)}}{2}

which gives a minimum electronic eigenvalue λ1.8512\lambda_- \approx -1.8512 Hartree. Adding nuclear repulsion, Etotal=λ+Enn1.1456E_{\text{total}} = \lambda_- + E_{nn} \approx -1.1456 Hartree — matching the well-known H2/STO-3G full-CI benchmark of 1.137\approx -1.137 Hartree to within the expected residual from the R = 0.75 Å vs. 0.735 Å bond-length difference between the source data and the textbook value.

The ansatz circuit

Since only the {01,10}\{|01\rangle, |10\rangle\} subspace matters, a single real parameter is enough to reach the exact ground state — no expressibility is wasted on states the Hamiltonian can never select. The ansatz is Hartree-Fock state preparation followed by a controlled rotation:

1export function h2AnsatzGates(): AnsatzGate[] {
2 return [
3 { kind: "X", qubit: 0 },
4 { kind: "CNOT", control: 1, target: 0 },
5 { kind: "RY", qubit: 1, parameterized: true },
6 { kind: "CNOT", control: 1, target: 0 },
7 ];
8}

Tracing the circuit by hand: X(q0)X(q_0) takes 00|00\rangle to q0=1,q1=0|q_0{=}1,q_1{=}0\rangle. The first CNOT(q1q0)\text{CNOT}(q_1 \to q_0) is a no-op (control qubit is 0|0\rangle). RY(θ)RY(\theta) on q1q_1 gives cosθ2q0=1,q1=0+sinθ2q0=1,q1=1\cos\frac{\theta}{2}|q_0{=}1,q_1{=}0\rangle + \sin\frac{\theta}{2}|q_0{=}1,q_1{=}1\rangle. The second CNOT now fires on the second term (control q1=1q_1=1), flipping q0q_0 there and landing exactly on the coupled subspace:

ψ(θ)=cosθ2q0=1,q1=0+sinθ2q0=0,q1=1|\psi(\theta)\rangle = \cos\tfrac{\theta}{2}\,|q_0{=}1,q_1{=}0\rangle + \sin\tfrac{\theta}{2}\,|q_0{=}0,q_1{=}1\rangle

Optimization uses the exact parameter-shift rule for this single RY(θ)RY(\theta) generator (no finite-difference approximation):

Eθ=E(θ+π/2)E(θπ/2)2\frac{\partial E}{\partial \theta} = \frac{E(\theta+\pi/2) - E(\theta-\pi/2)}{2}

Running this in the browser (runVqe() in src/lib/physics/vqe.ts) converges to θ0.2297\theta^\ast \approx -0.2297, E1.145630E \approx -1.145630 Hartree — matching the exact diagonalization above to machine precision, confirmed against exactGroundStateEnergy() at build-verification time. See it run live on the VQE Suite playground.

Source: src/lib/physics/h2Hamiltonian.ts, h2Ansatz.ts, vqe.ts, linalg.ts