Skip to main content

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

Project description

TTGlow Logo

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.2.tar.gz (68.6 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.2-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ttglow-0.1.2.tar.gz
  • Upload date:
  • Size: 68.6 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.2.tar.gz
Algorithm Hash digest
SHA256 73a500181df8f72fc889051f8eae9317d1544ebab595a15798df39874a665eff
MD5 090c20fa378e5f9f0beff03412bad455
BLAKE2b-256 7bbb96f3a65fb577a003036f8ae4474777b90d07fe4716ca335a69cc5058acc7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ttglow-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: ttglow-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 44.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a42d0973e3d8ed2007431bdfb69b33438b610135811ae89f0c80983e4c96f012
MD5 5f6c2b9bc801220a332f4ba8f80baf81
BLAKE2b-256 2d73c7168b08e1a4dd672bbfefaca221522c91000b4d520f92992f8b226c28ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for ttglow-0.1.2-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