TensorNetwork icon indicating copy to clipboard operation
TensorNetwork copied to clipboard

Environments

Open chaserileyroberts opened this issue 5 years ago • 1 comments

We should develop a way to easily/cheaply calculate all of the environments of a tensor network without any dangling edges.

chaserileyroberts avatar Apr 22 '20 22:04 chaserileyroberts

Hey @mganahl, given that ncon is currently being overhauled, maybe it is a good time to add this functionality? This is a very nice quality-of-life improvement that greatly simplifies the implementation of many tn algorithms. In my previous libraries I have added an optional which_env argument to ncon to specify an environment to return from a closed network. So if we had a closed tensor network (evaluates to a scalar):

tensors = [A,B,C,D]
connects = [A_ind, B_ind, C_ind, D_ind]
some_scalar = ncon(tensors, connects, con_order)

then one could get the environment of the 2nd tensor by calling instead:

tensors = [A,B,C,D]
connects = [A_ind, B_ind, C_ind, D_ind]
B_env = ncon(tensors, connects, con_order, which_env=2)

where the order of indices on B_env is chosen to match that from the removed tensor B. This is relatively easy to implement, although some care must be taken to properly adjust the contraction order to ensure the cost for computing the environment is the same as that of evaluating the closed network (I have a paper that explains this, https://arxiv.org/abs/1310.8023, or I could write the function for you that properly adjusts the order).

One can also write the code as to return multiple environments simultaneously, e.g.

tensors = [A,B,C,D]
connects = [A_ind, B_ind, C_ind, D_ind]
B_env, C_env, D_env = ncon(tensors, connects, con_order, which_env=[2,3,4])

although doing this with optimal computational efficiency is now much more complicated, though certainly doable as discussed in the arXiv preprint mentioned above (which also links to MATLAB code for a multi-env ncon).

gevenbly avatar Jun 11 '20 19:06 gevenbly