tnc/_tutorial/
pathfinding_and_contraction.rs

1//! # Pathfinding and Contraction
2//!
3//! ## Pathfinding
4//! To contract a tensor network, we need to specify the order in which the
5//! contractions should appear. This is passed as a list of pairs of tensor indices.
6//! There are different formats / interpretions of contraction paths; this library
7//! uses what we call the "replace left" format:
8//!
9//! | Format       | Action for a single contraction (i, j)                                | Example for 4 tensors                   |
10//! |--------------|-----------------------------------------------------------------------|-----------------------------------------|
11//! | SSA          | Contract tensor i and j, then append resulting tensor at end          | `[(0, 2), (1, 3), (4, 5)]`, result in 6 |
12//! | opt-einsum   | Pop tensors i and j, then contract and append resulting tensor at end | `[(0, 2), (0, 2), (0, 1)]`, result in 0 |
13//! | Replace left | Contract tensor i and j, then replace i by the resulting tensor       | `[(0, 2), (1, 3), (0, 1)]`, result in 0 |
14//!
15//! The rationale behind this format is that it can operate in-place without modifying the size of
16//! the tensors list, hence avoiding moving of elements and reallocations.
17//!
18//! To find contraction paths for a given tensor network, the library offers various contraction
19//! path finders. The best choice is usually to use [`Cotengrust`], which integrates a Rust port of
20//! path finders from the Python library *cotengra*. It has three variants specified by
21//! [`OptMethod`].
22//!
23//! ## Contraction
24//! To contract the tensor network locally, just use [`contract_tensor_network`] and pass in the
25//! tensor network and a contraction path.
26#![allow(unused_imports)]
27use crate::contractionpath::paths::cotengrust::{Cotengrust, OptMethod};
28use crate::tensornetwork::contraction::contract_tensor_network;
29
30pub use crate::_tutorial as table_of_contents;