Guide A
The stack for tensor network users
You work with quantics tensor trains, tensor cross interpolation or tree tensor networks. This guide tells you which tensor4all-rs crate does what, how it lines up with the Julia packages you may know, and how much of the backend you need to care about (very little).
Status as of 2026-10-13.
The typical workflow
Most QTT work follows the same four steps, and each step has a home crate.
- Describe a grid. Map continuous variables to binary digits with a
DiscretizedGrid(from quanticsgrids-rs, re-exported bytensor4all-quanticstci), choosing bounds, resolution and how variables are interleaved. - Learn a QTT from a function. Run quantics TCI on your function with
tensor4all-quanticstci. The function is sampled in batches, so it can be an expensive solver call. The result can be evaluated, summed and integrated. - Transform it. Apply QTT operators from
tensor4all-quanticstransform: Fourier transform, shift, flip, phase rotation, cumulative sum and affine coordinate maps, with multivariable variants. - Contract and compress. Multiply, contract and truncate with
tensor4all-treetn(zip-up, variational fit, randomized SRC), or withtensor4all-simplettfor plain tensor trains. Elementwise products of QTTs usetensor4all-aci. Save results in an ITensors.jl compatible HDF5 file withtensor4all-hdf5.
Coming from Julia
tensor4all-rs started as a port of the tensor4all Julia ecosystem, so most packages have a direct counterpart. Names follow the Julia ones where it made sense, but the APIs are Rust APIs, not transliterations.
| Julia package | Rust crate | Notes |
|---|---|---|
| TensorCrossInterpolation.jl | tensor4all-tensorci | TCI2 is the primary algorithm; TCI1 is kept for compatibility |
| QuanticsGrids.jl | quanticsgrids-rs | re-exported from tensor4all-quanticstci |
| QuanticsTCI.jl | tensor4all-quanticstci | high level quantics TCI |
| Quantics.jl | tensor4all-quanticstransform | QTT operators as MPOs |
| SimpleTensorTrains.jl | tensor4all-simplett | raw array tensor trains, compression |
| ITensors.jl (MPS, MPO) | tensor4all-itensorlike, tensor4all-core | dynamic Index and Tensor, ITensors-like tensor train API |
| ITensorNetworks.jl, FastMPOContractions.jl | tensor4all-treetn | arbitrary tree topology; canonicalization, contraction, DMRG, TDVP, linear solve |
| TreeTCI.jl | tensor4all-treetci | cross interpolation on trees |
| AlternatingCrossInterpolation.jl | tensor4all-aci | elementwise products of tensor trains |
| InterpolativeQTT.jl | tensor4all-interpolativeqtt | multiscale interpolative QTT construction |
| PartitionedMPSs.jl, TCIAlgorithms.jl (patching) | tensor4all-partitionedtreetn | masked subdomains, adaptive patching; replaces the deprecated tensor4all-partitionedtt |
If you want to stay in Julia, Tensor4all.jl calls tensor4all-rs through its C API. It is maintained on a best effort basis and is meant for light use and teaching. For production runs or anything performance sensitive, use the Rust crates directly.
Which crate to use
| You want to | Start with |
|---|---|
| Compress a function of one or more continuous variables into a QTT | tensor4all-quanticstci |
| Run TCI on a function of discrete indices | tensor4all-tensorci |
| Fourier transform, shift or otherwise transform a QTT | tensor4all-quanticstransform |
| Work with plain tensor trains as arrays (evaluate, sum, compress) | tensor4all-simplett |
| Use named indices like ITensors (MPS and MPO style code) | tensor4all-itensorlike |
| Contract, truncate or sweep (DMRG, TDVP) on chains or trees | tensor4all-treetn |
| Interpolate on a tree topology | tensor4all-treetci |
| Multiply two QTTs elementwise | tensor4all-aci (experimental tree variants: treeaci, treersi) |
| Split a hard function into patches with bounded bond dimension | tensor4all-partitionedtreetn |
| Read and write ITensors.jl HDF5 files | tensor4all-hdf5 |
| Call from C, Julia or another language | tensor4all-capi |
Two stacks and the bridge
tensor4all-rs deliberately contains two families of crates.
- The TT and TCI stack (
simplett,tensorci,quanticstci,quanticstransform) works with tensor trains as arrays indexed by position. It is close to the Julia TCI packages and is the fastest path from a function to a QTT. - The network stack (
core,itensorlike,treetn,treetci,partitionedtreetn) works with named indices and arbitrary tree topologies. A chain is just a tree shaped like a path, so MPS and MPO algorithms live here too.
They coexist on purpose. Converting between them is the job of a single bridge in tensor4all-treetn: tensor_train_to_treetn and treetn_to_tensor_train (with variants that set node names and site indices). A common pattern is to learn a QTT with quantics TCI, move it to the network stack, then apply operators and contract there.
Getting started
The crates are not on crates.io yet. Add them as git dependencies; pin a revision with rev = "..." for reproducible runs.
[dependencies]
tensor4all-simplett = { git = "https://github.com/tensor4all/tensor4all-rs", package = "tensor4all-simplett" }
tensor4all-quanticstci = { git = "https://github.com/tensor4all/tensor4all-rs", package = "tensor4all-quanticstci" }
A tensor train, from the README (checked in CI):
use tensor4all_simplett::prelude::*;
let tt = SimpleTensorTrain::<f64>::constant(&[2, 3, 4], 1.0);
assert!((tt.evaluate(&[0, 1, 2]).unwrap() - 1.0).abs() < 1e-12);
assert!((tt.sum() - 24.0).abs() < 1e-12);
Quantics TCI of x² on [0, 1] with 24 points, from the crate documentation (a doctest):
use tensor4all_quanticstci::{
quanticscrossinterpolate_batch, DiscretizedGrid, QtciOptions, QuanticsBatch,
};
let grid = DiscretizedGrid::builder(&[4])
.with_lower_bound(&[0.0])
.with_upper_bound(&[1.0])
.build()
.unwrap();
let f = |batch: QuanticsBatch<'_, f64>| -> anyhow::Result<Vec<f64>> {
Ok((0..batch.n_points())
.map(|point| batch.get(0, point).unwrap().powi(2))
.collect())
};
let (qtci, _ranks, _errors) =
quanticscrossinterpolate_batch(&grid, f, None, QtciOptions::default()).unwrap();
let integral = qtci.integral().unwrap();
For longer runnable examples (operators, tree networks, patching, GPU contraction), go to the tensor4all-rs user guide and the API reference.
Other entry points
- Julia: Tensor4all.jl (best effort, see above). Its build step compiles tensor4all-rs for you.
- C:
tensor4all-capiexposes indices, tensors, tree tensor networks and quantics materialization through a small FFI surface. - Python:
tensor4all-pyis an early PyO3 prototype forwarding to the core, tree network, tree TCI and quantics TCI crates.
What runs underneath
You rarely need to look below tensor4all-rs, but knowing the shape helps when reading performance numbers or error messages.
- Every dense operation (contraction, SVD, QR) goes through tenferro-rs, reached through one adapter crate,
tensor4all-tensorbackend. tenferro chooses CPU or GPU kernels and provides automatic differentiation. - On the CPU, tenferro hands contractions to tcontract and factorizations to tlinalg (pure Rust, using tensor4all's fork of faer) or optionally to a vendor LAPACK.
- There is no hidden global thread pool. Parallelism comes from an execution context that the caller creates (in tensor4all-rs, a
CpuExecutionContext) and that is reused across calls. If you construct a new context in a tight loop, you throw away its buffers. - CUDA contraction of dense tree networks exists as an experimental path with explicit upload and download; see the CUDA tutorial.
The backend guide explains these layers in detail.
Parallel runs with hataori
Many tensor network studies are embarrassingly parallel at the outer level: a parameter scan, a set of momenta, independent patches. hataori provides map and a dynamically scheduled pmap (in the spirit of Distributed.jl) over serial, Rayon, MPI and hybrid MPI plus threads execution. Its MPI support can load the MPI library at run time, so the same binary can share the MPI installation used by MPI.jl or mpi4py.
hataori owns the processes and threads, and lends them to each task through the same explicit contexts described above, so outer and inner parallelism do not fight over cores. Adapters for tenferro and tensor4all exist in the hataori repository. The synchronous map and pmap are usable today; the asynchronous runtime is still under development.
Maturity and help
- Stable enough to build on: TT and TCI, quantics TCI, quantics operators, tree network contraction and compression. APIs can still change between revisions, so pin one.
- Experimental: tree ACI and RSI, CUDA contraction, the Python bindings.
- Deprecated:
tensor4all-partitionedtt; usetensor4all-partitionedtreetn.
Using a coding agent? Install the tensor4all-rs agent skill, which teaches it the crate map and conventions:
npx skills add tensor4all/tensor4all-rs --skill use-tensor4all-rs -g
A machine oriented index of the documentation is in llms.txt. Questions and bug reports go to the tensor4all-rs issue tracker. If you publish results, please read the citation policy, which asks you to cite the algorithm papers your work relies on.