quimb
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
-
ImportError: cannot import name 'OperatorBuilder' from 'quimb.operatorbuilder'
cause The `OperatorBuilder` class was moved in quimb v1.12.0 from `quimb.operatorbuilder` to `quimb.operator`.fixChange your import statement to `from quimb.operator import OperatorBuilder`. -
RuntimeError: 'quimb' requires python>=3.11.
cause You are attempting to run quimb version 1.12.1 or newer on a Python environment older than 3.11.fixUpgrade your Python installation to version 3.11 or higher. For example, using `conda create -n quimb_env python=3.11` or `pyenv install 3.11`. -
TypeError: not all indices were contracted (contracting ... to ...)
cause When performing a tensor network contraction, some indices that were expected to be summed over remain uncontracted, often due to an incorrect `output_inds` specification or a mismatch in tensor indices.fixCarefully review the indices of your tensors and the `output_inds` argument passed to `tn.contract()`. Ensure all internal indices are matched for summation and only desired external indices are left. -
NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'jit' decorator.
cause This warning typically indicates a minor compatibility issue between the installed `numba` and `numpy` versions, or a general Numba best-practice recommendation. While usually harmless, it can sometimes precede other issues.fixUpgrade both `numba` and `numpy` to their latest compatible versions. Use `pip install --upgrade numba numpy`.
Warnings
- breaking quimb now requires Python 3.11 or newer.
- breaking Sign conventions for hopping strength `t` in `ham_hubbard_hardcore` and magnetic field terms in `heisenberg_from_edges` have been fixed/changed.
- breaking The `OperatorBuilder` class has moved from `quimb.operatorbuilder` to `quimb.operator`.
- breaking The `belief_propagation` module has moved from `quimb.tensor` to its own submodule `quimb.tensor.belief_propagation`.
- breaking The method `MatrixProductState.partial_trace` was renamed to `MatrixProductState.partial_trace_to_mpo` to clarify its output type (an MPO).
- gotcha Tensor network contraction can be computationally and memory intensive. Default optimization (`optimize='auto'`) might not always be ideal for very large or complex networks.
Install
-
pip install quimb -
pip install quimb[tensor,cut]
Imports
- quimb
import quimb as qb
- quimb.tensor
import quimb.tensor as qb.tn
- OperatorBuilder
from quimb.operatorbuilder import OperatorBuilder
from quimb.operator import OperatorBuilder
- belief_propagation
from quimb.tensor import belief_propagation
from quimb.tensor.belief_propagation import ...
Quickstart
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}")