pytreenet.special_ttn package¶
This module encodes subsets of TTN with more closely defined structure.
Submodules¶
pytreenet.special_ttn.fttn module¶
Provides the fork tree topology TTN.
A fork tree tensor network (FTTN) has the shape of a fork or comb. It consists of a main chain of tensor nodes and to each a subchain is attached. For example:
M0 -- S00 -- S01 -- S03
|
M1 -- S10 -- S11
|
M2 -- S20 -- S21
|
M3
Also contains the subclasses that combine the FTTN structure with the properties of a TTNS or TTNO.
- class pytreenet.special_ttn.fttn.ForkTreeProductOperator(main_identifier_prefix: str = 'main', subchain_identifier_prefix: str = 'sub')¶
Bases:
ForkTreeTensorNetwork,TreeTensorNetworkOperatorA fork tree tensor network operator.
A fork tree tensor network operator is a tensor network operator that has the structure of a fork tree tensor network. It consists of a main chain of tensor nodes and to each a subchain is attached. For example:
M0 -- S00 -- S01 -- S03 | M1 -- S10 -- S11 | M2 -- S20 -- S21 | M3
Every node has two open legs, that may be trivial.
- class pytreenet.special_ttn.fttn.ForkTreeProductState(main_identifier_prefix: str = 'main', subchain_identifier_prefix: str = 'sub')¶
Bases:
ForkTreeTensorNetwork,TreeTensorNetworkStateA fork tree tensor network state.
A fork tree tensor network state is a tensor network state that has the structure of a fork tree tensor network. It consists of a main chain of tensor nodes and to each a subchain is attached. For example:
M0 -- S00 -- S01 -- S03 | M1 -- S10 -- S11 | M2 -- S20 -- S21 | M3
Every node has one open leg, that may be trivial.
- class pytreenet.special_ttn.fttn.ForkTreeTensorNetwork(main_identifier_prefix: str = 'main', subchain_identifier_prefix: str = 'sub')¶
Bases:
TreeTensorNetwork- An FTTN is a tree tensor network that consists of a main chain
and subchains attached to each of the nodes in the main chain. Thus they look like a fork/comb:
M0 – S00 – S01 – S03 | M1 – S10 – S11 | M2 – S20 – S21 | M3
- main_identifier_prefix¶
A prefix set for all identifiers of nodes in the main chain. The identifiers will be prefix + position and used to automatically add nodes to the chain.
- Type:
str
- subchain_identifier_prefix¶
A prefix set for all identifiers of nodes in a sub chain. The identifiers will be
prefix + mainchainposition + _ + subchainposition
and used to automatically add nodes to the chain.
- Type:
str
- main_chain¶
A list of nodes in the main chain. The nodes are ordered according to the order in which they were added thus defining the order of the main chain.
- Type:
List[ndarray]
- sub_chains¶
A list of lists of nodes. Each list corresponds to a subchain attached to a node in the main chain. The nodes are ordered according to the order in which they were added thus defining the order of the subchain.
- Type:
List[List[ndarray]]
- add_main_chain_node(tensor: ndarray, parent_leg: None | int = None)¶
Add a new node to the main chain.
The identifier will be created automatically.
- Parameters:
tensor (np.ndarray) – The tensor that is to be associated to the new node.
parent_leg (Union[None, int], optional) – If there is already a node in the chain, the leg that should be attached to the new node can be specified. Otherwise it defaults to the first open leg.
- add_sub_chain_node(tensor: ndarray, subchain_index: int, parent_leg: None | int = None)¶
Add a new node to a given subchain.
The identifier will be created automatically.
- Parameters:
tensor (np.ndarray) – The tensor that is to be associated to the new node.
subchain_index (int) – The index of the subchain to which the new node is to be added.
parent_leg (Union[None, int], optional) – If there is already a node in the chain, the leg that should be attached to the new node can be specified. Otherwise it defaults to the first open leg of the to be parent node.
- main_chain_id(index: int) str¶
Creates the identifier of the ‘index’th node in the main chain.
- main_length() int¶
Returns the number of nodes in the main chain.
- subchain_id(main_index: int, sub_index: int) str¶
Creates the identifier of the node at the specified coordinates.
- Parameters:
main_index (int) – The index of the node according to the main chain.
sub_index (int) – The index of the node inside the subchain.
- Returns:
The identifier of the node.
- Return type:
str
- subchain_length(index: int) int¶
Returns the number of tensors in the ‘index’th subchain.
pytreenet.special_ttn.mps module¶
Provides the matrix product topology TTN.
A matrix product topology is just a chain of nodes. Nodes can be added automatically on either side. This is the most commonly used topology with MPS and MPO. These are also supplied combining the matrix product topology with the properties of a TTNS or TTNO.
- class pytreenet.special_ttn.mps.MatrixProductOperator¶
- class pytreenet.special_ttn.mps.MatrixProductState¶
Bases:
MatrixProductTree,TreeTensorNetworkStateA state with the matrix product topology.
A matrix product state (MPS) is one of the most common forms of tensor networks. It is a chain of tensors, each with one physical leg.
- classmethod constant_product_state(state_value: int, dimension: int, num_sites: int, node_prefix: str = 'site', root_site: int = 0, bond_dimensions: List[int] | None = None) Any¶
Generates an MPS that corresponds to a product state with the same value at every site.
- Parameters:
state_value (int) – The state’s value at every site.
dimension (int) – The local dimension of the MPS.
num_sites (int) – The number of sites in the MPS.
node_prefix (str, optional) – A prefix that should be part of the node identifiers before the site index. Defaults to “site”.
root_site (int, optional) – Which tensor should be associated to the root node. Defaults to 0.
bond_dimensions (Union[List[int],None]) – Give custom bond dimensions. The zeroth entry will be the dimension between nodes 0 and 1 and so forth. Defaults to None, in which case the bond dimensions are all one.
- Returns:
- Return type:
- class pytreenet.special_ttn.mps.MatrixProductTree¶
Bases:
TreeTensorNetworkA tree tensor network in the form of a chain.
In principle every node can have an arbitrary number of legs. Important special cases are the MPS and MPO. Mostly used for testing.
- left_nodes¶
A dictionary of nodes that are attached to the leftmost node. The keys are the identifiers of the nodes.
- Type:
Dict[str, Node]
- right_nodes¶
A dictionary of nodes that are attached to the rightmost node. The keys are the identifiers of the nodes.
- Type:
Dict[str, Node]
- attach_node_left_end(node: Node, tensor: ndarray, final: bool = False)¶
Attaches a node as a child to the leftmost node.
- Parameters:
node (Node) – The node to be added.
tensor (np.ndarray) –
The tensor to be associated with the node. Legs should be of the form
[other_virtual_leg, parent_leg, open_legs]
- attach_node_right_end(node: Node, tensor: ndarray)¶
Attaches a node as a child to the rightmost node.
- Parameters:
node (Node) – The node to be added.
tensor (np.ndarray) –
The tensor to be associated with the node. Legs should be of the form
[parent_leg, other_virtual_leg, open_legs]
- classmethod from_tensor_list(tensor_list: List[ndarray], node_prefix: str = 'site', root_site: int = 0) Any¶
Generates a MatrixProductTree from a list of tensors.
The nodes in the MPT will be considered as from left to right, in the same way as they are in the list.
- Parameters:
tensor_list (List[np.ndarray]) –
A list with site tensors. Their legs should be of the form
[left_leg,right_leg,open_legs]
node_prefix (str, optional) – A prefix that should be part of the node identifiers before the site index. Defaults to “site”.
root_site (int, optional) – Which tensor should be associated to the root node. Defaults to 0.
- Returns:
- A matrix product tree representing an MP
structure A_1 * A_2 … A_N, where the A are the tensors in the provided list.
- Return type:
- classmethod from_tensor_list_leftmost_node_is_root(tensor_list: List[ndarray], node_prefix: str = 'site') Any¶
Generates a MatrixProductTree from a list of tensors, where the leftmost tensor, i.e. index 0, corresponds to the root node.
The nodes in the MPT will be considered as from left to right, in the same way as they are in the list.
- Parameters:
tensor_list (List[np.ndarray]) –
A list with site tensors. Their legs should be of the form
[left_leg,right_leg,open_legs]
node_prefix (str, optional) – A prefix that should be part of the node identifiers before the site index. Defaults to “site”.
- Returns:
- A matrix product tree representing an MP
structure A_1 * A_2 … A_N, where the A are the tensors in the provided list.
- Return type: