pytreenet.contractions package

Submodules

pytreenet.contractions.contraction_util module

pytreenet.contractions.state_operator_contraction module

pytreenet.contractions.state_state_contraction module

pytreenet.contractions.tree_cach_dict module

This module provides the PartialTreeCachDict class.

This class is a dictionary that can in general be used to save tensors that depend on two nodes of a tree. The keys are the tuples of the two identifiers. The main use case is to save the contraction results of subtrees during larger contraction operations. For example during the TDVP algorithm or when computing the expecation value of a TTNO with respect to a given TTNS.

class pytreenet.contractions.tree_cach_dict.PartialTreeCachDict(dictionary: Dict[Tuple[str, str]] | None = None)

Bases: dict

A dictionary to save the chached subtrees during contractions.

The main use case is to save the contraction results of subtrees during larger contraction operations. For example during the TDVP algorithm or when computing the expecation value of a TTNO with respect to a given TTNS.

The keys are tuples of size two. The first entry is usually the identifier of a node that acts as the root of a subtree that was contracted. The second identifier is the identifier of the node to which the open legs of the contracted subtree point.

add_entry(node_id: str, next_node_id: str, cached_tensor: ndarray)

Saves a tensor in the dictionary.

Basically a wrapper for the __setitem__ method to ensure the correct order of keys.

Parameters:
  • node_id (str) – The identifier where the subtree ends.

  • next_node_id (str) – The identifier to which the open legs point.

  • cached_tensor (np.ndarray) – The corresponding tensor.

change_next_id_for_entry(node_id: str, old_next_id, new_next_id: str)

Canges the key for a given cached tensor.

For a given cached tensor the identifier to which the open legs of the chached tensor point are changed.

Parameters:
  • node_id (str) – The node to which the entry tensor correpsonds.

  • old_next_id (str) – The old identifier of the node to which the open legs point.

  • new_next_id (str) – The new identifier of the node to which the open legs point.

close_to(other: PartialTreeCachDict) bool

Checks if the other cache is close to this cache.

Parameters:

other (SandwichCache) – The other cache to compare with.

Returns:

True if the other cache is close to this cache.

Return type:

bool

contains(node_id: str, next_node_id: str) bool

Checks if the dictionary contains a given entry.

copy() PartialTreeCachDict

Returns a shallow copy of the dictionary.

Returns:

A shallow copy of the dictionary.

Return type:

PartialTreeCachDict

delete_entry(node_id: str, next_node_id: str)

Deletes an entry in the dictionary.

Basically a wrapper for the __delitem__ method to ensure the correct order of keys.

Parameters:
  • node_id (str) – The identifier where the subtree ends.

  • next_node_id (str) – The identifier to which the open legs point.

get_entry(node_id: str, next_node_id: str) ndarray

Returns the cached tensor saved.

Basically a wrapper for the __getitem__ method to ensure the correct order of keys.

Parameters:
  • node_id (str) – The identifier where the subtree tree ends.

  • next_node_id (str) – The identifier to which the open legs point.

Returns:

The corresponding contracted subtreetree tensor.

Return type:

np.ndarray

num_legs(node_id: str, next_node_id: str) int

Returns the number of legs of the cached tensor.

Parameters:
  • node_id (str) – The identifier where the subtree ends.

  • next_node_id (str) – The identifier to which the open legs point.

Returns:

The number of legs of the cached tensor.

Return type:

int

pytreenet.contractions.tree_contraction module