qib.tensor_network.symbolic_network.SymbolicTensorNetwork

class qib.tensor_network.symbolic_network.SymbolicTensorNetwork(tensors: Sequence[SymbolicTensor] | None = None, bonds: Sequence[SymbolicBond] | None = None)[source]

Bases: object

Symbolic tensor network, storing a list of tensors and bonds. Open (uncontracted) axes in the network are represented by the legs of a virtual tensor with ID -1.

Methods

add_bond

Add a bond to the network, and create references to this bond in tensors.

add_tensor

Add a tensor to the network.

as_einsum

Convert the contractions in the network to an numpy.einsum argument list, for a single call of numpy.einsum.

build_contraction_tree

Build the contraction tree based on the contraction ordering in scaffold, which is a recursively nested list of IDs to specify the tree, e.g., scaffold = [[ta, tb], [[tc, td], te]].

generate_bonds

Generate bonds based on the information stored in the tensors.

get_bond

Get the bond with ID bid.

get_bond_axes

Get the axes corresponding to the ordered tensor IDs referenced by the bond.

get_tensor

Get the tensor with ID tid.

has_bond

Whether the bond with ID bid exists.

has_tensor

Whether the tensor with ID tid exists.

is_consistent

Perform an internal consistency check, e.g., whether the bond ID specified by any tensor actually exist.

merge

Merge network with another symbolic tensor network, and join open axes specified as [(openax_self, openax_other), ...].

merge_bonds

Merge bonds with IDs bid1 and bid2.

merge_tensors

Merge tensors with IDs tid1 and tid2.

rename_bond

Rename bond ID bid_cur -> bid_new.

rename_tensor

Rename tensor ID tid_cur -> tid_new.

tensor_ids

Return the list of tensor IDs in the network (without virtual tensor ID -1).

transpose

Logically transpose the network, i.e., the virtual output tensor of the network.

Attributes

num_bonds

Number of bonds.

num_open_axes

Number of open (uncontracted) axes in the network.

num_tensors

Number of logical tensors.

shape

Logical shape of tensor network (after contracting all bonds).

add_bond(bond: SymbolicBond)[source]

Add a bond to the network, and create references to this bond in tensors.

add_tensor(tensor: SymbolicTensor)[source]

Add a tensor to the network.

as_einsum() tuple[source]

Convert the contractions in the network to an numpy.einsum argument list, for a single call of numpy.einsum. The ordering of the output axes follows the virtual tensor for the open axes.

Returns:

tensor IDs and index argument list for numpy.einsum,

and map from logical open axes to axes of output tensor of numpy.einsum (einsum does not support an output index appearing multiple times)

Return type:

tids, tidx, idxout, axes_map

build_contraction_tree(scaffold) ContractionTreeNode[source]

Build the contraction tree based on the contraction ordering in scaffold, which is a recursively nested list of IDs to specify the tree, e.g., scaffold = [[ta, tb], [[tc, td], te]].

generate_bonds()[source]

Generate bonds based on the information stored in the tensors.

get_bond(bid: int) SymbolicBond[source]

Get the bond with ID bid.

get_bond_axes(bid: int)[source]

Get the axes corresponding to the ordered tensor IDs referenced by the bond.

get_tensor(tid: int) SymbolicTensor[source]

Get the tensor with ID tid.

has_bond(bid: int) bool[source]

Whether the bond with ID bid exists.

has_tensor(tid: int) bool[source]

Whether the tensor with ID tid exists.

is_consistent(verbose=False) bool[source]

Perform an internal consistency check, e.g., whether the bond ID specified by any tensor actually exist.

merge(other, join_axes: Sequence[tuple] | None = None)[source]

Merge network with another symbolic tensor network, and join open axes specified as [(openax_self, openax_other), …].

merge_bonds(bid1: int, bid2: int)[source]

Merge bonds with IDs bid1 and bid2. The resulting bond inherits ID bid1.

merge_tensors(tid1: int, tid2: int)[source]

Merge tensors with IDs tid1 and tid2. The resulting tensor inherits ID tid1.

property num_bonds: int

Number of bonds.

property num_open_axes: int

Number of open (uncontracted) axes in the network.

property num_tensors: int

Number of logical tensors.

rename_bond(bid_cur: int, bid_new: int)[source]

Rename bond ID bid_cur -> bid_new.

rename_tensor(tid_cur: int, tid_new: int)[source]

Rename tensor ID tid_cur -> tid_new.

property shape: tuple

Logical shape of tensor network (after contracting all bonds).

tensor_ids() list[source]

Return the list of tensor IDs in the network (without virtual tensor ID -1).

transpose(axes=None)[source]

Logically transpose the network, i.e., the virtual output tensor of the network.