pub trait LocalUpdater<T, V>{
// Required method
fn update(
&mut self,
subtree: TreeTN<T, V>,
step: &LocalUpdateStep<V>,
full_treetn: &TreeTN<T, V>,
) -> Result<TreeTN<T, V>>;
// Provided methods
fn before_step(
&mut self,
_step: &LocalUpdateStep<V>,
_full_treetn_before: &TreeTN<T, V>,
) -> Result<()> { ... }
fn after_step(
&mut self,
_step: &LocalUpdateStep<V>,
_full_treetn_after: &TreeTN<T, V>,
) -> Result<()> { ... }
}Expand description
Trait for local update operations during a sweep.
Implementors of this trait provide the actual update logic that transforms a local subtree into an updated version. This allows different algorithms (truncation, fitting, DMRG, TDVP) to share the same sweep infrastructure.
§Type Parameters
T: Tensor type implementing TensorLikeV: Node name type
§Workflow
During apply_local_update_sweep:
- For each step in the sweep plan:
a. Extract the subtree containing
step.nodesb. Callupdate()with the extracted subtree and step info c. Replace the subtree in the original TreeTN with the updated one d. Update the canonical center tostep.new_center
Required Methods§
Sourcefn 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.
§Arguments
subtree- The extracted subtree to updatestep- The current step information (nodes and new_center)full_treetn- Reference to the full (global) TreeTN. This provides global context (e.g., topology, neighbor relations, and index/bond metadata) that some update algorithms may need. It may be unused by simple updaters.
§Returns
The updated subtree, which must have the same “appearance” as the input (same nodes, same external indices, same ortho_towards structure).
§Errors
Returns an error if the update fails (e.g., SVD doesn’t converge).
Provided Methods§
Sourcefn 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.
This is called with the full TreeTN state before the update is applied. Implementors can use it to validate assumptions or prefetch/update caches.
Sourcefn 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.
This is called after:
- The updated subtree has been inserted back into the full TreeTN
- The canonical center has been moved to
step.new_center
Implementors can use this to update caches that must see the post-update state.