quantum-simulation-lab
A test-driven tensor network library for finite-size DMRG, TEBD, and MPS/MPO algorithms on 1D quantum lattice models.
Installation · Quickstart · Features · Roadmap · Diary
Overview
quantum-simulation-lab is a from-scratch Python implementation of the core tensor network stack needed for finite-size DMRG and TEBD time evolution on 1D quantum lattice models. The focus is on correctness and clarity — every algorithm is covered by a dense test suite and cross-validated against exact diagonalisation and iTensor.
This project serves as both a learning vehicle and a research platform, built with the same engineering discipline expected in production scientific software: strict CI, typed APIs, and regression tests at every layer.
Features
🧱 Core Tensor Network Primitives
Tensor,Index— numpy-backed tensors with named indices and full linear algebra supportMPS— matrix product states with product-state, statevector, and qubit-label constructorsMPO— matrix product operators with identity, dense conversion, and MPS applicationTruncationPolicy— configurable SVD truncation (cutoff, max bond dimension, strict mode)- Utility routines for expectation values and left/right environments
⚛️ Hamiltonian Builders
- Transverse-field Ising model (TFIM)
- XXZ Heisenberg model — via
heisenberg_mpoand XX wrappers - Random field models — X and Z directions, ZZ+Z coupling
- Transverse Heisenberg model
🔬 Finite-Size 2-Site DMRG
- Mixed-canonical MPS, incremental left/right environments
- Two-site effective Hamiltonians with correct gauge fixing per sweep direction
- Converges on TFIM, Heisenberg, random Z/X fields, and ZZ+Z — results match iTensor
⏱️ TEBD Time Evolution (v2)
apply_two_site_gate— in-place SVD-based two-site gate application with optional truncationtwo_site_gate_from_hamiltonian/two_site_gate_imaginary— exact-diagonalisation gate buildersfinite_tebd— first-order Trotter real-time evolutionfinite_tebd_strang— second-order (Strang) Trotter splittingfinite_tebd_imaginary— imaginary-time evolution with optional in-loop energy callbackground_state_search— high-level ground-state search: runs imaginary-time TEBD to convergence, returns energy history and converged MPSmeasure_local— single-site expectation values via transfer-matrix sweepmeasure_bond_energies— two-site bond energy expectations
🔀 Entangled State Helpers (v2)
- Bell states (all four), GHZ states, W states — both statevector and MPS form
🧪 Test Suite
- 362 pytest tests — unit, integration, dense-reference checks, DMRG regression tests, and TEBD convergence tests
- CI runs on every push and pull request via GitHub Actions
Installation
pip install quantum-simulation-lab
Or from source:
git clone https://github.com/szmbthydmnk/quantum-simulation-lab.git
cd quantum-simulation-lab
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
Quickstart
Ground State Search with Imaginary-Time TEBD
import numpy as np
from tensor_network_library.core.mps import MPS
from tensor_network_library.algorithms.tebd import ground_state_search
L, J = 10, 1.0
d = 2
# Two-site Heisenberg Hamiltonian h_{i,i+1} = J/4 (XX + YY + ZZ)
X = np.array([[0, 1], [1, 0]], dtype=np.complex128)
Y = np.array([[0, -1j], [1j, 0]], dtype=np.complex128)
Z = np.array([[1, 0], [0, -1]], dtype=np.complex128)
H_local = J / 4.0 * (np.kron(X, X) + np.kron(Y, Y) + np.kron(Z, Z))
# Random initial MPS
rng = np.random.default_rng(42)
psi0 = rng.standard_normal(d**L) + 1j * rng.standard_normal(d**L)
mps0 = MPS.from_statevector(psi0 / np.linalg.norm(psi0), physical_dims=d)
result = ground_state_search(
mps0, H_local,
dtau=0.05, max_steps=300, chi_max=32, energy_tol=1e-8,
verbose=True,
)
print(f"Converged: {result.converged} after {result.n_steps} steps")
print(f"Ground-state energy: {result.energy_history[-1]:.10f}")
Ground State of TFIM with DMRG
import numpy as np
from tensor_network_library.core.env import Environment
from tensor_network_library.core.mps import MPS
from tensor_network_library.algorithms.dmrg import finite_dmrg, DMRGConfig
from tensor_network_library.hamiltonian.models import tfim_mpo
L, J, g = 10, 1.0, 1.0
env = Environment.qubit_chain(L=L, chi_max=32)
mpo = tfim_mpo(L=L, J=J, g=g)
rng = np.random.default_rng(0)
psi = rng.standard_normal(2**L) + 1j * rng.standard_normal(2**L)
mps0 = MPS.from_statevector(psi / np.linalg.norm(psi), physical_dims=2, normalize=True)
config = DMRGConfig(max_sweeps=10, energy_tol=1e-10, verbose=True)
result = finite_dmrg(env, mpo, mps0, config)
print(f"Ground-state energy: {result.energies[-1]:.12f}")
Real-Time Evolution with TEBD
import numpy as np
from tensor_network_library.core.mps import MPS
from tensor_network_library.algorithms.tebd import (
TEBDConfig,
two_site_gate_from_hamiltonian,
finite_tebd,
measure_local,
)
L = 10
dt = 0.05
n_steps = 40
J = 1.0
X = np.array([[0, 1], [1, 0]], dtype=np.complex128)
Y = np.array([[0, -1j], [1j, 0]], dtype=np.complex128)
Z = np.array([[1, 0], [0, -1]], dtype=np.complex128)
H_local = J / 4.0 * (np.kron(X, X) + np.kron(Y, Y) + np.kron(Z, Z))
labels = ["up" if i % 2 == 0 else "down" for i in range(L)]
mps0 = MPS.from_qubit_labels(labels)
G = two_site_gate_from_hamiltonian(H_local, dt)
config = TEBDConfig(n_steps=n_steps, normalize=True)
mps_t = finite_tebd(mps0, G, G, config=config)
Sz = 0.5 * Z
sz_profile = measure_local(mps_t, Sz)
print(f"<Sz> profile at t={n_steps * dt:.2f}: {sz_profile.round(4)}")
See examples/ for convergence plots and random-field model scripts.
Running Tests
pytest
The CI badge above reflects the current state of the main branch.
Roadmap
| Version | Focus | Status |
|---|---|---|
| v1 | Finite-size DMRG — qubit and spin-1/2 chains | ✅ Done |
| v2 | TEBD — real- and imaginary-time evolution, ground-state search | ✅ Done |
See ROADMAP.md for detailed per-version task lists and DIARY.md for development notes.
Lines of code
Last updated automatically by CI:
7733
Metadata
Release files for quantum-simulation-lab 2.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| quantum_simulation_lab-2.0.3.tar.gz | 316.7 kB | With provenance | Details for quantum_simulation_lab-2.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| quantum_simulation_lab-2.0.3-py3-none-any.whl | Python 3 | none | any | Details for quantum_simulation_lab-2.0.3-py3-none-any.whl |
Total release size: 381.9 kB
Release files / quantum_simulation_lab-2.0.3.tar.gz
| Download URL | quantum_simulation_lab-2.0.3.tar.gz |
|---|---|
| Size | 316.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6edc549d7795897ce61fd08d565034e6ddd888294ceb8f02903f363724a01787
|
|
BLAKE2b-256 checksum How to use checksums |
cfe809a7497677280314026007e38e2ac1b1625f44e876e38beb9742ceab22f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.
Transparency logRelease files / quantum_simulation_lab-2.0.3-py3-none-any.whl
| Download URL | quantum_simulation_lab-2.0.3-py3-none-any.whl |
|---|---|
| Size | 65.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f876d73737e77c3357bf69263bfd2e3e55f6384eafc79f71721432ab92984d74
|
|
BLAKE2b-256 checksum How to use checksums |
d538288a4dfcbe866eb8297d457770d554435c0c67e1aa7caba43d32c6f8ba0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.
Transparency logSecurity for quantum-simulation-lab 2.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for quantum_simulation_lab-2.0.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.