|q⟩ Bad Qubits

intermediate · Programming · Algorithm Projects & Benchmarking

Project: Mini-VQE

The Variational Quantum Eigensolver (VQE) is a hybrid algorithm that finds the lowest eigenvalue of a Hamiltonian HH — its ground-state energy E0E_0 — using a classical optimization loop wrapped around a parameterized quantum circuit.

The variational principle

The foundation of VQE is the quantum mechanical variational principle: for any normalized state ψ|\psi\rangle,

E0    ψHψ,E_0 \;\leq\; \langle\psi|H|\psi\rangle,

with equality only when ψ|\psi\rangle is the true ground state. This means that if we can minimize ψ(θ)Hψ(θ)\langle\psi(\boldsymbol{\theta})|H|\psi(\boldsymbol{\theta})\rangle over the parameter vector θ\boldsymbol{\theta}, the lowest value we reach is an upper bound on E0E_0 — and, with a rich enough ansatz, it equals E0E_0 exactly.

The VQE loop

  1. Choose a Hamiltonian HH and a parameterized ansatz circuit U(θ)U(\boldsymbol{\theta}).
  2. Prepare ψ(θ)=U(θ)0n|\psi(\boldsymbol{\theta})\rangle = U(\boldsymbol{\theta})|0\rangle^{\otimes n}.
  3. Measure the energy E(θ)=ψHψE(\boldsymbol{\theta}) = \langle\psi|H|\psi\rangle by decomposing HH into a sum of Pauli strings and measuring each term.
  4. Update θ\boldsymbol{\theta} using a classical optimizer (gradient descent, parameter-shift gradients, COBYLA, etc.).
  5. Repeat steps 2–4 until convergence.

Hamiltonian: ZZZ \otimes Z

For this project we work with the two-qubit Hamiltonian

H=Z0Z1.H = Z_0 \otimes Z_1.

Its eigenvalues come from the product of the ZZ eigenvalues ±1\pm 1. Explicitly:

| State | Z0\langle Z_0 \rangle | Z1\langle Z_1 \rangle | Z0Z1\langle Z_0 Z_1 \rangle | |-------|-------|-------|-------| | 00\|00\rangle | +1+1 | +1+1 | +1+1 | | 01\|01\rangle | +1+1 | 1-1 | 1-1 | | 10\|10\rangle | 1-1 | +1+1 | 1-1 | | 11\|11\rangle | 1-1 | 1-1 | +1+1 |

The ground-state energy is E0=1E_0 = -1, achieved by 01|01\rangle or 10|10\rangle.

Ansatz and optimal angles

We use the hardware-efficient ansatz with independent RyR_y rotations on each qubit:

ψ(θ0,θ1)=Ry(θ0)0Ry(θ1)0|\psi(\theta_0, \theta_1)\rangle = R_y(\theta_0)|0\rangle \otimes R_y(\theta_1)|0\rangle

where Ry(θ)=eiθY/2R_y(\theta) = e^{-i\theta Y/2}. Since the two qubits are unentangled, the expectation value factorizes:

Z0Z1=Z0Z1=cosθ0cosθ1.\langle Z_0 Z_1 \rangle = \langle Z_0 \rangle \cdot \langle Z_1 \rangle = \cos\theta_0 \cdot \cos\theta_1.

To minimize cosθ0cosθ1\cos\theta_0 \cos\theta_1 we want one factor to be +1+1 and the other 1-1. The choice θ0=0,  θ1=π\theta_0 = 0,\; \theta_1 = \pi gives

cos(0)cos(π)=1(1)=1=E0.\cos(0) \cdot \cos(\pi) = 1 \cdot (-1) = -1 = E_0.

Try it

The starter code provides the optimal angles from a completed VQE run (θ0=0\theta_0 = 0, θ1=π\theta_1 = \pi). Apply the ansatz Ry(θ0)R_y(\theta_0) on qubit 0 and Ry(θ1)R_y(\theta_1) on qubit 1. The grader checks the resulting statevector, which should be exactly 01|01\rangle — the ground state of ZZZ \otimes Z.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.