tensornetwork.Node

class tensornetwork.Node(tensor: Union[Any, tensornetwork.network_components.AbstractNode], name: Optional[str] = None, axis_names: Optional[List[str]] = None, backend: Union[str, tensornetwork.backends.abstract_backend.AbstractBackend, None] = None)

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__(tensor: Union[Any, tensornetwork.network_components.AbstractNode], name: Optional[str] = None, axis_names: Optional[List[str]] = None, backend: Union[str, tensornetwork.backends.abstract_backend.AbstractBackend, None] = None) → None

Create a node.

Parameters:
  • tensor – The concrete that is represented by this node, or a AbstractNode object. If a tensor is passed, it can be be either a numpy array or the tensor-type of the used backend. If a AbstractNode is passed, the passed node has to have the same backend as given by backend.
  • name – Name of the node. Used primarily for debugging.
  • axis_names – List of names for each of the tensor’s axes.
  • backend – The name of the backend or an instance of a AbstractBackend.
Raises:

ValueError – If there is a repeated name in axis_names or if the length doesn’t match the shape of the tensor.

Methods

__init__(tensor, …) 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()
op_protection(other, float, complex, Node])
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
classmethod from_serial_dict(serial_dict) → tensornetwork.network_components.Node

Return a node given a serialized dict representing it.

Parameters:serial_dict – A python dict representing a serialized node.
Returns:A node.
to_serial_dict() → Dict[KT, VT]

Return a serializable dict representing the node.

Returns: A dict object.