quimb

1.13.0 · active · verified Thu Apr 16

quimb is a versatile Python library for quantum information and many-body physics, offering tools for exact diagonalization, tensor networks (Matrix Product States, PEPS, etc.), quantum circuits, and general quantum mechanics simulations. It is currently at version 1.13.0 and maintains an active release cadence, with major and minor updates often arriving monthly or bi-monthly, frequently including breaking changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a random state vector and a simple Matrix Product State (MPS) using quimb's core and tensor network modules, along with basic operations like calculating norm and contraction.

import quimb as qb
import quimb.tensor as qb.tn

# Create a random state vector
psi = qb.rand_ket(8)  # 8-dimensional random state
print(f"State vector shape: {psi.shape}")

# Create a simple Matrix Product State (MPS)
L = 10  # Number of sites
D = 8   # Max bond dimension
d = 2   # Local dimension
psi_mps = qb.tn.rand_mps(L, D, d)
print(f"MPS with {L} sites, max bond dim {psi_mps.max_bond_dim()}, local dim {d}")

# Calculate the MPS norm
print(f"MPS norm: {psi_mps.norm()}")

# Contract the MPS to a single tensor (the full state vector)
# Note: This can be memory intensive for large L and D
full_state_from_mps = psi_mps.contract()
print(f"Full state from MPS shape: {full_state_from_mps.shape}")

view raw JSON →