|q⟩ Bad Qubits

intermediate · Programming · Variational Quantum Eigensolver (VQE)

Checkpoint: Run a VQE

You have worked through every building block of the Variational Quantum Eigensolver: the variational principle, parameterized ansatz circuits, Pauli-string measurements, classical optimization, convergence, and initialization. This checkpoint asks you to put them together and prepare the ground state of a two-qubit Hamiltonian.

The Hamiltonian

The system is described by

H=X0X1,H = -X_0 \otimes X_1,

where XX is the Pauli-XX operator. To find the ground state we need the lowest eigenvalue of this 4×44 \times 4 matrix.

The operator X0X1X_0 \otimes X_1 swaps pairs of basis states: it maps 0011|00\rangle \leftrightarrow |11\rangle and 0110|01\rangle \leftrightarrow |10\rangle. All four Bell states are eigenstates of X0X1X_0 \otimes X_1:

Φ+=12(00+11),eigenvalue +1,|{\Phi^+}\rangle = \tfrac{1}{\sqrt{2}}\bigl(|00\rangle + |11\rangle\bigr), \quad \text{eigenvalue } +1, Φ=12(0011),eigenvalue 1,|{\Phi^-}\rangle = \tfrac{1}{\sqrt{2}}\bigl(|00\rangle - |11\rangle\bigr), \quad \text{eigenvalue } -1, Ψ+=12(01+10),eigenvalue +1,|{\Psi^+}\rangle = \tfrac{1}{\sqrt{2}}\bigl(|01\rangle + |10\rangle\bigr), \quad \text{eigenvalue } +1, Ψ=12(0110),eigenvalue 1.|{\Psi^-}\rangle = \tfrac{1}{\sqrt{2}}\bigl(|01\rangle - |10\rangle\bigr), \quad \text{eigenvalue } -1.

Multiplying by the minus sign in HH, eigenstates with X0X1X_0 X_1 eigenvalue +1+1 get HH eigenvalue 1-1 and those with eigenvalue 1-1 get HH eigenvalue +1+1. The ground energy is E0=1E_0 = -1, and it is doubly degenerate: both Φ+|\Phi^+\rangle and Ψ+|\Psi^+\rangle are ground states.

E0=1,ground subspace=span{Φ+,Ψ+}.E_0 = -1, \quad \text{ground subspace} = \mathrm{span}\bigl\{|\Phi^+\rangle,\,|\Psi^+\rangle\bigr\}.

You can confirm this satisfies the variational bound: any two-qubit state ψ|\psi\rangle obeys ψHψ1\langle \psi | H | \psi \rangle \geq -1, with equality for any state in the ground subspace.

What VQE does (conceptually)

A real VQE run would:

  1. Initialize a hardware-efficient ansatz, e.g.\ RY(θ0)0RY(θ1)0R_Y(\theta_0)|0\rangle \otimes R_Y(\theta_1)|0\rangle followed by a CNOT.
  2. Measure the energy E(θ0,θ1)=ψ(θ)Hψ(θ)E(\theta_0, \theta_1) = \langle \psi(\boldsymbol{\theta}) | H | \psi(\boldsymbol{\theta}) \rangle by sampling in the XX basis (basis-change circuit: Hadamard before measurement).
  3. Optimize θ\boldsymbol{\theta} with a classical optimizer (COBYLA, gradient descent via the parameter-shift rule, etc.) until EE stops decreasing.
  4. The final circuit at convergence prepares the ground state.

For this two-qubit problem, the optimizer converges to a circuit whose output is Φ+|\Phi^+\rangle. That circuit is simply a Hadamard followed by a CNOT — the same Bell-state preparation you first built in module 4.

Why the Bell circuit reaches the target state

The specific ground state the exercise grader checks for is Φ+|\Phi^+\rangle, which is maximally entangled: it cannot be written as a product ψ0ψ1|\psi_0\rangle \otimes |\psi_1\rangle. Reaching Φ+|\Phi^+\rangle in particular therefore requires an entangling gate.

It is worth noting that the ground energy E0=1E_0 = -1 is not unique to entangled states. For example, the product state ++=H0H0|{+}\rangle|{+}\rangle = H|0\rangle \otimes H|0\rangle satisfies ++H++=X2=1\langle {+}{+}|H|{+}{+}\rangle = -\langle X\rangle^2 = -1, so it also achieves energy 1-1 and lies in the ground subspace. The ground subspace is two-dimensional, spanned by Φ+|\Phi^+\rangle and Ψ+|\Psi^+\rangle, and contains both entangled and product-state representatives.

A single CNOT layer is sufficient to reach Φ+|\Phi^+\rangle exactly (the target of this checkpoint), which is why the Bell circuit H0CNOT01H_0 \cdot CNOT_{01} is the natural choice.

Energies of all basis states

To build intuition, compare the energy of the VQE result with the energy of a random guess. For any computational basis state xy|xy\rangle the expectation value of H=XXH = -XX is

xy(X0X1)xy=xyxy=0,\langle xy | (-X_0 X_1) | xy \rangle = -\langle xy | x'y' \rangle = 0,

where xyx'y' is the bit-flipped state. Since xyxy|xy\rangle \perp |x'y'\rangle in the computational basis, all basis states give zero energy — much worse than the ground state energy of 1-1. Ground states achieve their energy precisely because of quantum superposition: the off-diagonal action of XX on a superposition produces a non-zero overlap with the original state, yielding a negative energy. The Bell state Φ+|\Phi^+\rangle additionally relies on entanglement, but any state in the two-dimensional ground subspace will do.

Try it

The classical optimizer has converged and found that the optimal circuit is H0CNOT01H_0 \cdot CNOT_{01}. Build that circuit to prepare the ground state of H=X0X1H = -X_0 X_1. The grader checks the full statevector, so a blank circuit or a computational basis state will not pass.

Run your code to see the quantum state.

After running, inspect the statevector: you should see amplitudes 120.707\tfrac{1}{\sqrt{2}} \approx 0.707 on 00|00\rangle and 11|11\rangle, and zero on 01|01\rangle and 10|10\rangle. This is Φ+|\Phi^+\rangle, a ground state of the XXXX Hamiltonian (ground energy E0=1E_0 = -1), achieved by the VQE at its convergence point.

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