Skip to main content

Tensor Train linear algebra package for efficient high-dimensional tensor operations

Project description

CI PyPI Python License Docs

TTGlow

Tensor Train linear algebra built on PyTorch for efficient high-dimensional tensor operations.

Overview

TTGlow provides an efficient implementation of the Tensor Train (TT) decomposition, a powerful technique for representing and manipulating high-dimensional tensors with reduced memory footprint and computational cost. This package is particularly useful for:

  • High-dimensional data analysis
  • Quantum many-body physics simulations
  • Machine learning with tensor methods
  • Efficient storage and computation of large-scale tensors

Installation

Using pip (Recommended)

pip install ttglow

From source (for development)

# Clone the repository
git clone https://github.com/romanellerbrock/ttglow.git
cd ttglow

# Install with pixi
pixi install
pixi shell

# Or install with pip
pip install -e .

Quick Start

import torch
from ttglow import TensorTrain

# Convert a dense tensor to TT format
dense = torch.randn(8, 8, 8, 8, dtype=torch.float64)
tt = TensorTrain.from_dense(dense, max_rank=4)  # Compress with rank truncation

print(f"Original: {dense.numel():,} elements")
print(f"Compressed: {tt.ttnumel:,} elements ({tt.ttnumel/dense.numel():.1%})")

# Arithmetic with operator overloading
tt2 = TensorTrain.random([8, 8, 8, 8], ranks=[4, 4, 4])
result = tt + tt2       # Addition
result = tt * tt2       # Hadamard (elementwise) product
result = 2.5 * tt       # Scalar multiplication
inner = tt @ tt2        # Inner product

# Shape operations (PyTorch-like API)
tt_reshaped = tt.reshape([64, 64])
tt_transposed = tt.transpose(0, 2)
tt_flat = tt.flatten(1, 3)

# Convert back to dense
reconstructed = tt.to_tensor()

Features

  • Efficient TT representation: Store high-dimensional tensors with minimal memory
  • Core operations: dot, hadamard, add, scale
  • Shape operations: reshape, transpose, permute, squeeze, unsqueeze, flatten, cat, stack
  • Decomposition: from_dense (TT-SVD with optional rank truncation), svd, qr
  • TT-Matrix support: Matrix-vector products, operator composition, kron, kronadd
  • PyTorch-like API: .to(), .clone(), .detach(), familiar tensor interface
  • PyTorch backend: Full GPU support and automatic differentiation

Development

Running Tests

pixi run test

Code Formatting

pixi run format

Linting

pixi run lint

Test Coverage

pixi run test-cov

Project Structure

ttglow/
├── src/ttglow/           # Main package code
│   ├── __init__.py
│   ├── tensortrain.py    # TensorTrain class and operations
│   ├── ttmatrix.py       # TT-Matrix (MPO) support
│   └── linalg.py         # Linear algebra (SVD, QR, norms)
├── tests/                # Test suite
├── examples/             # Usage examples
├── docs/                 # Documentation website
└── pyproject.toml        # Package configuration

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

References

  • Oseledets, I. V. (2011). "Tensor-train decomposition". SIAM J. Sci. Comput., 33(5), 2295-2317.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttglow-0.1.3.tar.gz (94.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ttglow-0.1.3-py3-none-any.whl (63.1 kB view details)

Uploaded Python 3

File details

Details for the file ttglow-0.1.3.tar.gz.

File metadata

  • Download URL: ttglow-0.1.3.tar.gz
  • Upload date:
  • Size: 94.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ttglow-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b76cbbfb14d45723687bf88a67ced29bfd3fd937920c9c9e19c08dd87afd8295
MD5 d0561a0deb0d81e42f2d2e37cf335ea9
BLAKE2b-256 72ef79cb8448cd3bde95da8b55730a195f66a8ec6cf75718f4ca6319e6ab5752

See more details on using hashes here.

Provenance

The following attestation bundles were made for ttglow-0.1.3.tar.gz:

Publisher: publish.yml on roman-ellerbrock/ttglow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ttglow-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ttglow-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 63.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ttglow-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ae502d63c90867027bcb44c9e4fe581c6458239ce5daddb39cf4963dc7adcbe4
MD5 1396dd0b294b7db6371fba1479670717
BLAKE2b-256 6cc26c2e5d41898380443d281665b92401b365aab9afce9f69f8e134feed938e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ttglow-0.1.3-py3-none-any.whl:

Publisher: publish.yml on roman-ellerbrock/ttglow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page