The Variational Quantum Eigensolver (VQE) finds the lowest eigenvalue of a Hamiltonian H
by minimizing the energy expectation value E(θ)=⟨ψ(θ)∣H∣ψ(θ)⟩
over the parameters θ of a trial circuit (the ansatz). In this lesson you apply the full idea
to a two-qubit toy model of the hydrogen molecule.
The toy H₂ Hamiltonian
A real H₂ calculation maps molecular orbital integrals onto qubits via the
Jordan-Wigner transformation. Even at the minimal STO-3G basis level the
full mapped Hamiltonian has five Pauli terms. For this introductory lesson we
strip everything down to the dominant spin-spin coupling term:
H=−Z0⊗Z1.
This operator is diagonal in the computational basis:
The two lowest-energy states are ∣00⟩ and ∣11⟩, both with
E0=−1.
Verifying the energy of ∣Φ+⟩
The expectation value of H=−Z0Z1 in the Bell state
∣Φ+⟩=21(∣00⟩+∣11⟩) is
⟨Φ+∣H∣Φ+⟩=−⟨Φ+∣Z0Z1∣Φ+⟩.
Because Z0Z1∣00⟩=+∣00⟩ and Z0Z1∣11⟩=+∣11⟩, we have
Z0Z1∣Φ+⟩=∣Φ+⟩, so
⟨Φ+∣Z0Z1∣Φ+⟩=1⟹⟨Φ+∣H∣Φ+⟩=−1=E0.
The variational principle guarantees ⟨H⟩≥E0=−1, and
∣Φ+⟩ achieves this bound exactly.
The ansatz circuit
The general two-parameter ansatz for states in the {∣00⟩,∣11⟩} subspace is
∣ψ(θ,ϕ)⟩=cos2θ∣00⟩+eiϕsin2θ∣11⟩.
Setting θ=π/2 and ϕ=0 gives ∣Φ+⟩. The circuit that prepares
this state from ∣00⟩ requires exactly two gates:
Hadamard on qubit 0: puts qubit 0 into 21(∣0⟩+∣1⟩), leaving
the full register in 21(∣00⟩+∣10⟩).
CNOT with qubit 0 as control and qubit 1 as target: flips qubit 1 only when qubit 0
is ∣1⟩, entangling the pair to give 21(∣00⟩+∣11⟩).
In a real VQE run, θ would be a free parameter tuned by the optimizer. Here the optimizer
has already converged: the optimal angle is θ=π/2, which is exactly H∣0⟩
composed with a CNOT.
The hybrid VQE loop (conceptual)
A production VQE run on H₂ would iterate:
Quantum step: prepare ∣ψ(θ)⟩ with the ansatz; measure ⟨H⟩
by estimating each Pauli term's expectation value from shot statistics.
Classical step: feed E(θ) to a gradient-free optimizer (e.g., COBYLA or SPSA),
which proposes a new θ.
Convergence: stop when E(θ) stops decreasing. The final value is the VQE
estimate of the ground-state energy.
In this toy model, if one uses only a plain RY(θ) on qubit 0 without the CNOT
(a product-state ansatz), the landscape is E(θ)=−cosθ, which has a
single minimum at θ=0 (E=−1, state ∣00⟩), so the
optimizer finds it in a few steps.
Try it
Prepare the Bell state ∣Φ+⟩=21(∣00⟩+∣11⟩), which
is the ground state of the toy H=−Z0Z1 Hamiltonian. The grader checks the full
statevector, so the two amplitudes must each equal 21≈0.707.
Run your code to see the quantum state.
After running, inspect the amplitudes: only ∣00⟩ and ∣11⟩ are nonzero, each
with coefficient 21. The circuit has discovered the ground state using
just a Hadamard and a CNOT — the simplest possible VQE ansatz for this Hamiltonian.
Sign in on the full site to ask questions and join the discussion.