|q⟩ Bad Qubits

intermediate · Programming · Variational Quantum Eigensolver (VQE)

Ansatz Circuits

In VQE the quantum computer's job is to prepare a trial state ψ(θ)|\psi(\boldsymbol{\theta})\rangle whose energy ψ(θ)Hψ(θ)\langle\psi(\boldsymbol{\theta})|H|\psi(\boldsymbol{\theta})\rangle we want to minimize. The circuit that prepares this trial state is called the ansatz (German: "initial attempt" or "approach"). Choosing a good ansatz is the central design decision in any VQE experiment.

What makes a good ansatz?

An ansatz must balance two competing demands:

The two are in tension: a circuit with more layers can reach more states but also incurs more error.

Hardware-efficient ansatz

The most common near-term choice is the hardware-efficient ansatz (HEA): apply single-qubit rotation gates (typically RYR_Y or RYRZR_Y R_Z pairs) to every qubit, then add a layer of two-qubit entangling gates (CNOT or CZ) that match the device's native connectivity. Repeat for LL layers.

For two qubits, one layer looks like this:

ψ(θ0,θ1)=CNOT01[RY(θ0)RY(θ1)]00.|\psi(\theta_0, \theta_1)\rangle = \mathrm{CNOT}_{01}\,\bigl[R_Y(\theta_0)\otimes R_Y(\theta_1)\bigr]\,|00\rangle.

The RYR_Y rotation is

RY(θ)=(cos(θ/2)sin(θ/2)sin(θ/2)cos(θ/2)),R_Y(\theta) = \begin{pmatrix} \cos(\theta/2) & -\sin(\theta/2) \\ \sin(\theta/2) & \cos(\theta/2) \end{pmatrix},

so RY(θ)0=cos(θ/2)0+sin(θ/2)1R_Y(\theta)|0\rangle = \cos(\theta/2)|0\rangle + \sin(\theta/2)|1\rangle. When θ=π/2\theta = \pi/2 this is the +|+\rangle state; θ=π\theta = \pi gives 1|1\rangle.

Entanglement is essential

Without the CNOT layer the ansatz is a product state ψ0ψ1|\psi_0\rangle \otimes |\psi_1\rangle, which can never reach an entangled ground state. Even a single entangling gate can dramatically increase expressibility. For a 2-qubit system, one CNOT layer is often enough to reach any state in the two-dimensional subspace of interest.

Try it

Build a two-qubit hardware-efficient ansatz with the angles fixed to θ0=π/3\theta_0 = \pi/3 and θ1=π/4\theta_1 = \pi/4. The grader checks the full state vector, so the circuit must produce the correct amplitudes.

Run your code to see the quantum state.

After running, inspect the amplitudes: the CNOT entangles the two qubits so you cannot write the output as a simple tensor product. That entanglement is exactly what lets VQE explore correlated ground states.

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