Variational Quantum Deflation (VQD) — General Implementation
What You'll Learn:
- How VQD scales to larger systems (4 qubits, arbitrary Hamiltonian)
- How the deflation process systematically removes found states from the search space
- Why β must increase as more states are found (cumulative penalty landscape)
- How to implement measurement-based energy computation for a spin-chain Hamiltonian
Level: Advanced | Time: 30 minutes | Qubits: 4 | Framework: Qiskit
Prerequisites
- H2 Excited States — VQD on 2 qubits (molecular Hamiltonian)
- H2 Ground State — VQE fundamentals
The Idea
The H2 VQD tutorial shows the core algorithm on 2 qubits with a molecular Hamiltonian. This circuit generalizes VQD to arbitrary Hamiltonians and demonstrates it on the 4-qubit Transverse Field Ising Model (TFIM) — a fundamental model in condensed matter physics.
VQD works by "deflating" the Hilbert space: after finding each eigenstate, it adds a penalty that makes that region of the space expensive to visit. The optimizer is forced to explore new regions, discovering higher-energy states.
CODEState 0 (VQE): L₀ = ⟨H⟩ State 1 (VQD): L₁ = ⟨H⟩ + β₀|⟨ψ₁|ψ₀⟩|² State 2 (VQD): L₂ = ⟨H⟩ + β₀|⟨ψ₂|ψ₀⟩|² + β₁|⟨ψ₂|ψ₁⟩|²
Each additional state adds one more penalty term. The penalty "walls" accumulate, creating an increasingly constrained landscape.
How It Works
The Transverse Field Ising Model
H = -Σᵢ ZᵢZᵢ₊₁ - h Σᵢ Xᵢ (h = 0.5)
| Term | Physical meaning |
|---|---|
| -ZᵢZᵢ₊₁ | Nearest-neighbor spin alignment (ferromagnetic coupling) |
| -hXᵢ | Transverse field (quantum fluctuations, spin flipping) |
At h = 0.5 (below critical point h = 1.0), the system is in the ordered phase: spins prefer to align, and the ground state is close to the even superposition of |0000⟩ and |1111⟩. The two lowest levels are nearly degenerate (E₁ - E₀ ≈ 0.095), then E₂ - E₁ ≈ 1.51.
Measurement Strategy
The TFIM has two types of Pauli terms:
-
ZZ terms (3 for 4 qubits): Measured in the computational basis. One circuit gives all ZZ expectations simultaneously.
-
X terms (4 for 4 qubits): Each requires a Hadamard rotation before measurement. We can measure all X terms from individual single-qubit rotations on the same circuit.
Total: 2 measurement circuits per energy evaluation (one in the Z basis, one with a Hadamard on every qubit).
Hardware-Efficient Ansatz
CODE┌────────┐ ┌────────┐┌────────┐ ┌────────┐┌────────┐ q_0: ┤ RY(θ₀) ├──■───────┤ RY(θ₄) ├┤ RZ(θ₅) ├──■───────┤ RY(θ₁₂)├┤ RZ(θ₁₃)├ ├────────┤┌─┴─┐ ├────────┤├────────┤┌─┴─┐ ├────────┤├────────┤ q_1: ┤ RY(θ₁) ├┤ X ├──■──┤ RY(θ₆) ├┤ RZ(θ₇) ├┤ X ├──■──┤ RY(θ₁₄)├┤ RZ(θ₁₅)├ ├────────┤└───┘┌─┴─┐├────────┤├────────┤└───┘┌─┴─┐├────────┤├────────┤ q_2: ┤ RY(θ₂) ├─────┤ X ├┤ RY(θ₈) ├┤ RZ(θ₉) ├─────┤ X ├┤ RY(θ₁₆)├┤ RZ(θ₁₇)├ ├────────┤ └───┘├────────┤├────────┤ └───┘├────────┤├────────┤ q_3: ┤ RY(θ₃) ├──────────┤ RY(θ₁₀)├┤ RZ(θ₁₁)├──────────┤ RY(θ₁₈)├┤ RZ(θ₁₉)├ └────────┘ └────────┘└────────┘ └────────┘└────────┘
20 parameters per state × 3 states = 60 total (but optimized sequentially, 20 at a time).
β Selection for Multiple States
Each penalty βᵢ must exceed the gap from state i up to the state being searched for (see the Deflation Guarantee below). For the TFIM at h = 0.5:
| Gap | Approximate value | Recommended β |
|---|---|---|
| E₁ - E₀ | ≈ 0.095 | β₀ > 0.095 to find state 1 |
| E₂ - E₁ | ≈ 1.51 | to find state 2: β₁ > 1.51 and β₀ > E₂ - E₀ ≈ 1.60 |
Using a uniform β = 3.0 provides safety margin for all gaps.
The Math
Deflation Guarantee
VQD converges to the k-th eigenstate if:
- βᵢ > E_k - Eᵢ for every lower state i < k (each penalty exceeds the gap from that state up to the target state; Higgott et al. 2019)
- The ansatz can represent the k-th eigenstate
- The optimizer finds the global minimum
When all conditions hold, the cost function landscape has its global minimum exactly at the k-th eigenstate:
CODEL_k(ψ_k) = E_k + Σᵢ βᵢ × 0 = E_k L_k(ψ_j, j<k) = E_j + βⱼ × 1 > E_j + (E_k - E_j) = E_k
So the ground states of lower cost functions are more expensive than the target state.
Error Propagation
VQD's main weakness: errors compound. If state k has error εₖ, then state k+1 sees a distorted penalty landscape. The overlap |⟨ψ_{k+1}|ψ̃_k⟩|² (where ψ̃_k is the approximate state k) differs from |⟨ψ_{k+1}|ψ_k⟩|² by O(εₖ). This shifts the optimal state k+1 by O(εₖ/gap).
Expected Output
For TFIM (4 qubits, h = 0.5):
| State (order found) | VQD (6 runs) | Exact | Error |
|---|---|---|---|
| 0 | -2.83 to -1.55 | -3.427 (E₀) | 0.6 to 1.9 |
| 1 | -3.16 to -2.92 | -3.332 (E₁) | 0.17 to 0.42 |
| 2 | -2.39 to -1.18 | -1.827 (E₂) | 0.08 to 0.65 |
With 50 COBYLA iterations and 2048 shots per circuit the optimizer does not converge: in 6 runs of run_circuit(n_states=3, beta=3.0, max_iterations=50, seed=42) the first state missed E₀ by 0.6 to 1.9, and the second state came out lower than the first in all 6, so the states are not returned in energy order. Runs are not repeatable even with seed=42, because the simulator's shots are not seeded. Try a larger max_iterations to see how close it gets.
Running the Circuit
PYTHONfrom circuit import run_circuit, verify_vqd, compute_exact_eigenvalues # Exact reference exact = compute_exact_eigenvalues(n_states=3) print(f"Exact: {[f'{e:.4f}' for e in exact]}") # VQD: find 3 eigenstates sequentially result = run_circuit(n_states=3, beta=3.0, max_iterations=50, seed=42) for state in result['states']: print(f"State {state['index']}: E = {state['energy']:.4f}") # Verification v = verify_vqd() for check in v["checks"]: status = "PASS" if check["passed"] else "FAIL" print(f"[{status}] {check['name']}: {check['detail']}")
Try It Yourself
-
Break β: Set
beta=0.05(below the first gap of about 0.095). The second state can then collapse back to the ground state. -
Find 5 states: Run
run_circuit(n_states=5). Do the higher states maintain correct ordering? Does the error grow linearly or faster? -
Critical point: Set
TRANSVERSE_FIELD=1.0. For an infinitely long chain the gap closes here (the quantum phase transition), but on 4 sites the lowest gap actually grows, from about 0.09 to about 0.69. Compare VQD at h = 0.5 and h = 1.0. How large does β need to be? -
Compare with SSVQE: Run SSVQE for the same system. Which method gets better excited states? (Hint: SSVQE finds them simultaneously, so no error propagation.)
-
Increase shots: Run with 256, 1024, 4096, 16384 shots. Does the spread (standard deviation) of the energy shrink as 1/√shots?
What's Next
- SSVQE — Simultaneous optimization (no error propagation)
- Multistate VQE — Contracted Hamiltonian (few parameters)
- H2 Excited States — 2-qubit molecular VQD
Applications
| Domain | Use case |
|---|---|
| Condensed matter | Spin chain excitation spectra |
| Quantum chemistry | Full molecular energy manifold |
| Quantum dynamics | Propagator construction from eigenstates |
| Spectroscopy | Transition energy predictions |
References
- Higgott, O., Wang, D., Brierley, S. (2019). "Variational Quantum Computation of Excited States." Quantum 3, 156. DOI: 10.22331/q-2019-07-01-156
- McClean, J.R. et al. (2016). "The theory of variational hybrid quantum-classical algorithms." New Journal of Physics 18, 023023. DOI: 10.1088/1367-2630/18/2/023023
- Nakanishi, K.M., Mitarai, K., Fujii, K. (2019). "Subspace-search variational quantum eigensolver for excited states." Physical Review Research 1, 033062. DOI: 10.1103/PhysRevResearch.1.033062