quimb.tensor.networking¶
Functionality for analyzing the structure of tensor networks, including finding paths, loops, connected components, hierarchical groupings and more.
Classes¶
A simple class to represent a path through a tensor network, storing |
Functions¶
|
Check if this tensor network has a tree structure, (treating |
|
Check whether this tensor network is connected, i.e. whether |
|
Split this tensor network into disconneceted subgraphs. |
|
Generate a tree on the tensor network graph, fanning out from the |
|
Find a shortest path between |
|
Generate all shortest paths between |
|
Generate all paths, up to a specified length, that represent loops in |
|
Generate sets of tids that represent 'regions' where every node is |
|
Generate sequences of tids that represent loops in the TN. |
|
Generate all index 'patches' of size up to |
|
Check whether nodes |
|
Compute the minimum graph distances between all or some nodes |
|
|
|
Compute a hierarchical grouping of |
|
Compute a hierarchical ordering of |
|
Group |
Compute a simple centrality measure for each tensor in the network. The |
|
|
Find the most central tensor in the network. |
Find the least central tensor in the network. |
Module Contents¶
- class quimb.tensor.networking.NetworkPath(tids, inds=())[source]¶
A simple class to represent a path through a tensor network, storing both the tensor identifies (tids) and indices (inds) it passes through.
- __slots__ = ('_tids', '_inds', '_key')¶
- _tids¶
- _inds = ()¶
- _key = None¶
- property tids¶
- property inds¶
- property key¶
- quimb.tensor.networking.istree(tn)[source]¶
Check if this tensor network has a tree structure, (treating multibonds as a single edge).
Examples
>>> MPS_rand_state(10, 7).istree() True
>>> MPS_rand_state(10, 7, cyclic=True).istree() False
- quimb.tensor.networking.isconnected(tn)[source]¶
Check whether this tensor network is connected, i.e. whether there is a path between any two tensors, (including size 1 indices).
- quimb.tensor.networking.subgraphs(tn, virtual=False)[source]¶
Split this tensor network into disconneceted subgraphs.
- Parameters:
virtual (bool, optional) – Whether the tensor networks should view the original tensors or not - by default take copies.
- Return type:
- quimb.tensor.networking.get_tree_span(tn, tids, min_distance=0, max_distance=None, include=None, exclude=None, ndim_sort='max', distance_sort='min', sorter=None, weight_bonds=True, inwards=True)[source]¶
Generate a tree on the tensor network graph, fanning out from the tensors identified by
tids
, up to a maximum ofmax_distance
away. The tree can be visualized withdraw_tree_span()
.- Parameters:
tids (sequence of str) – The nodes that define the region to span out of.
min_distance (int, optional) – Don’t add edges to the tree until this far from the region. For example,
1
will not include the last merges from neighboring tensors in the region defined bytids
.max_distance (None or int, optional) – Terminate branches once they reach this far away. If
None
there is no limit,include (sequence of str, optional) – If specified, only
tids
specified here can be part of the tree.exclude (sequence of str, optional) – If specified,
tids
specified here cannot be part of the tree.ndim_sort ({'min', 'max', 'none'}, optional) – When expanding the tree, how to choose what nodes to expand to next, once connectivity to the current surface has been taken into account.
distance_sort ({'min', 'max', 'none'}, optional) – When expanding the tree, how to choose what nodes to expand to next, once connectivity to the current surface has been taken into account.
weight_bonds (bool, optional) – Whether to weight the ‘connection’ of a candidate tensor to expand out to using bond size as well as number of bonds.
- Returns:
The ordered list of merges, each given as tuple
(tid1, tid2, d)
indicating mergetid1 -> tid2
at distanced
.- Return type:
See also
draw_tree_span
- quimb.tensor.networking.get_path_between_tids(tn, tida, tidb)[source]¶
Find a shortest path between
tida
andtidb
in this tensor network. Returns aNetworkPath
if a path is found, otherwiseNone
.Currently ignores dangling and hyper indices.
- Parameters:
tn (TensorNetwork) – The tensor network to find a path in.
tida (int) – The tensor id to start from.
tidb (int) – The tensor id to end at.
- Return type:
NetworkPath or None
- quimb.tensor.networking.gen_all_paths_between_tids(tn, tida, tidb)[source]¶
Generate all shortest paths between
tida
andtidb
in this tensor network. Returns a generator ofNetworkPath
objects, ignores dangling and hyper indices currently.- Parameters:
tn (TensorNetwork) – The tensor network to find paths in.
tida (int) – The tensor id to start from.
tidb (int) – The tensor id to end at.
- Yields:
NetworkPath
- quimb.tensor.networking.gen_paths_loops(tn, max_loop_length=None, intersect=False, tids=None, inds=None, paths=None)[source]¶
Generate all paths, up to a specified length, that represent loops in this tensor network. Unlike
gen_loops
this function will yield a NetworkPath objects, allowing one to differentiate between e.g. a double loop and a ‘figure of eight’ loop. Dangling and hyper indices are ignored.Currently ignores dangling and hyper indices.
- Parameters:
tn (TensorNetwork) – The tensor network to find loops in.
max_loop_length (None or int) – Set the maximum number of indices that can appear in a loop. If
None
, wait until any loop is found and set that as the maximum length.intersect (bool, optional) – Whether to allow self-intersecting loops.
tids (None or sequence of int, optional) – If supplied, only consider loops containing one of these tensor ids.
inds (None or sequence of str, optional) – If supplied, only consider loops containing one of these indices.
paths (None or sequence of NetworkPath, optional) – If supplied, only consider loops starting from these paths.
- Yields:
NetworkPath
See also
- quimb.tensor.networking.gen_regions(tn, max_region_size=None, tids=None, which='all')[source]¶
Generate sets of tids that represent ‘regions’ where every node is connected to at least two other region nodes, i.e. 2-degree connected subgraphs.
- Parameters:
tn (TensorNetwork) – The tensor network to find regions in.
max_region_size (None or int) – Set the maximum number of tensors that can appear in a region. If
None
, wait until any valid region is found and set that as the maximum size.tids (None or sequence of int, optional) – If supplied, only yield regions containing these tids, see
which
.which ({'all', 'any'}, optional) – Only if
tids
is specified, this determines how to filter regions. If ‘all’, only yield regions containing all of the tids intids
, if ‘any’, yield regions containing any of the tids intids
.
- Yields:
tuple[int]
- quimb.tensor.networking.gen_loops(tn, max_loop_length=None)[source]¶
Generate sequences of tids that represent loops in the TN.
- Parameters:
max_loop_length (None or int) – Set the maximum number of tensors that can appear in a loop. If
None
, wait until any loop is found and set that as the maximum length.- Yields:
tuple[int]
See also
- quimb.tensor.networking.gen_inds_connected(tn, max_length)[source]¶
Generate all index ‘patches’ of size up to
max_length
.- Parameters:
max_length (int) – The maximum number of indices in the patch.
- Yields:
tuple[str]
See also
- quimb.tensor.networking.tids_are_connected(tn, tids)[source]¶
Check whether nodes
tids
are connected.- Parameters:
tn (TensorNetwork) – The tensor network to check.
tids (sequence of int) – Nodes to check.
- Return type:
- quimb.tensor.networking.compute_shortest_distances(tn, tids=None, exclude_inds=())[source]¶
Compute the minimum graph distances between all or some nodes
tids
.- Parameters:
tn (TensorNetwork) – The tensor network to compute distances in.
tids (None or sequence of int, optional) – If supplied, only compute distances between these nodes.
exclude_inds (sequence of str, optional) – Exclude these indices when computing distances.
- Return type:
- quimb.tensor.networking.compute_hierarchical_linkage(tn, tids=None, method='weighted', optimal_ordering=True, exclude_inds=())[source]¶
- quimb.tensor.networking.compute_hierarchical_ssa_path(tn, tids=None, method='weighted', optimal_ordering=True, exclude_inds=(), are_sorted=False, linkage=None)[source]¶
Compute a hierarchical grouping of
tids
, as assa_path
.
- quimb.tensor.networking.compute_hierarchical_ordering(tn, tids=None, method='weighted', optimal_ordering=True, exclude_inds=(), linkage=None)[source]¶
Compute a hierarchical ordering of
tids
.
- quimb.tensor.networking.compute_hierarchical_grouping(tn, max_group_size, tids=None, method='weighted', optimal_ordering=True, exclude_inds=(), linkage=None)[source]¶
Group
tids
(by default, all tensors) into groups of sizemax_group_size
or less, using a hierarchical clustering.
- quimb.tensor.networking.compute_centralities(tn)[source]¶
Compute a simple centrality measure for each tensor in the network. The values go from 0 to 1, with 1 being the most central tensor.
- Parameters:
tn (TensorNetwork) – The tensor network to compute centralities for.
- Return type: