pub struct TruncateUpdater {
pub max_rank: Option<usize>,
pub svd_policy: Option<SvdTruncationPolicy>,
}Expand description
Truncation updater for nsite=2 sweeps.
This updater performs SVD-based truncation on two-site subtrees, compressing bond dimensions while preserving the tensor train structure.
§Algorithm
For each step with nodes [A, B] where B is the new center:
- Contract tensors A and B into a single tensor AB
- Factorize AB using SVD with truncation (left indices = A’s external + bond to A’s other neighbors)
- The left tensor becomes the new A, the right tensor becomes the new B
- B is the orthogonality center (isometry pointing towards B)
§Usage
use tensor4all_core::{DynIndex, TensorDynLen};
use tensor4all_treetn::{apply_local_update_sweep, LocalUpdateSweepPlan, TreeTN, TruncateUpdater};
let s0 = DynIndex::new_dyn(2);
let bond = DynIndex::new_dyn(1);
let s1 = DynIndex::new_dyn(2);
let t0 = TensorDynLen::from_dense(vec![s0, bond.clone()], vec![1.0, 0.0])?;
let t1 = TensorDynLen::from_dense(vec![bond, s1], vec![1.0, 0.0])?;
let mut treetn = TreeTN::<TensorDynLen, usize>::from_tensors(vec![t0, t1], vec![0, 1])?;
treetn.canonicalize_mut(std::iter::once(0usize), Default::default())?;
let plan = LocalUpdateSweepPlan::from_treetn(&treetn, &0usize, 2).unwrap();
let mut updater = TruncateUpdater::new(
Some(4),
Some(tensor4all_core::SvdTruncationPolicy::new(1e-10)),
);
apply_local_update_sweep(&mut treetn, &plan, &mut updater)?;
assert_eq!(treetn.node_count(), 2);Fields§
§max_rank: Option<usize>Maximum bond dimension after truncation.
svd_policy: Option<SvdTruncationPolicy>Explicit SVD truncation policy.
Implementations§
Trait Implementations§
Source§impl Clone for TruncateUpdater
impl Clone for TruncateUpdater
Source§fn clone(&self) -> TruncateUpdater
fn clone(&self) -> TruncateUpdater
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TruncateUpdater
impl Debug for TruncateUpdater
Source§impl<T, V> LocalUpdater<T, V> for TruncateUpdater
impl<T, V> LocalUpdater<T, V> for TruncateUpdater
Source§fn update(
&mut self,
subtree: TreeTN<T, V>,
step: &LocalUpdateStep<V>,
_full_treetn: &TreeTN<T, V>,
) -> Result<TreeTN<T, V>>
fn update( &mut self, subtree: TreeTN<T, V>, step: &LocalUpdateStep<V>, _full_treetn: &TreeTN<T, V>, ) -> Result<TreeTN<T, V>>
Update a local subtree. Read more
Source§fn before_step(
&mut self,
_step: &LocalUpdateStep<V>,
_full_treetn_before: &TreeTN<T, V>,
) -> Result<()>
fn before_step( &mut self, _step: &LocalUpdateStep<V>, _full_treetn_before: &TreeTN<T, V>, ) -> Result<()>
Optional hook called before performing an update step. Read more
Source§fn after_step(
&mut self,
_step: &LocalUpdateStep<V>,
_full_treetn_after: &TreeTN<T, V>,
) -> Result<()>
fn after_step( &mut self, _step: &LocalUpdateStep<V>, _full_treetn_after: &TreeTN<T, V>, ) -> Result<()>
Optional hook called after an update step has been applied to the full TreeTN. Read more
Auto Trait Implementations§
impl Freeze for TruncateUpdater
impl RefUnwindSafe for TruncateUpdater
impl Send for TruncateUpdater
impl Sync for TruncateUpdater
impl Unpin for TruncateUpdater
impl UnsafeUnpin for TruncateUpdater
impl UnwindSafe for TruncateUpdater
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
Casts
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more