Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Fix base contraction #974

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions tensornetwork/contractors/opt_einsum_paths/path_contractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ def base(nodes: Iterable[AbstractNode],

# Then apply `opt_einsum`'s algorithm
path, nodes = utils.get_path(nodes_set, algorithm)
for a, b in path:
new_node = contract_between(nodes[a], nodes[b], allow_outer_product=True)
for p in path:
if len(p) == 2:
a, b = p
new_node = contract_between(nodes[a], nodes[b], allow_outer_product=True)
elif len(p) == 1:
new_node = nodes[p[0]]
else:
raise NotImplementedError('Hypergraph contraction not supported.')
nodes.append(new_node)
nodes = utils.multi_remove(nodes, [a, b])
nodes = utils.multi_remove(nodes, p)

# if the final node has more than one edge,
# output_edge_order has to be specified
Expand Down