Skip to main content

random_treetn

Function random_treetn 

Source
pub fn random_treetn<T, R, V>(
    rng: &mut R,
    site_network: &SiteIndexNetwork<V, DefaultIndex>,
    link_space: LinkSpace<V>,
) -> TreeTN<TensorDynLen, V>
where T: RandomScalar, R: Rng, V: Clone + Hash + Eq + Ord + Send + Sync + Debug,
Expand description

Create a random TreeTN from a site index network (generic over scalar type).

Generates random tensors at each node with:

  • Site indices from the site_network
  • Link indices created according to link_space

§Type Parameters

  • T - Scalar type (e.g. f64 or Complex64)
  • R - RNG type
  • V - Node name type

§Arguments

  • rng - Random number generator for tensor data
  • site_network - Network topology and site (physical) indices
  • link_space - Specification for bond dimensions

§Example

use tensor4all_treetn::{SiteIndexNetwork, random_treetn, LinkSpace};
use tensor4all_core::index::{Index, DynId, TagSet};
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use std::collections::HashSet;

// Create a simple 2-node network
let mut site_network = SiteIndexNetwork::<String, Index<DynId, TagSet>>::new();
let i = Index::new_dyn(2);
let j = Index::new_dyn(3);
site_network.add_node("A".to_string(), HashSet::from([i.clone()])).unwrap();
site_network.add_node("B".to_string(), HashSet::from([j.clone()])).unwrap();
site_network.add_edge(&"A".to_string(), &"B".to_string()).unwrap();

let mut rng = ChaCha8Rng::seed_from_u64(42);
let treetn = random_treetn::<f64, _, _>(&mut rng, &site_network, LinkSpace::uniform(4));

assert_eq!(treetn.node_count(), 2);