|q⟩ Bad Qubits

intermediate · Programming · Variational Quantum Eigensolver (VQE)

VQE for H₂ (Toy Model)

The Variational Quantum Eigensolver (VQE) finds the lowest eigenvalue of a Hamiltonian HH by minimizing the energy expectation value E(θ)=ψ(θ)Hψ(θ)E(\theta) = \langle \psi(\theta) | H | \psi(\theta) \rangle over the parameters θ\theta 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=Z0Z1.H = -Z_0 \otimes Z_1.

This operator is diagonal in the computational basis:

| State | Z0Z1Z_0 Z_1 eigenvalue | HH eigenvalue | |-------|---------------------|----------------| | 00|00\rangle | +1+1 | 1-1 | | 01|01\rangle | 1-1 | +1+1 | | 10|10\rangle | 1-1 | +1+1 | | 11|11\rangle | +1+1 | 1-1 |

The two lowest-energy states are 00|00\rangle and 11|11\rangle, both with E0=1E_0 = -1.

Verifying the energy of Φ+|\Phi^+\rangle

The expectation value of H=Z0Z1H = -Z_0 Z_1 in the Bell state Φ+=12(00+11)|\Phi^+\rangle = \tfrac{1}{\sqrt{2}}(|00\rangle + |11\rangle) is

Φ+HΦ+=Φ+Z0Z1Φ+.\langle \Phi^+ | H | \Phi^+ \rangle = -\langle \Phi^+ | Z_0 Z_1 | \Phi^+ \rangle.

Because Z0Z100=+00Z_0 Z_1 |00\rangle = +|00\rangle and Z0Z111=+11Z_0 Z_1 |11\rangle = +|11\rangle, we have Z0Z1Φ+=Φ+Z_0 Z_1 |\Phi^+\rangle = |\Phi^+\rangle, so

Φ+Z0Z1Φ+=1Φ+HΦ+=1=E0.\langle \Phi^+ | Z_0 Z_1 | \Phi^+ \rangle = 1 \quad\Longrightarrow\quad \langle \Phi^+ | H | \Phi^+ \rangle = -1 = E_0.

The variational principle guarantees HE0=1\langle H \rangle \geq E_0 = -1, and Φ+|\Phi^+\rangle achieves this bound exactly.

The ansatz circuit

The general two-parameter ansatz for states in the {00,11}\{|00\rangle, |11\rangle\} subspace is

ψ(θ,ϕ)=cos ⁣θ200+eiϕsin ⁣θ211.|\psi(\theta, \phi)\rangle = \cos\!\tfrac{\theta}{2}|00\rangle + e^{i\phi}\sin\!\tfrac{\theta}{2}|11\rangle.

Setting θ=π/2\theta = \pi/2 and ϕ=0\phi = 0 gives Φ+|\Phi^+\rangle. The circuit that prepares this state from 00|00\rangle requires exactly two gates:

  1. Hadamard on qubit 0: puts qubit 0 into 12(0+1)\tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle), leaving the full register in 12(00+10)\tfrac{1}{\sqrt{2}}(|00\rangle + |10\rangle).
  2. CNOT with qubit 0 as control and qubit 1 as target: flips qubit 1 only when qubit 0 is 1|1\rangle, entangling the pair to give 12(00+11)\tfrac{1}{\sqrt{2}}(|00\rangle + |11\rangle).

In a real VQE run, θ\theta would be a free parameter tuned by the optimizer. Here the optimizer has already converged: the optimal angle is θ=π/2\theta = \pi/2, which is exactly H0H|0\rangle composed with a CNOT.

The hybrid VQE loop (conceptual)

A production VQE run on H₂ would iterate:

  1. Quantum step: prepare ψ(θ)|\psi(\theta)\rangle with the ansatz; measure H\langle H \rangle by estimating each Pauli term's expectation value from shot statistics.
  2. Classical step: feed E(θ)E(\theta) to a gradient-free optimizer (e.g., COBYLA or SPSA), which proposes a new θ\theta.
  3. Convergence: stop when E(θ)E(\theta) 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(θ)R_Y(\theta) on qubit 0 without the CNOT (a product-state ansatz), the landscape is E(θ)=cosθE(\theta) = -\cos\theta, which has a single minimum at θ=0\theta = 0 (E=1E = -1, state 00|00\rangle), so the optimizer finds it in a few steps.

Try it

Prepare the Bell state Φ+=12(00+11)|\Phi^+\rangle = \tfrac{1}{\sqrt{2}}(|00\rangle + |11\rangle), which is the ground state of the toy H=Z0Z1H = -Z_0 Z_1 Hamiltonian. The grader checks the full statevector, so the two amplitudes must each equal 120.707\tfrac{1}{\sqrt{2}} \approx 0.707.

Run your code to see the quantum state.

After running, inspect the amplitudes: only 00|00\rangle and 11|11\rangle are nonzero, each with coefficient 12\tfrac{1}{\sqrt{2}}. 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.