tensornetwork.Edge

class tensornetwork.Edge(node1: tensornetwork.network_components.AbstractNode, axis1: int, name: Optional[str] = None, node2: Optional[tensornetwork.network_components.AbstractNode] = None, axis2: Optional[int] = None)

Each edge represents a vector space common to the tensors it connects and over which a contraction may be performed. In numpy terms, each edge represents a tensordot operation over the given axes. There are 3 main types of edges:

Standard Edge:
A standard edge is like any other edge you would find in a normal undirected graph as they connect two different nodes. This edge represents a tensor contraction of the underlying tensors along their given axes. The two axes must be the same dimension.
Dangling Edge:
A dangling edge is an edge that only connects to a single node and only one part of the edge connects to the node. The other end is left “dangling”. These types of edges can not be contracted and represent additional dimensions on the underlying tensor. After all other edges are contracted, the final result will have the same rank as the number of dangling edges. If there are no dangling edges, then the final value will be a scalar.
Trace Edges:
Trace edges are edges that connect a node to itself. These edges represent a trace along the given axis. Once again, the axes must be the same dimension.
__init__(node1: tensornetwork.network_components.AbstractNode, axis1: int, name: Optional[str] = None, node2: Optional[tensornetwork.network_components.AbstractNode] = None, axis2: Optional[int] = None) → None

Create an Edge.

Parameters:
  • name – Name of the edge. Used primarily for debugging.
  • node1 – One of the nodes edge connects.
  • axis1 – The axis of node1 that represents this edge.
  • node2 – The other node that this edge connects. Can be None if edge is dangling.
  • axis2 – The axis of node2 that represents this edge. Must be None if node2 is None.
Raises:

ValueError – If node2 and axis2 are not either both None or both not be None.

Methods

__init__(node1, axis1, name, node2, axis2) Create an Edge.
disable()
disconnect(edge1_name, edge2_name) Break an existing non-dangling edge.
get_nodes() Get the nodes of the edge.
is_being_used() Whether the nodes this edge points to also use this edge.
is_dangling() Whether this edge is a dangling edge.
is_trace()
set_name(name)
update_axis(old_axis, old_node, new_axis, …) Update the node that Edge is connected to.

Attributes

axis1
axis2
dimension
name
node1
node2
disconnect(edge1_name: Optional[str] = None, edge2_name: Optional[str] = None) → Tuple[tensornetwork.network_components.Edge, tensornetwork.network_components.Edge]

Break an existing non-dangling edge.

This updates both Edge.node1 and Edge.node2 by removing the connecting edge from Edge.node1.edges and Edge.node2.edges and adding new dangling edges instead :param edge1_name: A name for the new dangling edge at self.node1 :param edge2_name: A name for the new dangling edge at self.node2

Returns:
The new Edge objects of
self.node1 and self.node2
Return type:(new_edge1, new_edge2)
get_nodes() → List[Optional[tensornetwork.network_components.AbstractNode]]

Get the nodes of the edge.

is_being_used() → bool

Whether the nodes this edge points to also use this edge.

During edge flattening, nodes can change their edges. Since deleting objects in python isn’t possible, we use this to ensure that the edge is actually being used by the given nodes.

Returns:Whether this edge is actually being used.
is_dangling() → bool

Whether this edge is a dangling edge.

to_serial_dict() → Dict[KT, VT]

Return a serializable dict representing the edge.

Returns: A dict object.

update_axis(old_axis: int, old_node: tensornetwork.network_components.AbstractNode, new_axis: int, new_node: tensornetwork.network_components.AbstractNode) → None

Update the node that Edge is connected to.

Parameters:
  • old_axis – The old axis that the edge pointed to.
  • old_node – The old node that the edge pointed to.
  • new_axis – The new axis that the edge should point to.
  • new_node – The new node that replaces the old_node.
Raises:

AssertionError – Whether the edge actually contained old_node.