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 [1], and DMRG for linear systems [2], non-linear (multigrid) [3] and eigenvalue problems; adaptive rank control via SVD truncation [4]
- Time evolution — single- and two-site TDVP [5], implicit Euler, Crank–Nicolson, and Krylov exponential integrators
- TT-cross — MaxVol [6], DMRG-cross [7], and Greedy algorithms [8] for black-box function approximation and numerical integration [9]
- QTT operators — exact low-rank representations of Laplacians, gradient operators [10], shift matrices, and the discrete Fourier transform [11]
- 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 = linear_solve(A, b, x0, ALS(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.
[1] S. Holtz, T. Rohwedder, R. Schneider, "The Alternating Linear Scheme for Tensor Optimization in the Tensor Train Format", SIAM Journal on Scientific Computing 34 (2) (2012)
[2] Oseledets, Ivan V., and Sergey V. Dolgov. "Solution of linear systems and matrix inversion in the TT-format." SIAM Journal on Scientific Computing 34.5 (2012): A2718-A2739.
[3] Lubasch, Michael, Pierre Moinier, and Dieter Jaksch. "Multigrid renormalization." Journal of Computational Physics 372 (2018): 587-602.
[4] Oseledets, Ivan V. "Tensor-train decomposition." SIAM Journal on Scientific Computing 33.5 (2011): 2295-2317.
[5] Haegeman, Jutho, et al. "Unifying time evolution and optimization with matrix product states." Physical Review B 94.16 (2016): 165116.
[6] I. Oseledets, E. Tyrtyshnikov, "TT-cross approximation for multidimensional arrays", Linear Algebra and its Applications 432 (1) (2010)
[7] Savostyanov, Dmitry, and Ivan Oseledets. "Fast adaptive interpolation of multi-dimensional arrays in tensor train format." The 2011 International Workshop on Multidimensional (nD) Systems. IEEE, 2011.
[8] Savostyanov, Dmitry V. "Quasioptimality of maximum-volume cross interpolation of tensors." Linear Algebra and its Applications 458 (2014): 217-244.
[9] Vysotsky, Lev I., Alexander V. Smirnov, and Eugene E. Tyrtyshnikov. "Tensor-train numerical integration of multivariate functions with singularities." Lobachevskii Journal of Mathematics 42.7 (2021): 1608-1621.
[10] Kazeev, Vladimir A., and Boris N. Khoromskij. "Low-rank explicit QTT representation of the Laplace operator and its inverse." SIAM journal on matrix analysis and applications 33.3 (2012): 742-758.
[11] Chen, Jielun, and Michael Lindsey. "Direct interpolative construction of the discrete Fourier transform as a matrix product operator." Applied and Computational Harmonic Analysis (2025): 101817.