Skip to main content

T3Toolbox

tests docs

A pure-Python (NumPy + optional JAX) library for Tucker tensor trains (T3). A Tucker tensor train is a tensor network which consists of a Tucker decomposition composed with a tensor train decomposition of the central core. When the ranks are moderate, a T3 breaks the curse of dimensionality: storing a dense tensor costs O(N^d) memory, while the T3 representing it costs O(dnr^2 + dnN). Tucker tensor trains are also known as extended tensor trains (ETT).

Tensor network diagram for a Tucker tensor train:

    r0        r1        r2       r(d-1)          rd
1 ------ G0 ------ G1 ------ ... ------ G(d-1) ------ 1
         |         |                    |
         | n0      | n1                 | n(d-1)
         |         |                    |
         B0        B1                   B(d-1)
         |         |                    |
         | N0      | N1                 | N(d-1)
         |         |                    |

Here the Gi (TT cores) and Bi (Tucker cores) are small tensors contracted along the edges to form a large dense N0 x ... x N(d-1) tensor. Unless stated otherwise, operations in this package are defined with respect to the dense tensor that the T3 represents, even though that dense tensor is never formed.

Installation

The package is pure Python. Dependencies: numpy (required), jax (optional).

pip install t3toolbox

To include the optional JAX backend:

pip install "t3toolbox[jax]"

From source (development install):

git clone https://github.com/NickAlger/T3Toolbox.git
cd T3Toolbox
pip install -e .

Quickstart

Create T3s and operate on the tensors they represent (arithmetic is dense-tensor arithmetic — adding two T3s concatenates ranks; T3-SVD reduces back to minimal ranks):

import numpy as np
import t3toolbox as t3t

np.random.seed(0)
x = t3t.TuckerTensorTrain.randn((10, 11, 12), (3, 4, 3), (1, 2, 2, 1))
y = t3t.TuckerTensorTrain.randn((10, 11, 12), (2, 2, 2), (1, 2, 2, 1))

z = x + y
print(z.tucker_ranks, z.tt_ranks)      # (5, 6, 5) (2, 4, 4, 2)   <- ranks add ...
np.linalg.norm(z.to_dense() - (x.to_dense() + y.to_dense()))  # ... tensors add: 0.0

z2, ss_tucker, ss_tt = z.t3svd()       # reduce to minimal ranks (lossless)
print(z2.tucker_ranks, z2.tt_ranks)    # (4, 6, 4) (1, 4, 4, 1)

Sample the represented tensor without forming it (entries / apply / probe, each also available for tangent vectors and with symmetric-derivative generalizations):

ww = [np.random.randn(N) for N in x.shape]
zz = x.probe(ww)                       # d vectors, one per mode (all but one mode contracted)
a  = x.apply(ww)                       # a scalar (all modes contracted)
e  = x.entries(np.array([3, 1, 2]))    # one entry

Fit a fixed-rank T3 to sampled measurements by Riemannian optimization (a zero start on the manifold; unit-norm probe rows keep the least-squares well-conditioned):

A  = t3t.TuckerTensorTrain.randn((6, 7, 8), (2, 2, 2), (1, 2, 2, 1))     # the unknown target
ww = [np.random.randn(120, N) for N in A.shape]
ww = [w / np.linalg.norm(w, axis=1, keepdims=True) for w in ww]          # unit-norm rows
b  = A.apply(ww)                                                         # 120 measurements

x0 = t3t.TuckerTensorTrain.zeros((6, 7, 8), (2, 2, 2), (1, 2, 2, 1))
x_fit, stats = t3t.newton_cg(t3t.MANIFOLD, 'apply', ww, b, x0, max_newton=30)
# relative error of the recovery: < 1e-6

Everything runs on NumPy or JAX — dispatch is inferred from the input array types, frontend objects are jax pytrees (jax.jit applies to them directly), and passing a UniformTuckerTensorTrain start runs the same fitting calls fully packed and jit-compile-once on the uniform layer. See Getting started for the full tour with verified outputs.

Included functionality

  • The T3 format: arithmetic with dense-tensor semantics, orthogonalization, minimal ranks, T3-SVD (truncation / minimal-rank reduction), save/load, batching (stack_shape) on every operation.
  • The three sampling operations — entries, apply, probe — evaluating the represented tensor without forming it, plus their symmetric directional derivatives (jets) and the ambient/corewise/tangent transposes.
  • The fixed-rank T3 manifold: orthogonal frame + gauged variations (T3Frame, T3Variations, T3Tangent), gauge projections, retraction, and two geometries — the Hilbert-Schmidt MANIFOLD and the Euclidean-coordinate COREWISE.
  • Least-squares fitting from any of the sampling operations or their derivatives (Gauss-Newton or exact-Hessian local models) with four optimizers: gradient_descent, mc_sgd, adam, newton_cg — with optional residual weighting, Tikhonov regularization, live Newton-CG diagnostics, and rank continuation. newton_cg(..., hessian='exact') solves each Newton step with the exact Riemannian Hessian under a trust region, for a Newton tail on noisy or unrepresentable targets where Gauss-Newton is only linear.
  • Shared Tucker factors (SF-T3): optimize over T3s whose Tucker factors are constrained equal within user-specified groups of modes — shared(MANIFOLD, sharing) wraps any geometry, and the grouped T3-SVD, rank bookkeeping and continuation follow.
  • Edge weighting: diagonal weights on a T3's internal edges (T3Weights) and on a tangent's coordinates (T3FrameWeights, the Grasedyck-Kramer preconditioner), with absorb into cores.
  • The uniform layer: zero-padded supercores + boolean rank masks mirroring the whole stack — same results, uniform shapes — for jax.lax.scan vectorization, GPU efficiency, and compile-once jit (optimizers included).
  • NumPy / JAX backends with dispatch inferred from the input arrays; frontend classes are registered jax pytrees.
  • Safe mode: numerical preconditions (same tangent space, orthogonal frame, gauged variations, tied factors) checked by default, skippable for speed (t3toolbox.unsafe()); structural problems always error.

Documentation

https://nickalger.github.io/T3Toolbox/ — getting started, user guide, design notes, and the full API reference (frontend and backend — the backend is a first-class, fully documented surface). Worked end-to-end fitting examples live in examples/. Contributing? Start with the Contributor guide.

Authors

MIT License. To cite T3Toolbox, cite the software itself (CITATION.cff). The library grew out of the research in Alger, Christierson, Chen & Ghattas (2026), "Tucker Tensor Train Taylor Series", arXiv:2603.21141, where many of the core algorithms are described — cite that paper when you build on its research contributions.

Metadata

Release files for t3toolbox 2026.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for t3toolbox 2026.3.0
File Size Uploaded Provenance Actions
t3toolbox-2026.3.0.tar.gz 774.6 kB With provenance Details for t3toolbox-2026.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for t3toolbox 2026.3.0
File Interpreter ABI Platform Actions
t3toolbox-2026.3.0-py3-none-any.whl Python 3 none any Details for t3toolbox-2026.3.0-py3-none-any.whl

Total release size: 1.4 MB

Release files / t3toolbox-2026.3.0.tar.gz

Download URL t3toolbox-2026.3.0.tar.gz
Size 774.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6b9cb9db754e9f075926ded8b8fd22c63addeae55d5c141bc27627ae76500c39
BLAKE2b-256 checksum
How to use checksums
eba3948584e32448a4d982cfab85e7f7606b53f2fdd29ab20b244bef6d3a4c6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / t3toolbox-2026.3.0-py3-none-any.whl

Download URL t3toolbox-2026.3.0-py3-none-any.whl
Size 578.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44daa60cc925c8f723fde828b5fb1ddbbb6dcbe9d45b0ab22c8633f15ff27063
BLAKE2b-256 checksum
How to use checksums
931d949167c900ae5f61654d7980f683f568b503f52a8cee8f0a3776b302568c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for t3toolbox 2026.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for t3toolbox-2026.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page