tensor4all_simplett/lib.rs
1#![warn(missing_docs)]
2//! Tensor Train (MPS) library for numerical tensor networks.
3//!
4//! A **tensor train** (TT), also known as a **Matrix Product State** (MPS),
5//! decomposes a high-dimensional tensor into a chain of rank-3 cores:
6//!
7//! ```text
8//! T[i0, i1, ..., iL-1] = A0[i0] * A1[i1] * ... * A_{L-1}[i_{L-1}]
9//! ```
10//!
11//! where each `Ak[ik]` is a matrix of shape `(r_{k-1}, r_k)` and the
12//! bond dimensions `r_k` control the approximation accuracy.
13//!
14//! # Main types
15//!
16//! | Type | Purpose |
17//! |------|---------|
18//! | [`TensorTrain`] | Primary tensor train container |
19//! | [`AbstractTensorTrain`] | Common interface (evaluate, sum, norm) |
20//! | [`CompressionOptions`] | Controls compression accuracy/cost trade-off |
21//! | [`TTCache`] | Caches partial contractions for repeated evaluation |
22//! | [`SiteTensorTrain`] | Center-canonical form for sweeping algorithms |
23//! | [`VidalTensorTrain`] | Vidal canonical form with explicit singular values |
24//! | [`Tensor3`] / [`Tensor3Ops`] | Rank-3 core tensors and their operations |
25//!
26//! # Typical workflow
27//!
28//! ```
29//! use tensor4all_simplett::{TensorTrain, AbstractTensorTrain, CompressionOptions};
30//!
31//! // 1. Create a tensor train (e.g. constant function)
32//! let tt = TensorTrain::<f64>::constant(&[2, 3, 2], 1.0);
33//! assert_eq!(tt.len(), 3);
34//!
35//! // 2. Evaluate at a specific multi-index
36//! let value = tt.evaluate(&[0, 1, 1]).unwrap();
37//! assert!((value - 1.0).abs() < 1e-12);
38//!
39//! // 3. Sum over all indices: 1.0 * 2 * 3 * 2 = 12.0
40//! let sum = tt.sum();
41//! assert!((sum - 12.0).abs() < 1e-10);
42//!
43//! // 4. Compress to reduce bond dimensions
44//! let compressed = tt.compressed(&CompressionOptions::default()).unwrap();
45//! let val2 = compressed.evaluate(&[0, 1, 1]).unwrap();
46//! assert!((val2 - 1.0).abs() < 1e-10);
47//! ```
48
49pub mod arithmetic;
50pub mod cache;
51pub mod canonical;
52pub mod compression;
53pub mod contraction;
54pub(crate) mod einsum_helper;
55pub mod error;
56pub mod mpo;
57pub mod tensor;
58pub mod tensortrain;
59pub mod traits;
60pub mod types;
61pub mod vidal;
62
63// Re-export main types
64pub use cache::TTCache;
65pub use canonical::{center_canonicalize, SiteTensorTrain};
66pub use compression::{CompressionMethod, CompressionOptions};
67pub use contraction::{dot, ContractionOptions};
68pub use error::{Result, TensorTrainError};
69pub use tensortrain::TensorTrain;
70pub use traits::{AbstractTensorTrain, TTScalar};
71pub use types::{tensor3_from_data, tensor3_zeros, LocalIndex, MultiIndex, Tensor3, Tensor3Ops};
72pub use vidal::{DiagMatrix, InverseTensorTrain, VidalTensorTrain};