Tensor Network Theory Library  Beta release 1.2.1
A library of routines for performing TNT-based operations
 All Data Structures Functions Variables Groups Pages
tntMpsST2sc.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 $LastChangedDate: 2016-06-29 15:50:34 +0100 (Wed, 29 Jun 2016) $
4 (c) University of Oxford 2014
5 */
6 
13 /* Include the internal header for the TNT library */
14 #include "tntMpsInternal.h"
15 
31 void tntMpsPropST2scConnect(tntNetwork mps,
32  tntNetwork Prop)
33 {
34 
35  tntNetwork Propc; /* A copy of the propagator network */
36  tntNode P; /* The current propagator */
37  tntNode A; /* The current MPS node */
38  unsigned j; /* site counter */
39 
40  /* make a copy of the network */
41  Propc = tntNetworkCopy(Prop);
42 
43  /* Find the first node in the copy of the propagator */
44  P = tntNodeFindFirst(Propc);
45 
46  /* Find the first MPS node */
47  A = tntNodeFindFirst(mps);
48 
49  /* Attach the top left leg of the first propagator to the first MPS node */
50  tntNodeJoin(P, "U", A, "D");
51 
52  /* Loop through the networks, joining top right leg of propagator to the next MPS node */
53  for (j = 1; j < tntMpsLength(mps); j++) {
54  /* Find the next MPS node */
55  A = tntNodeFindConn(A, "R");
56 
57  /* Connect it to the top right leg of the current propagator */
58  tntNodeJoin(P, "V", A, "D");
59 
60  /* Go to the next propagator in the staircase */
61  P = tntNodeFindConn(P, "E");
62  }
63 
64  P = tntNodeFindFirst(Propc);
65 
66  /* Get rid of connections to the start and end of the network */
67  tntNetworkToNodeGroup(&Propc,1);
68 
69  return;
70 
71 }
72 
73 
97 double tntMpsPropSTscContract(tntNetwork mpsProp,
98  int chi)
99 {
100  tntNode Al, Ar, S; /* The left and right current nodes and the singular values from the SVD */
101  unsigned j, L; /* Number of nodes in the MPS and site counter */
102  int direction=1; /* direction of the sweep: 1 = left to right, 0 = right to left */
103  double err = 0; /* Total truncation error */
104 
105  /* Get the number of nodes in the MPS */
106  L = tntMpsLength(mpsProp);
107 
108  /* Determine the direction of the staircase. If the first two nodes are connected to the same propagator it is a left-to-right sweep, otherwise assume left to right sweep */
109  Al = tntNodeFindFirst(mpsProp);
110  Ar = tntNodeFindConn(Al,"R");
111  if (tntNodeFindConn(Al, "D") != tntNodeFindConn(Ar, "D")) direction = -1;
112 
113  /* Sweep through the network */
114  if (1 == direction) {
115  /* Set the current tensor equal to the first tensor in the network if moving right */
116  Al = tntNodeFindFirst(mpsProp);
117  Ar = tntNodeFindConn(Al,"R");
118 
119  for (j = 0; j < L-1; j ++) {
120  /* Perform local operations to change apply the propagator, then factorise into two unitary nodes and a singular value matrix */
121  S = tntMpsPropTwoSite(&Al, &Ar, chi, &err);
122 
123  /* Contract S and Ar and assign the result to Al to move along one site. */
124  Al = tntNodeContract(S, Ar);
125 
126  /* Find the next node along */
127  Ar = tntNodeFindConn(Al,"R");
128  }
129  } else {
130  /* Set the current tensor equal to the last tensor in the network if moving left */
131  Ar = tntNodeFindLast(mpsProp);
132  Al = tntNodeFindConn(Ar,"L");
133 
134  for (j = L-1; j > 0; j--) {
135  /* Perform local operations to change apply the propagator, then factorise into two unitary nodes and a singular value matrix */
136  S = tntMpsPropTwoSite(&Al, &Ar, chi, &err);
137 
138  /* Contract S and Ar and assign the result to Al to move along one site. */
139  Ar = tntNodeContract(S, Al);
140 
141  /* Find the next node along */
142  Al = tntNodeFindConn(Ar,"L");
143  }
144  }
145 
146  /* Return the error */
147  return err;
148 
149 }
150 
157 tntNode tntMpsPropTwoSite(tntNode *Alp,
158  tntNode *Arp,
159  int chi,
160  double *err)
161 {
162  tntNode Al=*Alp, Ar=*Arp; /* The current pair of MPO nodes */
163  tntNode S; /* The singular value matrix from the SVD */
164  tntNode theta; /* The node made by contracting the the two MPO nodes with the two site gate(s) */
165  tntNode P; /* The propagators to contract with MPO */
166  double errc; /* Truncation error from each SVD */
167 
168 
169  /* Find the propagator */
170  P = tntNodeFindConn(Al, "D");
171 
172  /* Contract the MPS nodes with the time step */
173  theta = tntNodeListContract(NULL, Al, Ar, P);
174 
175  /* SVD theta tensor */
176  Al = tntNodeSVD(theta,"LD","R","L","R","L",chi,&errc,"E=D");
177  *err += errc;
178 
179  /* Find S and the right node (VT from SVD) */
180  S = tntNodeFindConn(Al,"R");
181  *Arp = tntNodeFindConn(S,"R");
182  *Alp = Al;
183 
184  return S;
185 }
186 
203 double tntMpsPropST2scProduct(tntNetwork mps,
204  tntNetwork Prop,
205  int chi)
207 {
208  /* Total truncation error */
209  double err;
210 
211  /* Connect a copy of Prop to the mps */
212  tntMpsPropST2scConnect(mps,Prop);
213 
214  /* Apply two contractions of a single staircase */
215  err = tntMpsPropSTscContract(mps,chi);
216  err += tntMpsPropSTscContract(mps,chi);
217 
218  /* Note if the system is a two-site system, we need to force the MPS to become orthogonalised on the first site */
219  if (2 == tntMpsLength(mps)) {
220  tntMpsOrth(mps,0);
221  }
222 
223  /* Return the error */
224  return err;
225 
226 }
void tntNodeJoin(tntNode A, tntLegLabel legA, tntNode B, tntLegLabel legB)
Definition: tntNodeConn.c:52
tntNode tntNodeFindLast(tntNetwork nw)
Definition: tntNodeInfo.c:68
double tntMpsPropSTscContract(tntNetwork mpsProp, int chi)
Definition: tntMpsST2sc.c:97
tntNode tntNodeSVD(tntNode A, tntLegLabel Ulegs, tntLegLabel legUS, tntLegLabel legSU, tntLegLabel legSV, tntLegLabel legVS, int chi, double *err, tntLegLabel legmap)
unsigned tntMpsLength(tntNetwork wf)
Definition: tntMpsUtil.c:17
double tntMpsPropST2scProduct(tntNetwork mps, tntNetwork Prop, int chi)
Definition: tntMpsST2sc.c:203
tntNode tntMpsPropTwoSite(tntNode *Alp, tntNode *Arp, int chi, double *err)
Definition: tntMpsST2sc.c:157
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
void tntMpsOrth(tntNetwork wf, unsigned orth_centre)
Definition: tntMpsOrth.c:36
void tntNetworkToNodeGroup(tntNetwork *nwp, int strip_connections)
Definition: tntNetwork.c:268
void tntMpsPropST2scConnect(tntNetwork mps, tntNetwork Prop)
Definition: tntMpsST2sc.c:31