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:
objectSymbolic 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 a bond to the network, and create references to this bond in tensors.
Add a tensor to the network.
Convert the contractions in the network to an numpy.einsum argument list, for a single call of numpy.einsum.
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 based on the information stored in the tensors.
Get the bond with ID bid.
Get the axes corresponding to the ordered tensor IDs referenced by the bond.
Get the tensor with ID tid.
Whether the bond with ID bid exists.
Whether the tensor with ID tid exists.
Perform an internal consistency check, e.g., whether the bond ID specified by any tensor actually exist.
Merge network with another symbolic tensor network, and join open axes specified as [(openax_self, openax_other), ...].
Merge bonds with IDs bid1 and bid2.
Merge tensors with IDs tid1 and tid2.
Rename bond ID bid_cur -> bid_new.
Rename tensor ID tid_cur -> tid_new.
Return the list of tensor IDs in the network (without virtual tensor ID -1).
Logically transpose the network, i.e., the virtual output tensor of the network.
Attributes
Number of bonds.
Number of open (uncontracted) axes in the network.
Number of logical tensors.
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]].
- 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.
- 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.