Skip to main content

tensor4all_treetn/
lib.rs

1//! Tree Tensor Network (TreeTN) library for tensor4all.
2//!
3//! This crate provides data structures and algorithms for working with tree tensor networks,
4//! a generalization of matrix product states (MPS) to tree-shaped graphs. Tree tensor networks
5//! are useful for representing quantum states and operators on systems with tree-like connectivity.
6//!
7//! # Key Types
8//!
9//! - [`TreeTN`]: The main tree tensor network type, parameterized by tensor and node name types.
10//! - [`DefaultTreeTN`]: A convenient alias for `TreeTN<TensorDynLen, NodeIndex>`.
11//! - [`NamedGraph`]: A graph wrapper that maps node names to internal graph indices.
12//!
13//! # Features
14//!
15//! - **Canonicalization**: Transform networks into canonical forms (unitary, LU, CI).
16//! - **Truncation**: Compress networks using SVD-based truncation.
17//! - **Contraction**: Contract two networks using zip-up or fit algorithms.
18//! - **Linear operators**: Apply and compose linear operators on tree tensor networks.
19//! - **Linear solvers**: Solve linear systems involving tree tensor network operators.
20
21#![warn(missing_docs)]
22pub mod algorithm;
23// dyn_treetn.rs has been removed.
24// TreeTN uses the `T: TensorLike` pattern, making a separate dyn wrapper unnecessary.
25pub mod link_index_network;
26pub mod linsolve;
27pub mod named_graph;
28pub mod node_name_network;
29pub mod operator;
30pub mod options;
31pub mod random;
32mod simplett_bridge;
33pub mod site_index_network;
34pub mod treetn;
35
36pub use algorithm::{CanonicalForm, CompressionAlgorithm, ContractionAlgorithm};
37pub use treetn::contraction;
38
39// dyn_treetn exports removed - use TreeTN<TensorDynLen, V> directly
40pub use link_index_network::LinkIndexNetwork;
41pub use named_graph::NamedGraph;
42pub use node_name_network::{CanonicalizeEdges, NodeNameNetwork};
43pub use operator::{
44    apply_linear_operator, are_exclusive_operators, build_identity_operator_tensor,
45    compose_exclusive_linear_operators, ApplyOptions, ArcLinearOperator, IndexMapping,
46    LinearOperator, Operator,
47};
48pub use options::{CanonicalizationOptions, RestructureOptions, SplitOptions, TruncationOptions};
49pub use random::{random_treetn, LinkSpace};
50pub use simplett_bridge::{
51    tensor_train_to_treetn, tensor_train_to_treetn_with_names,
52    tensor_train_to_treetn_with_names_and_site_indices,
53};
54pub use site_index_network::SiteIndexNetwork;
55pub use treetn::{
56    // Local update
57    apply_local_update_sweep,
58    // Decomposition
59    factorize_tensor_to_treetn,
60    factorize_tensor_to_treetn_with,
61    get_boundary_edges,
62    partial_contract,
63    BoundaryEdge,
64    LocalUpdateStep,
65    LocalUpdateSweepPlan,
66    LocalUpdater,
67    PartialContractionSpec,
68    // Swap
69    ScheduledSwapStep,
70    SwapOptions,
71    SwapSchedule,
72    // Core type
73    TreeTN,
74    TreeTopology,
75    TruncateUpdater,
76};
77
78// Re-export linsolve types from new location
79pub use linsolve::{
80    square_linsolve, EnvironmentCache, LinsolveOptions, LinsolveVerifyReport, NetworkTopology,
81    NodeVerifyDetail, ProjectedOperator, ProjectedState, SquareLinsolveResult,
82    SquareLinsolveUpdater,
83};
84
85use petgraph::graph::NodeIndex;
86use tensor4all_core::TensorDynLen;
87
88/// Default TreeTN type using TensorDynLen as the tensor type.
89///
90/// This is the most common configuration for TreeTN, equivalent to:
91/// ```
92/// use tensor4all_treetn::DefaultTreeTN;
93///
94/// let tree: DefaultTreeTN = DefaultTreeTN::new();
95/// assert_eq!(tree.node_count(), 0);
96/// ```
97///
98/// Use this when you don't need custom tensor types.
99pub type DefaultTreeTN<V = NodeIndex> = TreeTN<TensorDynLen, V>;