Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
tntMpsTruncate.c
1  /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 $LastChangedDate: 2014-08-07 14:12:05 +0100 (Thu, 07 Aug 2014)$
4 (c) University of Oxford 2015
5 */
6
13 /* Include the header for the TNT MPS library */
14 #include "tntMpsInternal.h"
15
16
44 double tntMpsTruncate(tntNetwork mps,
45  unsigned orth_centre,
46  int chi)
47 {
48  tntNode A; /* The current node */
49  tntNode S, VT; /* Nodes that result from taking SVD */
50  unsigned L, j; /* Number of nodes and node counter in the MPS network */
51  double err, err_tot = 0.0; /* Truncation error per SVD and total truncation error */
52
53  /* Check the the number of nodes in the MPS network */
54  L = tntMpsLength(mps);
55
56  /* Give an error if orth_centre is more than index of the last site */
57  if (orth_centre > L-1) {
58  tntErrorPrint("The site for the orthogonality centre (%d) is greater than the length of the MPS (%d)", orth_centre, L); /* NO_COVERAGE */
59  } /* NO_COVERAGE */
60
61  /* Loop from first site to orthogonality centre, leaving the twist' at the orthogonality centre */
62  A = tntNodeFindFirst(mps);
63  for (j = 0; j < orth_centre; j++) {
64  /* Choose take truncated SVD and add truncation error to total value. */
65  A = tntNodeSVD(A,"LD","R","L","R","L",chi,&err);
66  err_tot += err;
67
68  /* A is assigned to U so is now normalised. Contract S and VT with next node along. */
69
70  /* Find S, VT and the next node */
71  S = tntNodeFindConn(A,"R");
72  VT = tntNodeFindConn(S,"R");
73  A = tntNodeFindConn(VT,"R");
74
75  /* Contract all three nodes and assign to A. */
76  A = tntNodeListContract(NULL,S,VT,A);
77  }
78
79  /* Loop from the last site to the orthogality centre, leaving the twist' at the orthogonality centre */
80  A = tntNodeFindLast(mps);
81
82  for (j = L-1; j > orth_centre; j--) {
83  /* Choose take truncated SVD and add truncation error to total value. */
84  A = tntNodeSVD(A,"RD","L","R","L","R",chi,&err);
85  err_tot += err;
86  /* A is assigned to U so is now normalised. Contract S and VT with next node along. */
87
88  /* Find S, VT and the next node */
89  S = tntNodeFindConn(A,"L");
90  VT = tntNodeFindConn(S,"L");
91  A = tntNodeFindConn(VT,"L");
92
93  /* Contract all three nodes and assign to A. */
94  A = tntNodeListContract(NULL,S,VT,A);
95  }
96
97  return err_tot;
98 }
tntNode tntNodeFindLast(tntNetwork nw)
Definition: tntNodeInfo.c:68
double tntMpsTruncate(tntNetwork mps, unsigned orth_centre, int chi)
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
tntNode tntNodeFindConn(tntNode A, tntLegLabel legA)
Definition: tntNodeInfo.c:29
tntNode tntNodeFindFirst(tntNetwork nw)
Definition: tntNodeInfo.c:50