Curriculum / Quantum Algorithms / Variational Eigensolver Basics

Lesson 11 of 12Code challengePro+200 XP

Variational Eigensolver Basics

Build a simple VQE-style ansatz and understand variational quantum algorithms.

VQE: Variational Quantum Eigensolver

The Variational Quantum Eigensolver (VQE) is the most widely studied near-term quantum algorithm. It combines a parameterized quantum circuit (the ansatz) with a classical optimizer to find the ground state energy of a Hamiltonian: with applications in quantum chemistry, materials science, and optimization.

The variational principle:

The foundation of VQE is the quantum variational principle:

Any quantum state |ψ(θ)⟩ provides an upper bound on the ground state energy. By minimizing ⟨ψ(θ)|H|ψ(θ)⟩ over θ, we approach (or reach) the ground state.

The hybrid loop:

VQE operates as a hybrid quantum-classical algorithm:

  1. 1.Prepare the ansatz state |ψ(θ)⟩ on the quantum computer
  2. 2.Measure the energy: E(θ) = ⟨ψ(θ)|H|ψ(θ)⟩ via expectation values of Pauli terms
  3. 3.Optimize: a classical optimizer (COBYLA, L-BFGS, SPSA) updates θ to reduce E(θ)
  4. 4.Repeat until convergence

The quantum computer does only steps 1-2; the optimizer runs classically. This keeps circuit depth shallow: compatible with near-term hardware.

Decomposing the Hamiltonian into Pauli terms

Any Hermitian operator (including molecular Hamiltonians) can be written as a sum of tensor products of Pauli matrices: , where . Each Pauli term can be measured separately: requires measuring in the appropriate basis. The total energy is assembled classically from many measurement groups. For H₂ (hydrogen molecule): .

Ansatz design:

The ansatz must balance:

  • Expressibility: can it represent the target ground state?
  • Trainability: do gradient signals survive (no barren plateaus)?
  • Hardware efficiency: does the gate structure match the hardware connectivity?

Common ansatze:

  • Hardware Efficient Ansatz (HEA): alternating single-qubit rotations + entangling gates, optimized for device topology
  • UCCSD (Unitary Coupled Cluster): chemically motivated, captures electron correlation
  • QAOA-style: problem-inspired, structured for specific Hamiltonians (QAOA, the Quantum Approximate Optimization Algorithm, is the subject of the next lesson)

This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.

How this lesson works

A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.

Part of: Quantum Algorithms

Learn the algorithms that make quantum computers powerful.

This lesson is part of Pro

Unlock Quantum Algorithms and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.