Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
tntMpoMpo.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 $LastChangedDate$
4 (c) University of Oxford 2014
5 */
6
12 /* Include the header for the TNT MPS library */
13 #include "tntMpsInternal.h"
14
15
24 tntNetwork tntMpoMpoProduct(tntNetwork mpoO,
25  tntNetwork mpoP)
26 {
27
28  tntNode O, P; /* current node and the next node of first MPO */
29  unsigned m, L; /* site index and length of the network */
30
31  L = tntMpoLength(mpoO);
32
33  /* Before contracting, check that the MPO networks have the same number of sites */
34  if (tntMpoLength(mpoP) != L) {
35  tntErrorPrint("The MPO networks cannot multiplied as they do not have the same number of nodes"); /* NO_COVERAGE */
36  } /* NO_COVERAGE */
37
38  /* Take copies */
39  mpoO = tntNetworkCopy(mpoO);
40  mpoP = tntNetworkCopy(mpoP);
41
42  /* Get the first nodes */
43  O = tntNodeFindFirst(mpoO);
44  P = tntNodeFindFirst(mpoP);
45
46  /* Turn P to a node group but leave the connections intact */
47  tntNetworkToNodeGroup(&mpoP,0);
48
49  /* Move through the network joining legs and contracting */
50  for (m = 0; m < L; m++) {
51
52  /* Join the two MPO nodes */
53  tntNodeJoin(O, "D", P, "U");
54
55  /* Contract them together */
56  O = tntNodeContract(O, P, NULL, "LR=MS");
57
58  /* Move along one site if we are not at the end */
59  if (m != L-1) {
60  P = tntNodeFindConn(O, "S");
61  O = tntNodeFindConn(O, "R");
62  }
63  }
64
65  /* Now find the first node, and fuse the first two legs on the left */
66  O = tntNodeFindFirst(mpoO);
67  tntNodeFuse(O, "LM", "L", "");
68
69  /* Move right through the network fusing all right facing legs (which will fuse left facing legs on the connecting node) */
70  for (m = 0; m < L; m++) {
71  tntNodeFuse(O, "RS", "R", "L");
72  O = tntNodeFindConn(O, "R");
73  }
74
75  return mpoO;
76
77 }
78
87 tntComplex tntMpoMpoTrace(tntNetwork mpoO,
88  tntNetwork mpoP)
89 {
90
91  tntNode O, P, alpha; /* current node and the next node of first MPO, contracted node */
92  unsigned m, L; /* site index and length of the network */
93  tntComplex contracted; /* The contracted network */
94
95  L = tntMpoLength(mpoO);
96
97  /* Before contracting, check that the MPO networks have the same number of sites */
98  if (tntMpoLength(mpoP) != L) {
99  tntErrorPrint("The MPO networks cannot multiplied as they do not have the same number of nodes"); /* NO_COVERAGE */
100  } /* NO_COVERAGE */
101
102  /* Take copies */
103  mpoO = tntNetworkCopy(mpoO);
104  mpoP = tntNetworkCopy(mpoP);
105
106  /* Get the first nodes */
107  O = tntNodeFindFirst(mpoO);
108  P = tntNodeFindFirst(mpoP);
109
110  /* Turn P to a node group but leave the connections intact */
111  tntNetworkToNodeGroup(&mpoP,0);
112
113  /* Move through the network joining legs and contracting */
114  for (m = 0; m < L; m++) {
115
116  /* Join the two MPO nodes along both physical legs */
117  tntNodeJoin(O, "D", P, "U");
118  tntNodeJoin(O, "U", P, "D");
119
120  /* Move along one site if we are not at the end */
121  if (m != L-1) {
122  O = tntNodeFindConn(O, "R");
123  P = tntNodeFindConn(P, "R");
124  }
125  }
126
127  /* Now contract the first two nodes to make alpha */
128  O = tntNodeFindFirst(mpoO);
129  P = tntNodeFindConn(O, "D");
130  alpha = tntNodeContract(O, P, NULL, "LR=MS");
131
132  /* Go through remaining sites, contracting them with alpha one by one */
133  for (m = 1; m < L; m++) {
134
135  /* Find the next nodes along */
136  O = tntNodeFindConn(alpha, "R");
137  P = tntNodeFindConn(alpha, "S");
138
139  /* Contract them with alpha */
140  alpha = tntNodeListContract("LMRS", alpha, O, P);
141
142  }
143
144  /* Get the one remaining element */
145  contracted = tntNodeGetFirstEl(alpha);
146
147  /* Free the network */
148  tntNetworkFree(&mpoO);
149
150  /* Return the result of the contraction */
151  return contracted;
152 }
153
161 tntNetwork tntMpoHC(tntNetwork mpoO) {
162
163  tntNode O; /* Node in the conjugate network */
164  unsigned m, L; /* site index and length of the network */
165
166  L = tntMpoLength(mpoO);
167
168  mpoO = tntNetworkConjCopy(mpoO);
169  O = tntNodeFindFirst(mpoO);
170  for (m = 0; m < L; m++) {
171  tntNodeMapLegs(O,"UD=DU");
172  O = tntNodeFindConn(O, "R");
173  }
174
175  return mpoO;
176 }
void tntNodeFuse(tntNode A, tntLegLabel fuseLegs, tntLegLabel newLabelA, tntLegLabel newLabelB)
Definition: tntNodeConn.c:90
void tntNetworkFree(tntNetwork *nwp)
Definition: tntNetwork.c:118
void tntNodeJoin(tntNode A, tntLegLabel legA, tntNode B, tntLegLabel legB)
Definition: tntNodeConn.c:52
tntNetwork tntMpoMpoProduct(tntNetwork mpoO, tntNetwork mpoP)
Definition: tntMpoMpo.c:24
tntNetwork tntNetworkConjCopy(tntNetwork nw)
Definition: tntNetwork.c:19
void tntNodeMapLegs(tntNode A, tntLegLabel legmap)
Definition: tntNodeConn.c:125
tntNetwork tntMpoHC(tntNetwork mpoO)
Definition: tntMpoMpo.c:161
Definition: tnt.h:65
tntNode tntNodeFindConn(tntNode A, tntLegLabel legA)
Definition: tntNodeInfo.c:29
tntNode tntNodeContract(tntNode A, tntNode B, tntLegLabel legMapAC, tntLegLabel legMapBC)
tntNode tntNodeFindFirst(tntNetwork nw)
Definition: tntNodeInfo.c:50
tntNetwork tntNetworkCopy(tntNetwork nw)
Definition: tntNetwork.c:56
tntComplex tntMpoMpoTrace(tntNetwork mpoO, tntNetwork mpoP)
Definition: tntMpoMpo.c:87
tntComplex tntNodeGetFirstEl(tntNode A)
Definition: tntNodeInfo.c:86
void tntNetworkToNodeGroup(tntNetwork *nwp, int strip_connections)
Definition: tntNetwork.c:268