TensorTrainNumerics.jl is a Julia package for numerical methods in tensor train (TT) and quantics tensor train (QTT) format. It provides iterative solvers for high-dimensional linear systems and eigenvalue problems, time-stepping and TDVP methods for evolution equations, and TT-cross algorithms for black-box function approximation — all operating on compressed tensor representations that scale linearly in the number of dimensions rather than exponentially.
- Solvers — ALS, MALS, and DMRG for linear systems and eigenvalue problems; adaptive rank control via SVD truncation
- Time evolution — single- and two-site TDVP, implicit Euler, Crank–Nicolson, and Krylov exponential integrators
- TT-cross — MaxVol, DMRG-cross, and Greedy algorithms for black-box function approximation and numerical integration
- QTT operators — exact low-rank representations of Laplacians, gradient operators, shift matrices, and the discrete Fourier transform
- Quantics tensor trains — serial and interleaved multi-dimensional encodings with
QTTvector/QTToperatorwrappers - Interoperability — compatible with KrylovKit.jl and OptimKit.jl via VectorInterface.jl
using Pkg
Pkg.add("TensorTrainNumerics")using LinearAlgebra
using TensorTrainNumerics
tensor = reshape(collect(1.0:16.0), 2, 2, 2, 2)
tt = ttv_decomp(tensor; tol = 1.0e-12)
tensor_reconstructed = ttv_to_tensor(tt)
relerr = norm(tensor - tensor_reconstructed) / norm(tensor)
println("Relative error: ", relerr)Relative error: 4.447195710046155e-16using LinearAlgebra
using TensorTrainNumerics
f(X) = vec(exp.(-sum(X .^ 2, dims = 2)))
domain = [collect(range(-1.0, 1.0, length = 8)) for _ in 1:4]
tt = tt_cross(f, domain, MaxVol(verbose = false, tol = 1.0e-8); ranks = 2)
approx = ttv_to_tensor(tt)
exact = similar(approx)
for I in CartesianIndices(exact)
x = reshape([domain[k][I[k]] for k in 1:4], 1, :)
exact[I] = f(x)[1]
end
relerr = norm(approx - exact) / norm(exact)
println(tt)
println("Relative error: ", relerr)Relative error: 2.661496213238571e-16using LinearAlgebra
using TensorTrainNumerics
d = 6
A = id_tto(d)
b = qtt_sin(d, λ = π)
x0 = rand_tt(b.ttv_dims, b.ttv_rks)
x = als_linsolve(A, b, x0; sweep_count = 4)
rhs = qtt_to_function(b)
sol = qtt_to_function(x)
relerr = norm(sol - rhs) / norm(rhs)
println("Relative error: ", relerr)Relative error: 4.560872651853784e-16For more examples including 2D PDEs, time evolution, and the QTT Fourier transform, see the documentation.