Computing Library › Worked Examples
Worked Examples

The VQE Energy Curve for H2

Sweep the bond length of the hydrogen molecule and minimize a two-parameter ansatz to trace the ground-state energy well.

Problem

The variational quantum eigensolver (VQE) estimates a molecule's ground-state energy by minimizing the expectation value of its Hamiltonian over a parameterized trial state. For H2 in a minimal basis the problem reduces to a small effective Hamiltonian whose ground state a single rotation angle can reach.

Reduced model

Kronos motion — q curve

In the minimal (STO-3G, two-orbital) picture the H2 Hamiltonian at a given bond length maps to a 2x2 effective matrix in the relevant symmetry sector. The variational energy is E(theta) = , minimized over theta; the true minimum equals the smaller eigenvalue.

python
import numpy as np
def H_of_R(R):
    # illustrative 2x2 block: diagonal + coupling that grows near equilibrium
    d=1.0/R; off=0.3*np.exp(-(R-0.74)**2)
    return np.array([[ -1.0-d, -off],[-off, -0.5-0.5*d]])
Es=[]
for R in np.linspace(0.4,2.5,15):
    H=H_of_R(R)
    thetas=np.linspace(0,np.pi,200)
    e=[ (np.cos(t/2)**2*H[0,0]+np.sin(t/2)**2*H[1,1]
         +np.sin(t)*H[0,1]) for t in thetas]
    Es.append(min(e))
print('minimum energy along curve',round(min(Es),3))

Result

Sweeping bond length and minimizing theta at each point traces a curve that falls to a minimum near the equilibrium separation, then rises as the atoms are pulled apart, the familiar molecular potential well. The variational minimum matches the exact ground state because a single rotation spans the two-dimensional sector exactly.