Quantics and operators
QTT functions and grids, differential and transfer operators, and spin-chain Hamiltonians. Unless stated otherwise, QTT functions use 2^d grid points with site 1 holding the most significant bit.
Quantics tensor trains
Functions on a uniform grid
TensorTrainNumerics.function_to_qtt — Function
function_to_qtt(f, d; a=0.0, b=1.0) -> TTVectorSample the univariate function f on the 2^d uniform grid points of [a, b] (both endpoints included; see function_to_tensor) and compress the samples with tt_decomp. This is the grid used by qtt_polynomial, qtt_sin, and the other closed-form QTT constructors. The dense 2^d samples are formed first, so this is practical only for moderate d; tt_cross avoids that.
TensorTrainNumerics.function_to_qtt_uniform — Function
function_to_qtt_uniform(f, d::Int) -> TTVectorSample f at the periodic grid x_n = n/2^d, n = 0, …, 2^d − 1 (the right endpoint 1 is excluded), and compress the samples with tt_decomp.
Site 1 of the result holds the least significant bit of n, which is the input layout expected by fourier_qtto. The other QTT constructors and qtt_to_vector put the most significant bit first; apply reverse_qtt_bits to convert between the two.
TensorTrainNumerics.function_to_tensor — Function
function_to_tensor(f, d; a=0.0, b=1.0) -> Array{Float64,d}Evaluate f on the 2^d grid points x_j = a + j(b − a)/(2^d − 1), j = 0, …, 2^d − 1, which include both endpoints, and return the values as a 2 × ⋯ × 2 array indexed by the bits of j (most significant first).
TensorTrainNumerics.qtt_to_function — Function
qtt_to_function(qtt::TTVector) -> VectorReturn the 2^d entries of the binary QTT qtt as a vector; identical to qtt_to_vector.
TensorTrainNumerics.qtt_to_vector — Function
qtt_to_vector(qtt::TTVector) -> VectorReturn the 2^d entries of the binary QTT qtt as a vector, with site 1 the most significant bit. The contraction is progressive and never forms the 2 × ⋯ × 2 tensor.
TensorTrainNumerics.tensor_to_grid — Function
tensor_to_grid(tensor) -> VectorFlatten a 2 × ⋯ × 2 array to a vector of length 2^d, reading the array indices as the bits of the position with the first index most significant (the ordering of tuple_to_index).
TensorTrainNumerics.matricize — Function
matricize(qtt::TTVector, core::Int) -> VectorEvaluate a binary (QTT) tensor train on the coarse grid spanned by its first core bits, returning 2^core values in big-endian order (bit 1 is the most significant, matching tuple_to_index). The remaining sites are fixed at physical index 1 (bit value 0). For core == nsites(qtt) this is the full grid vector, identical to qtt_to_vector.
The contraction is progressive — O(d·r²·2^core) — and never materializes the full tensor.
TensorTrainNumerics.qtt_polynomial — Function
Constructs a Quantized Tensor Train (QTT) representation a polynomial with given coefficients over a uniform grid in the interval [a, b] with 2^d points.
TensorTrainNumerics.qtt_sin — Function
Constructs a Quantized Tensor Train (QTT) representation of sin(λπx) over a uniform grid in the interval [a, b] with 2^d points.
TensorTrainNumerics.qtt_cos — Function
Constructs a Quantized Tensor Train (QTT) representation of cos(λπx) over a uniform grid in the interval [a, b] with 2^d points.
TensorTrainNumerics.qtt_exp — Function
Constructs a Quantized Tensor Train (QTT) representation of the exponential function over a uniform grid in the interval [a, b] with 2^d points.
TensorTrainNumerics.qtt_chebyshev — Function
Constructs a Quantized Tensor Train (QTT) representation of the Chebyshev polynomial of degree n over 2^d Chebyshev-Lobatto nodes.
Details
- The function uses the Gauss-Chebyshev-Lobatto nodes, shifted to the interval [0, 1].
TensorTrainNumerics.qtt_basis_vector — Function
qtt_basis_vector(d, pos::Int, val=1.0) -> TTVectorReturn the rank-1 QTT with d sites that is val at the 1-based position pos (site 1 the most significant bit) and zero elsewhere.
TensorTrainNumerics.qtt_trapezoidal_weights — Function
qtt_trapezoidal_weights(d; a=0.0, b=1.0) -> TTVectorReturn the weights of the composite trapezoidal rule on the 2^d uniform grid points of [a, b] (the grid of function_to_qtt) as a QTT: h = (b − a)/(2^d − 1) at interior points and h/2 at both endpoints. Then dot(qtt_trapezoidal_weights(d; a, b), u) approximates ∫ₐᵇ u(x) dx. The weights have TT rank at most 3.
TensorTrainNumerics.gauss_chebyshev_lobatto — Function
gauss_chebyshev_lobatto(n; shifted=true) -> (x, w)Return the n Chebyshev–Lobatto nodes x[j+1] = cos(πj/(n−1)), j = 0, …, n−1 (in decreasing order), and the Gauss–Chebyshev–Lobatto weights for the weight function 1/√(1−x²): π/(n−1), halved at both endpoints. With shifted = true the nodes are mapped from [−1, 1] to [0, 1] and the weights are halved.
TensorTrainNumerics.index_to_point — Function
index_to_point(t; L=1.0) -> Float64Map a tuple of 1-based QTT indices t = (t₁, …, t_d), with t₁ the most significant bit, to the grid point L·j/(2^d − 1) in [0, L], where j = Σₖ 2^(d−k)(tₖ − 1).
TensorTrainNumerics.tuple_to_index — Function
tuple_to_index(t) -> IntMap a tuple of 1-based QTT indices t = (t₁, …, t_d), with t₁ the most significant bit, to the 1-based linear index 1 + Σₖ 2^(d−k)(tₖ − 1).
TensorTrainNumerics.reverse_qtt_bits — Function
reverse_qtt_bits(x::TTVector) -> TTVectorReverse the order of the sites of x. For a binary QTT this reverses the bit order of the position index, converting between most-significant-bit-first and least-significant-bit-first layouts.
Multidimensional QTT
TensorTrainNumerics.function_to_qttv — Function
function_to_qttv(f, n_dims, bits_per_dim; ordering=:interleaved, a=0.0, b=1.0)Evaluate an n_dims-dimensional function f on a uniform grid with 2^bits_per_dim points per dimension and return a QTTVector. f receives an n_dims-length coordinate vector.
Grid points: a + i * (b - a) / (2^bits_per_dim - 1) for i = 0, ..., 2^bits_per_dim - 1.
TensorTrainNumerics.qttv_to_array — Function
qttv_to_array(q::QTTVector)Contract the TT chain and return an n_dims-dimensional array of size 2^bits_per_dim per dimension, with values ordered on the uniform grid (index 1 = leftmost grid point).
TensorTrainNumerics.to_qtt — Function
to_qtt(tt, split_dims; threshold=0.0)Convert a TTVector to QTT format by splitting each core's physical dimension via SVD.
split_dims[i] is a list of integers whose product equals tt.dims[i], specifying how to factor that core. The first entry is the coarsest (most significant) dimension, consistent with the rest of the package's QTT convention.
An optional threshold (relative to the largest singular value) controls rank truncation.
TensorTrainNumerics.to_ttv — Function
to_ttv(qtt, merge_numbers)Convert a QTT (or any TTVector) back to TT format by contracting consecutive cores.
merge_numbers[i] is the number of consecutive QTT cores to merge into TT core i. sum(merge_numbers) must equal the total number of QTT cores.
Physical dimensions are merged using the same BIG-ENDIAN convention as to_qtt: the earlier (coarser) core provides the more significant bits.
TensorTrainNumerics.reorder — Function
reorder(q::QTTVector, new_ordering::Symbol; threshold=0.0)Convert a QTTVector between :interleaved and :serial orderings by performing a sequence of adjacent site swaps (sorting-network style, via bubble sort).
Each adjacent swap contracts two neighboring cores, permutes their physical indices, and re-factorizes via SVD. The optional threshold (relative to the largest singular value) controls rank truncation during each SVD step.
Returns a new QTTVector with ordering == new_ordering.
reorder(A::QTTOperator, new_ordering::Symbol; threshold=0.0)Convert a QTTOperator between :interleaved and :serial orderings by performing a sequence of adjacent site swaps (sorting-network style, via bubble sort).
Returns a new QTTOperator with ordering == new_ordering.
TensorTrainNumerics.check_compat — Function
check_compat(a::QTTVector, b::QTTVector)Verify that two QTTVectors have compatible QTT metadata (ndims, bitsper_dim, ordering).
Throws AssertionError if incompatible.
check_compat(A::QTTOperator, ψ::QTTVector)Verify that a QTTOperator and QTTVector have compatible QTT metadata.
Throws AssertionError if incompatible.
check_compat(::TTVector, ::TTVector)No-op for plain TTVectors (always compatible).
check_compat(::TTOperator, ::TTVector)No-op for plain TTOperator/TTVector pairs (always compatible).
Differential and transfer operators
TensorTrainNumerics.toeplitz_to_qtto — Function
Constructs a tensor train operator (TTO) representation of a Toeplitz matrix parameterized by α, β, and γ over d dimensions.
TensorTrainNumerics.shift — Function
Constructs a tensor train operator (TTO) representation of the shift matrix
TensorTrainNumerics.∇ — Function
Constructs a tensor train operator (TTO) representation of the gradient matrix
TensorTrainNumerics.Δ — Function
Δ(d; bc=:DD) -> TTOperatorSecond-difference (negative Laplacian) operator on a grid of 2^d points in QTT format, without the 1/h² scaling.
bc selects the boundary conditions at the left and right end of the grid: :DD (Dirichlet–Dirichlet), :DN (Dirichlet–Neumann), :ND (Neumann–Dirichlet), :NN (Neumann–Neumann), or :periodic. All except :DD require d ≥ 4.
TensorTrainNumerics.Δ⁻¹ — Function
Δ⁻¹(d; bc=:DN) -> TTOperatorInverse of Δ in QTT format. Only bc = :DN (Dirichlet–Neumann) is available.
TensorTrainNumerics.qtt_laplacian — Function
qtt_laplacian(n_dims, bits_per_dim; ordering=:interleaved, a=0.0, b=1.0, bc=:DN)Build the n_dims-dimensional Laplacian operator in QTT format as the Kronecker sum of 1D second-derivative operators:
Δ_nd = Δ₁⊗I⊗…⊗I + I⊗Δ₂⊗I⊗…⊗I + … + I⊗…⊗I⊗ΔₙEach 1D operator acts on bits_per_dim sites, a uniform grid of N = 2^bits_per_dim points. The finite-difference scaling 1/h² is included. The grid contains both endpoints of [a, b], so h = (b - a) / (N - 1), except for bc = :periodic, where it covers one period [a, b) without repeating the endpoint and h = (b - a) / N.
Arguments
n_dims::Int: Number of spatial dimensions (≥ 1).bits_per_dim::Int: Number of QTT bits per dimension.
Keyword arguments
ordering::Symbol::serial(sites grouped by dimension) or:interleaved(sites interleaved across dimensions). Default::interleaved.a::Real,b::Real: Interval endpoints. Default:[0, 1].bc::Symbol: Boundary conditions of each 1D operator, as inΔ::DD,:DN,:ND,:NN, or:periodic. Default::DN.
Returns
A QTTOperator with N = n_dims * bits_per_dim sites.
TensorTrainNumerics.qtto_prolongation — Function
Constructs a tensor train operator (TTO) representation of the prolongation operator for multigrid methods
TensorTrainNumerics.qtto_constant_prolongation — Function
Constructs a constant QTT prolongation operator from d to d + 1 binary sites.
TensorTrainNumerics.qtto_linear_prolongation — Function
Constructs a linear QTT prolongation operator from d to d + 1 binary sites.
TensorTrainNumerics.qtto_to_matrix — Function
Converts a quantics tensor train operator (TTOperator) into its full matrix representation.
TensorTrainNumerics.fourier_qtto — Function
fourier_qtto(d; sign=-1.0, K=25, normalize=true) -> TTOperator{ComplexF64}Discrete Fourier transform on 2^d points as a QTT operator, built with the interpolative construction of Chen and Lindsey (arXiv:2404.03182):
y_k = s · Σₙ x_n exp(sign · 2πi · k n / 2^d), s = 2^(−d/2) if `normalize`, else 1.The operator reverses the bit order: the input must have its least significant bit of n on site 1 (as produced by function_to_qtt_uniform), and the output has the most significant bit of k on site 1 (as read by qtt_to_vector and matricize). Every interior bond has rank K + 1; larger K gives a more accurate transform.
Spin-chain operators
TensorTrainNumerics.pauli_matrix — Function
pauli_matrix(μ)Return the Pauli matrix for axis μ, where μ is :x, :y, or :z.
TensorTrainNumerics.pauli_sum_tto — Function
pauli_sum_tto(μ, d)Construct the rank-2 TT operator
H_μ = sum_i I ⊗ ... ⊗ P_μ ⊗ ... ⊗ Ion d spin-1/2 sites with open boundaries.
TensorTrainNumerics.pauli_pair_sum_tto — Function
pauli_pair_sum_tto(μ, ν, d)Construct the rank-3 nearest-neighbor TT operator
H_{μ,ν} = sum_i I ⊗ ... ⊗ P_μ ⊗ P_ν ⊗ ... ⊗ Ion d spin-1/2 sites with open boundaries.
TensorTrainNumerics.H_μ — Function
H_μ(μ, d)Alias for pauli_sum_tto(μ, d).
TensorTrainNumerics.H_μν — Function
H_μν(μ, ν, d)Alias for pauli_pair_sum_tto(μ, ν, d).
TensorTrainNumerics.heisenberg_xyz_tto — Function
heisenberg_xyz_tto(d; jx=1.0, jy=1.0, jz=1.0, λ=0.0, field=:x)Construct the open-boundary Heisenberg XYZ Hamiltonian
H = jx H_{x,x} + jy H_{y,y} + jz H_{z,z} + λ H_fieldas a direct low-rank TT operator on d spin-1/2 sites.
TensorTrainNumerics.ising_tto — Function
ising_tto(d; J=1.0, h=0.0, interaction=:z, field=:x)Construct the open-boundary Ising Hamiltonian
H = J H_{interaction,interaction} + h H_fieldon d spin-1/2 sites. Coefficients are used with their given sign.
TensorTrainNumerics.xxz_tto — Function
xxz_tto(d; J=1.0, Δ=1.0, h=0.0, field=:z)Construct the open-boundary XXZ Hamiltonian
H = J(H_{x,x} + H_{y,y}) + JΔ H_{z,z} + h H_field.TensorTrainNumerics.xxx_tto — Function
xxx_tto(d; J=1.0, h=0.0, field=:z)Construct the open-boundary isotropic Heisenberg XXX Hamiltonian
H = J(H_{x,x} + H_{y,y} + H_{z,z}) + h H_field.TensorTrainNumerics.xy_tto — Function
xy_tto(d; jx=1.0, jy=1.0, h=0.0, field=:z)Construct the open-boundary XY Hamiltonian
H = jx H_{x,x} + jy H_{y,y} + h H_field.