Replies: 2 comments 1 reply
-
Hi @epelaaez, there are a number of ways to specify a contraction path, but mostly I think your options if you don't want to use automated contraction are: manual contraction using tags
Since each contraction involves modifying the tensor network there is a slight performance hit to this approach, but you can draw the TN at each stage etc. manual low level specification of pathThe 'raw' path format
This is not a very convenient format to work with directly (since many tensors' index changes each contraction) and is inherited from SSA (single static assignment) pathThis is a more easily understandable path, similar to the above but you assume that when contracting (2, 3) you don't pop them from the list, so the intermediates are labelled
|
Beta Was this translation helpful? Give feedback.
-
For future reference to anyone that this might be useful to, I ended up writing the following simple function: def contract_tn(tn, path: List[Tuple[int, int]], inplace=False):
tn = tn if inplace else tn.copy()
tags = [f"T{i}" for i in range(tn.num_tensors)]
# use tags
for i, tensor in enumerate(tn):
tensor.add_tag(f"T{i}")
for edge in path:
tn.contract_tags_([f"T{edge[0]}", f"T{edge[1]}"])
tn.drop_tags(tags + ["contract"])
return tn |
Beta Was this translation helpful? Give feedback.
-
I have the following tensor network.
Ignoring outer edges, I can graph this as:
I compute a contraction path of the form
[(2, 3), (4, 5), (0, 1), (0, 2), (1, 2), (3, 4), (5, 6)]
, which I want to transverse in reverse. I.e., first contract tensors 5 and 6, then 3 and 4, and so on. Is there a way to do this withtn.contract
?Beta Was this translation helpful? Give feedback.
All reactions