A lightweight, educational Python library for simulating one-dimensional quantum spin chains using the Time-Evolving Block Decimation (TEBD) algorithm with Matrix Product States (MPS).
- Ground-state preparation via imaginary-time evolution
- Real-time quench dynamics for studying information spreading
- Light-cone visualization with Lieb-Robinson bound validation
- Systematic error analysis (Trotter, truncation, convergence)
- Modular design — easily extend to new models
- Minimal dependencies — only NumPy, SciPy, and Matplotlib
git clone https://github.com/yi-hsiu-yang/qdynet.git
cd qdynet
pip install -e .from qdynet.models import TFIM
from qdynet.mps import product_state_mps, imaginary_time_evolution
from qdynet.observables import half_chain_entropy
from qdynet.utils import TEBDConfig
# Configure simulation
config = TEBDConfig(L=40, chi_max=64, dtau=0.02)
# Initialize MPS in |+⟩^⊗L state
mps = product_state_mps(config.L, state="plus")
# Create TFIM at critical point (J=h=1)
model = TFIM(J=1.0, h=1.0, L=config.L)
# Evolve to ground state
mps, history = imaginary_time_evolution(mps, model, config)
# Measure observables
energy = model.energy_density(mps)
entropy = half_chain_entropy(mps)
print(f"E/N = {energy:.6f}, S = {entropy:.4f}")from qdynet.mps import real_time_evolution, apply_local_operator
from qdynet.observables import measure_profile
import numpy as np
# Prepare ground state (as above)...
# Apply X operator at center site
X = np.array([[0, 1], [1, 0]])
mps_perturbed = apply_local_operator(mps, X, site=config.L // 2)
# Evolve in real time
config_real = TEBDConfig(L=40, chi_max=64, dt=0.01, t_max=3.0)
mps_t, profiles = real_time_evolution(mps_perturbed, model, config_real)qdynet/
├── src/qdynet/ # Core library
│ ├── models/ # Physical models (TFIM, XXZ)
│ │ ├── base.py # Abstract base class
│ │ ├── tfim.py # Transverse-field Ising model
│ │ └── xxz.py # XXZ Heisenberg model
│ ├── mps/ # MPS representation and TEBD
│ │ ├── mps_init.py # State initialization
│ │ ├── tebd.py # TEBD algorithm
│ │ ├── evolution.py # High-level evolution routines
│ │ └── gates.py # Gate utilities
│ ├── observables/ # Measurement functions
│ │ ├── energy.py # Energy computation
│ │ ├── entropy.py # Entanglement entropy
│ │ ├── mps_utils.py # MPS manipulation utilities
│ │ └── correlators.py # Two-point functions
│ ├── analysis/ # Post-processing tools
│ │ └── front.py # Light-cone front tracking
│ └── utils/ # Configuration and utilities
│ ├── config.py # Centralized parameters
│ ├── svd.py # SVD with truncation
│ └── timing.py # Performance measurement
└── experiments/ # Runnable experiment scripts
├── ground_state.py # Ground-state preparation
├── quench_dynamics.py # Light-cone dynamics
├── convergence.py # Parameter sweeps
└── error_analysis.py # Systematic error budget
Run pre-built experiments from the experiments/ directory:
# Ground-state preparation
python experiments/ground_state.py
# Outputs: ground_state.csv, fig_gs_energy.png, fig_gs_entropy.png
# Quench dynamics and light-cone visualization
python experiments/quench_dynamics.py
# Outputs: quench_profiles.csv, quench_diagnostics.csv, fig_quench_log.png, fig_quench_front.png
# Parameter convergence analysis
python experiments/convergence.py
# Outputs: convergence.csv, fig_conv_E_vs_chi.png, fig_conv_S_vs_chi.png, fig_conv_time.png
# Full error budget (~8 hours)
python experiments/error_analysis.py --full
# Quick validation (~15 minutes)
python experiments/error_analysis.py --fast
# Outputs: error_*.csv, error_analysis.txt, fig_error_analysis.pngThe model exhibits a quantum phase transition at
-
$g < 1$ : Ordered (ferromagnetic) phase -
$g > 1$ : Disordered (paramagnetic) phase -
$g = 1$ : Critical point with logarithmic entanglement scaling
Exact ground-state energy density (thermodynamic limit):
Validated on TFIM at criticality (J = h = 1, L = 40):
| Metric | Value | Note |
|---|---|---|
| Ground-state energy | ~1% deviation from exact (finite-size) | |
| Numerical error | Trotter + truncation + convergence | |
| Light-cone velocity |
|
Below Lieb-Robinson bound |
| Parameter | Ground State | Quench Dynamics |
|---|---|---|
| System size |
40 | 40 |
| Bond dimension |
64 | 64 |
| Time step |
||
| Total time | ||
| Trotter order | 1st | 2nd |
| SVD threshold |
Extend the SpinChainModel base class:
from qdynet.models.base import SpinChainModel
from scipy.linalg import expm
import numpy as np
class MyModel(SpinChainModel):
def __init__(self, L, **params):
super().__init__(L)
self.params = params
def two_site_gate(self, dt, kind="real"):
"""Return exp(-dt * h_{i,i+1}) for TEBD."""
# Build local Hamiltonian h_{i,i+1}
h_local = ... # Your implementation
if kind == "real":
return expm(-1j * dt * h_local).reshape(2, 2, 2, 2)
else: # imaginary
return expm(-dt * h_local).reshape(2, 2, 2, 2)
def energy(self, mps):
"""Compute total energy ⟨H⟩."""
# Your implementation
passRequired:
- Python ≥ 3.9
- NumPy ≥ 1.20
- SciPy ≥ 1.7
- Matplotlib ≥ 3.5
Optional:
- pytest (testing)
- tqdm (progress bars)
Python 3.12.0
NumPy 1.26.4
SciPy 1.12.0
Matplotlib 3.8.3
OS: Ubuntu 22.04 (WSL2 on Windows 11)
Hardware: AMD Ryzen 7 5800U, 16 GB RAM
Typical execution times on consumer hardware (AMD Ryzen 7, 16 GB RAM):
| Task | Time | Memory |
|---|---|---|
| Ground state ( |
~3 hours | < 1 GB |
| Quench dynamics ( |
~45 min | < 1 GB |
| Convergence sweep | ~3 hours | < 2 GB |
| Full error analysis | ~8 hours | < 2 GB |
- P. Pfeuty, The one-dimensional Ising model with a transverse field, Ann. Phys. 57, 79 (1970)
- P. Calabrese & J. Cardy, Entanglement entropy and quantum field theory, J. Stat. Mech. (2004)
- P. Calabrese & J. Cardy, Evolution of entanglement entropy in one-dimensional systems, J. Stat. Mech. (2005)
- E. H. Lieb & D. W. Robinson, The finite group velocity of quantum spin systems, Commun. Math. Phys. 28, 251 (1972)
- G. Vidal, Efficient classical simulation of slightly entangled quantum computations, Phys. Rev. Lett. 91, 147902 (2003)
- G. Vidal, Efficient simulation of one-dimensional quantum many-body systems, Phys. Rev. Lett. 93, 040502 (2004)
- G. Vidal, Classical simulation of infinite-size quantum lattice systems in one spatial dimension, Phys. Rev. Lett. 98, 070201 (2007)
MIT License — see LICENSE for details.
This project was developed as part of the module "Modern Computational Techniques for Theoretical Physicists" at King's College London, based on a research idea proposed by Professor Nikolay Gromov.