YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Quantum Krylov Subspace Diagonalization (QKSD) on the TFIM
Real-time-evolution Quantum Krylov diagonalization for the ground-state energy of a 4-qubit transverse-field Ising model at criticality (J = h = 1, open boundaries), implemented from scratch in Qiskit 2.x.
References:
- Kirby, Analysis of quantum Krylov algorithms with errors, arXiv:2401.01246.
- Klymko, Williams-Young, Sud, de Jong, Tubman, Real-Time Krylov Theory, arXiv:2208.01063.
- Cortes & Gray, QKSD for ground and excited states, arXiv:2109.06868.
- Lee, Choi, Huh, Izmaylov, Efficient strategies for reducing QKSD sampling error, arXiv:2409.02504.
Algorithm
Pick reference state |Ο_0β© = |+β©^β4 (overlap with the true ground state ~ 0.81). Build the non-orthogonal Krylov basis
V = [|Ο_0β©, U(Ξt)|Ο_0β©, U(2Ξt)|Ο_0β©, U(3Ξt)|Ο_0β©], U(t) = e^(βiHt).
Form the (D Γ D) Toeplitz matrices
S_jk = β¨Ο_0|U((kβj)Ξt)|Ο_0β©
H_jk = β¨Ο_0|U((kβj)Ξt) H|Ο_0β©
and solve the generalized eigenvalue problem H c = E S c with thresholded SVD on S (truncate eigenvalues < Ξ΅ Ξ»_max(S)) to handle ill-conditioning. The smallest E approximates E_0.
Each matrix element is measured by a Hadamard test: an ancilla in |+β©, a controlled-W where W is either U(mΞt) (for S) or U(mΞt) P_Ξ± (for each Pauli term P_Ξ± in H), and read out β¨Z_ancβ© β real part, β¨Y_ancβ© β imaginary part. The script measures all 7 Pauli terms Γ 7 distinct lags Γ 2 (real / imag) per shot count.
Time evolution is implemented with PauliEvolutionGate (LieTrotter
synthesis); for this model the Trotter representation is exact to
machine precision.
Three modes compared
| mode | matrix elements | purpose |
|---|---|---|
| A | exact statevector | algorithm-only test (Krylov truncation only) |
| B | Hadamard test, exact (no shots) | sanity-check the Hadamard-test wiring |
| C | Hadamard test, finite shots | full quantum simulation |
Results
Exact ground-state energy of the TFIM(N=4, J=h=1): E_0 = β4.75877.
| method | E_min | error |
|---|---|---|
| classical exact diag | β4.75877 | 0 |
| Krylov A (classical, D=4) | β4.74338 | +0.0154 |
| Krylov B (exact Hadamard, D=4) | β4.74338 | +0.0154 |
| Krylov C (sampled, 8000 sh./elem.) | β5.0958 | β0.337 β non-variational |
| Krylov C (sampled, 8000 sh., eps=0.1, kept=2) | β4.62 | +0.14 (variational) |
Convergence with Krylov dimension D (mode A)
| D | E_min | error |
|---|---|---|
| 1 | β4.0000 | 0.759 |
| 2 | β4.5907 | 0.168 |
| 3 | β4.7005 | 0.058 |
| 4 | β4.7434 | 0.015 |
Roughly exponential convergence β exactly what real-time Krylov is known to give for gapped Hamiltonians.
What goes wrong under shot noise
S is genuinely ill-conditioned (eigenvalues 0.029, 0.24, 0.45, 3.28 β cond β 110). With finite shots, S_C is a noisy version of S_A; even at 8000 shots per element the noise on the smallest eigenvalue (~0.03) is comparable to its magnitude. The regularized GEVP then explores a slightly wrong subspace and can give a non-variational eigenvalue below the true ground state β this is exactly the pathology discussed in arXiv:2401.01246 and 2409.02504. Aggressive truncation (eps = 0.1, keep only 2 directions) restores variationality but sacrifices resolution.
The shots scan also shows that simply throwing more shots is not enough: even at 32 000 shots per element, the best |error| stays ~0.12. The condition number of S is the bottleneck, not raw statistical precision. Mitigations the literature proposes: thresholded GEVP (Epperly et al.), measurement-efficient construction of Krylov matrices (Zhang et al. 2301.13353), measurement-allocation strategies (Lee et al. 2409.02504), or symmetry-aware schemes (Cortes & Gray).
Files
qksd_tfim.py
artifacts/
βββ results.json # all matrix elements, energies, S spectra
βββ run.log # full execution log (everything printed above + per-element values)
βββ bar.png # 4-bar comparison
βββ convergence_D.png # |EβE_exact| vs D (log-y)
βββ shots_scan.png # |EβE_exact| vs shots (log-log, mode C)
βββ S_matrices.png # |S| heatmaps for modes A, B, C
README.md
Run
pip install "qiskit~=2.4" qiskit-aer scipy matplotlib
python qksd_tfim.py
Tested with qiskit==2.4.1, qiskit-aer==0.17.2. Runtime ~50 s on a CPU sandbox.
Bugs I hit while building this (so they're documented)
- Hand-rolled Trotter circuit had wrong sign convention β gave a
spectral-norm error of ~2 (independent of
reps!) which made modes B and C wildly wrong on the first run. Fix: use Qiskit'sPauliEvolutionGate+LieTrotter. - Setting
AerSimulator(seed_simulator=β¦)at construction reuses the same RNG state on every.run()call, biasing aggregated estimators. Fix: pass a freshseed_simulator=per.run()call (already carried over from the previous shadows demo).