Skip to main content

contract

Function contract 

Source
pub fn contract<T: SVDScalar + EinsumScalar>(
    mpo_a: &MPO<T>,
    mpo_b: &MPO<T>,
    algorithm: ContractionAlgorithm,
    options: &ContractionOptions,
) -> Result<MPO<T>>
where <T as ComplexFloat>::Real: Into<f64>,
Expand description

Unified contraction function with algorithm dispatch

Contracts two MPOs using the specified algorithm.

§Arguments

  • mpo_a - First MPO
  • mpo_b - Second MPO
  • algorithm - Which algorithm to use
  • options - Contraction options (tolerance, max_bond_dim, etc.)

§Returns

The contracted MPO

§Example

use tensor4all_simplett::mpo::{contract, MPO, ContractionOptions, ContractionAlgorithm};

let mpo_a = MPO::<f64>::identity(&[2, 2]).unwrap();
let mpo_b = MPO::<f64>::identity(&[2, 2]).unwrap();
let options = ContractionOptions::default();

// Use naive algorithm
let result = contract(&mpo_a, &mpo_b, ContractionAlgorithm::Naive, &options).unwrap();
assert_eq!(result.site_dims(), vec![(2, 2), (2, 2)]);

// Use zip-up algorithm for memory efficiency
let result = contract(&mpo_a, &mpo_b, ContractionAlgorithm::ZipUp, &options).unwrap();
assert_eq!(result.len(), 2);

// Use variational fitting for controlled bond dimension
let result = contract(&mpo_a, &mpo_b, ContractionAlgorithm::Fit, &options).unwrap();
assert_eq!(result.len(), 2);