# tensornetwork.AbstractNode¶

class tensornetwork.AbstractNode(name: Optional[str] = None, axis_names: Optional[List[str]] = None, backend: Optional[tensornetwork.backends.abstract_backend.AbstractBackend] = None, shape: Optional[Tuple[int]] = None)

Abstract class for nodes. Should be subclassed.

A Node represents a concrete tensor in a tensor network. The number of edges for a node represents the rank of that tensor.

For example:

• A node with no edges means this node represents a scalar value.
• A node with a single edge means this node is a vector.
• A node with two edges represents a matrix.
• A node with three edges is a tensor of rank 3, etc.

Each node can have an arbitrary rank/number of edges, each of which can have an arbitrary dimension.

__init__(name: Optional[str] = None, axis_names: Optional[List[str]] = None, backend: Optional[tensornetwork.backends.abstract_backend.AbstractBackend] = None, shape: Optional[Tuple[int]] = None) → None

Create a node. Should be subclassed before usage and a limited number of abstract methods and properties implemented.

Parameters: name – Name of the node. Used primarily for debugging. axis_names – List of names for each of the tensor’s axes. shape – the shape of the tensor, as tuple of integers. ValueError – If there is a repeated name in axis_names or if the length doesn’t match the shape of the tensor.

Methods

 __init__(name, axis_names, backend, shape) Create a node. add_axis_names(axis_names) Add axis names to a Node. add_edge(edge, axis, str], override) Add an edge to the node on the given axis. copy(conjugate) disable() fresh_edges(axis_names) get_all_dangling() Return the set of dangling edges connected to this node. get_all_edges() get_all_nondangling() Return the set of nondangling edges connected to this node. get_axis_number(axis, int]) Get the axis number for a given axis name or value. get_dimension(axis, int]) Get the dimension of the given axis. get_edge(axis, str]) get_rank() Return rank of tensor represented by self. get_tensor() has_dangling_edge() has_nondangling_edge() reorder_axes(perm) Reorder axes of the node’s tensor. reorder_edges(edge_order) Reorder the edges for this given Node. set_name(name) set_tensor(tensor) tensor_from_edge_order(perm)

Attributes

 axis_names dtype edges name shape sparse_shape tensor
add_axis_names(axis_names: List[str]) → None

Add axis names to a Node.

Parameters: axis_names – List of names for each of the tensor’s axes. ValueError – If there is a repeated name in axis_names or if the length doesn’t match the shape of the tensor.
add_edge(edge: tensornetwork.network_components.Edge, axis: Union[int, str], override: bool = False) → None

Add an edge to the node on the given axis.

Parameters: edge – The edge to add. axis – The axis the edge points to. override – If true, replace the existing edge with the new one. ValueError – If the edge on axis is not dangling.
classmethod from_serial_dict(serial_dict) → tensornetwork.network_components.AbstractNode

Return a node given a serialized dict representing it.

Parameters: serial_dict – A python dict representing a serialized node. A node.
get_all_dangling() → List[tensornetwork.network_components.Edge]

Return the set of dangling edges connected to this node.

get_all_nondangling() → Set[tensornetwork.network_components.Edge]

Return the set of nondangling edges connected to this node.

get_axis_number(axis: Union[str, int]) → int

Get the axis number for a given axis name or value.

get_dimension(axis: Union[str, int]) → Optional[int]

Get the dimension of the given axis.

Parameters: axis – The axis of the underlying tensor. The dimension of the given axis. ValueError – if axis isn’t an int or if axis is too large or small.
get_rank() → int

Return rank of tensor represented by self.

reorder_axes(perm: List[int]) → tensornetwork.network_components.AbstractNode

Reorder axes of the node’s tensor.

This will also update all of the node’s edges.

Parameters: perm – Permutation of the dimensions of the node’s tensor. This node post reordering. AttributeError – If the Node has no tensor.
reorder_edges(edge_order: List[Edge]) → tensornetwork.network_components.AbstractNode

Reorder the edges for this given Node.

This will reorder the node’s edges and transpose the underlying tensor accordingly.

Parameters: edge_order – List of edges. The order in the list determines the new edge ordering. This node post reordering. ValueError – If either the list of edges is not the same as expected or if you try to reorder with a trace edge. AttributeError – If the Node has no tensor.
to_serial_dict() → Dict[KT, VT]

Return a serializable dict representing the node.

Returns: A dict object.