Exercises: Chapter 19 — Variational Quantum Eigensolver (VQE) — Finding Ground State Energies for Chemistry and Materials Science
Exercise 19.1: Variational Principle Proof
Prove the variational principle: for any normalized trial state $|\psi\rangle$, $\langle\psi|H|\psi\rangle \geq E_0$, with equality if and only if $|\psi\rangle = |\Psi_0\rangle$. Then show that if $|\psi\rangle = \sqrt{1-\epsilon^2}|\Psi_0\rangle + \epsilon|\Psi_1\rangle$, the energy error is $O(\epsilon^2)$, not $O(\epsilon)$. This is why VQE can achieve chemical accuracy even with imperfect wavefunctions.
Exercise 19.2: Pauli Measurement Basis Rotations
Derive the basis rotation circuits for measuring $\langle X \rangle$, $\langle Y \rangle$, and $\langle Z \rangle$ on a single qubit. Then generalize to a 2-qubit Pauli string $\langle X \otimes Y \rangle$. Draw the measurement circuit and compute the expected outcome probabilities for the Bell state $|\Phi^+\rangle = (|00\rangle + |11\rangle)/\sqrt{2}$.
Exercise 19.3: Commuting Group Partition
Given the 4-qubit Hamiltonian: $$H = 0.5\, IIZI + 0.3\, IZII + 0.2\, ZIII + 0.4\, IZZI + 0.1\, ZIZI + 0.6\, XIXI + 0.3\, IXIX + 0.2\, XXXX$$
Partition the terms into the minimum number of qubit-wise commuting groups. How many distinct measurement circuits are needed? Compare with the naive approach of measuring each term separately.
Exercise 19.4: Implement SPSA Optimizer
Implement the SPSA optimizer from scratch and apply it to a simple 2-parameter VQE problem (e.g., a 2-qubit ansatz for a model Hamiltonian). Compare convergence speed and noise robustness with COBYLA by adding simulated Gaussian noise to the energy evaluations.
Exercise 19.5: Noise Impact Analysis
Using the noise model from the Qiskit example in Section 19.11, run the H₂ VQE calculation with varying two-qubit gate error rates ($p_2 \in [0, 0.05]$). Plot the VQE energy error vs. $p_2$. At what error rate does the VQE energy error exceed chemical accuracy (1 kcal/mol)? Discuss the implications for current hardware.
Exercise 19.6: UCCSD Ansatz Construction
For the BeH₂ molecule (4 electrons in 10 spin-orbitals), count the number of single and double excitation operators in UCCSD. Estimate the number of CNOT gates required for the Jordan-Wigner mapped circuit. How does this compare with current hardware coherence times?
Exercise 19.7: Trotter Error Analysis
The first-order Trotter decomposition of $e^{\hat{T} - \hat{T}^\dagger}$ introduces an error of $O(\theta^2/N_t)$, where $N_t$ is the number of Trotter steps. For H₂, the single double excitation amplitude $\theta \approx 0.1$. How many Trotter steps are needed for a Trotter error below 1 mHartree? What is the circuit depth for this number of steps?
Exercise 19.8: ZNE with Richardson Extrapolation
Implement zero-noise extrapolation using Richardson extrapolation (fitting a polynomial to data at noise scale factors $\lambda = 1, 3, 5$ and extrapolating to $\lambda = 0$). Compare the extrapolated energy with the linear ZNE result and the unmitigated result for the H₂ VQE.
Exercise 19.9: Barren Plateau Detection
Implement a function that estimates the gradient variance for a hardware-efficient ansatz with $n = 2, 4, 6, 8, 10$ qubits and depth 3. For each $n$, sample 500 random parameter sets and compute $\text{Var}[\partial E / \partial \theta_1]$. Plot the variance vs. $n$ on a log scale. Does it decay exponentially? What is the implication for VQE scalability?
Exercise 19.10: Active Space Reduction for H₂O
Using Qiskit Nature, set up the H₂O molecule and apply an active space transformation that freezes the oxygen 1s orbital and keeps 6 electrons in 8 spin-orbitals. Compute the number of qubits and Pauli terms before and after reduction. How does the UCCSD ansatz size change?
Exercise 19.11: Probabilistic Error Cancellation
For a single-qubit depolarizing channel with $p = 0.05$, implement probabilistic error cancellation to recover the expectation value $\langle Z \rangle$ for the state $R_Y(\pi/3)|0\rangle$. Compute the quasi-probability decomposition and the sampling overhead $\gamma$. How many shots are needed for 1% precision?
Exercise 19.12: Commuting Group Partitioning
Implement the sorted-insertion heuristic for grouping Pauli terms. Given the H₂O Hamiltonian (after active space reduction), partition the terms into qubit-wise commuting groups. Compare the number of groups with the number of terms. What is the measurement reduction factor?
Exercise 19.13: Quantum Natural Gradient
Implement quantum natural gradient descent for the 2-qubit H₂ VQE. Compute the Fubini-Study metric tensor $g_{ij}$ at each iteration and use it to precondition the gradient. Compare convergence (iterations to chemical accuracy) with standard gradient descent and COBYLA. Under what conditions does natural gradient significantly outperform?
Exercise 19.14: Subspace-Expansion VQE for Excited States
Implement the subspace-expansion method for finding the first excited state of H₂. After finding the ground state $|\psi_0\rangle$, search for the first excited state by adding a correction vector $|\phi\rangle = \sum_k c_k (H - E_0)|\psi_0\rangle$ orthogonal to $|\psi_0\rangle$. Compare the result with the exact first excited state energy.