tensorcircuit.simplify

Tensornetwork Simplification

tensorcircuit.simplify.infer_new_shape(a: Node, b: Node, include_old: bool = True) Any[source]

Get the new shape of two nodes, also supporting to return original shapes of two nodes.

Example:

a = tn.Node(np.ones([2, 3, 5]))
b = tn.Node(np.ones([3, 5, 7]))
a[1] ^ b[0]
a[2] ^ b[1]
tc.simplify.infer_new_shape(a, b)
# ((2, 7), (2, 3, 5), (3, 5, 7))
# return order: (new_shape, shape_of_a, shape_of_b)
Parameters:
  • a (tn.Node) – node one

  • b (tn.Node) – node two

  • include_old (bool) – Whether to include original shape of two nodes, default is True.

Returns:

The new shape of the two nodes.

Return type:

Union[Tuple[int, …], Tuple[Tuple[int, …], Tuple[int, …], Tuple[int, …]]]

tensorcircuit.simplify.pseudo_contract_between(a: Node, b: Node, **kws: Any) Node[source]

Contract between Node a and b, with correct shape only and no calculation

The returned node’s tensor is filled with zeros (no actual contraction is performed); this is useful for shape inference and graph manipulation when the resulting values are not needed.

Parameters:
  • a (tn.Node) – first node to “contract”

  • b (tn.Node) – second node to “contract”

Returns:

A new node whose tensor has the contracted shape but uninitialized (zero-filled) values; the shared edges between a and b are removed from the graph.

Return type:

tn.Node