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
tntMpsUtil.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 Date: February 2013
4 (c) University of Oxford 2012
5 */
6 
7 /* Include the header for the TNT MPS library */
8 #include "tntMpsInternal.h"
9 
10 
17 unsigned tntMpsLength(tntNetwork mps)
18 {
19 
20  tntNode A; /* The current MPS node */
21  tntNode A_last; /* The last MPS node */
22  unsigned L = 0; /* The number of MPS nodes in the network */
23 
24  /* Loop through network determining the number of sites in the mps */
25  A = tntNodeFindFirst(mps);
26  A_last = tntNodeFindLast(mps);
27 
28  /* The loop will continue until the last site is reached - it will not be entered for a zero-length network */
29  while (NULL != A) {
30  /* Increment the number of sites in the network */
31  L++;
32 
33  /* If the last site has been reached, exit the loop, otherwise move to the next site */
34  if (A == A_last) {
35  break;
36  } else {
37  A = tntNodeFindConn(A, "R");
38  }
39 
40  }
41 
42  /* Return the number of sites in the MPS network */
43  return L;
44 
45 }
46 
51 tntIntArray tntMpsOpGetQN(tntNode op)
52 {
53  tntIntArray qnums_op, qnums_phys;
54  tntNode opc;
55 
56  /* First check whether the node is already covariant, if so simply send zeros */
57  if (tntNodeIsCovariant(op)) {
58 
59  qnums_op = tntIntArrayAlloc(tntSymmNumGet());
60 
61  } else {
62 
63  /* make a copy of the operator required */
64  /* Note: using right operator since the function tntNodeMakeCovariant() calculates QN for outgoing leg, and the right operator will be associated with the outgoing leg */
65  opc = tntNodeCopy(op,0);
66 
67  /* add a leg to it */
68  tntNodeAddLeg(opc, "R");
69 
70  /* Get the quantum numbers for the physical leg */
71  qnums_phys = tntNodeGetQN(tntSysBasisOpGet(),"D");
72 
73  /* assign quantum numbers to the physical legs */
74  tntNodeSetQN(opc,"D",&qnums_phys,TNT_QN_IN);
75  tntNodeSetQN(opc,"U",&qnums_phys,TNT_QN_OUT);
76 
77  /* assign quantum number label to the remaining singleton leg, where the leg is chosen to make the node invariant */
79 
80  /* get the quantum number label */
81  qnums_op = tntNodeGetQN(opc, "R");
82 
83  /* free the copy of the operator and the physical quantum numbers */
84  tntNodeFree(&opc);
85  tntIntArrayFree(&qnums_phys);
86  }
87 
88  return qnums_op;
89 }
90 
91 
98 {
99 
100  /* Free all the node arrays */
101  tntNodeArrayFree(&ExOp->ExOpOs);
102  tntNodeArrayFree(&ExOp->ExOp2nn);
103  tntNodeArrayFree(&ExOp->ExOp2cs);
104  tntNodeArrayFree(&ExOp->ExOp2ap);
105 
106  /* Free all the string arrays */
107  tntStringArrayFree(&ExOp->LbOpOs);
108  tntStringArrayFree(&ExOp->LbOp2nn);
109  tntStringArrayFree(&ExOp->LbOp2cs);
110  tntStringArrayFree(&ExOp->LbOp2ap);
111 
112 }
113 
123 tntNetwork tntMpsAdd(tntNetwork mpsA,
124  tntNetwork mpsB,
125  int orthresult)
126 {
127 
128  unsigned L, j;
129  tntNode A, B, C;
130  tntNetwork mpsC;
131 
132  L = tntMpsLength(mpsA);
133  mpsC = tntNetworkCreate();
134 
135  A = tntNodeFindFirst(mpsA);
136  B = tntNodeFindFirst(mpsB);
137 
138  C = tntNodeDirectSum(A, B, "R");
139 
140  tntNodeInsertAtEnd(C,"L","R",mpsC);
141 
142  for (j = 1; j < L-1; j++) {
143  A = tntNodeFindConn(A,"R");
144  B = tntNodeFindConn(B,"R");
145 
146  C = tntNodeDirectSum(A, B, "LR");
147 
148  tntNodeInsertAtEnd(C,"L","R",mpsC);
149  }
150 
151  A = tntNodeFindConn(A,"R");
152  B = tntNodeFindConn(B,"R");
153 
154  C = tntNodeDirectSum(A, B, "L");
155 
156  tntNodeInsertAtEnd(C,"L","R",mpsC);
157 
158  if (orthresult > -1)
159  tntMpsOrthNorm(mpsC,orthresult);
160 
161  return mpsC;
162 }
tntNode tntNodeCopy(tntNode A)
Definition: tntNodeUtil.c:304
#define tntMpsExOp
Definition: tntMps.h:75
void tntNodeArrayFree(tntNodeArray *arr)
Definition: tntArray.c:668
void tntNodeSetQN(tntNode A, tntLegLabel legA, tntIntArray *qvals, int legdir)
Definition: tntNodeQN.c:37
void tntMpsExOpFree(tntMpsExOp *ExOp)
Definition: tntMpsUtil.c:97
tntNode tntNodeDirectSum(tntNode A, tntNode B, tntLegLabel expandedLegs)
void tntStringArrayFree(tntStringArray *arr)
Definition: tntArray.c:684
tntNetwork tntNetworkCreate(void)
Definition: tntNetwork.c:92
tntNode tntNodeFindLast(tntNetwork nw)
Definition: tntNodeInfo.c:68
void tntNodeMakeCovariantQN(tntNode A)
Definition: tntNodeQN.c:204
unsigned tntSymmNumGet(void)
Definition: tntSys.c:512
void tntNodeInsertAtEnd(tntNode I, tntLegLabel legIlast, tntLegLabel legInwend, tntNetwork nw)
Definition: tntNodeConn.c:252
void tntNodeFree(tntNode *A)
Definition: tntNodeUtil.c:275
void tntMpsOrthNorm(tntNetwork mps, unsigned orth_centre)
Definition: tntMpsOrth.c:83
unsigned tntMpsLength(tntNetwork mps)
Definition: tntMpsUtil.c:17
unsigned tntNodeIsCovariant(tntNode A)
Definition: tntNodeInfo.c:535
tntIntArray tntNodeGetQN(tntNode A, tntLegLabel legA)
Definition: tntNodeQN.c:155
void tntIntArrayFree(tntIntArray *arr)
Definition: tntArray.c:620
void tntNodeAddLeg(tntNode A, tntLegLabel legA)
Definition: tntNodeConn.c:24
tntIntArray tntIntArrayAlloc(unsigned numrows, unsigned numcols)
Definition: tntArray.c:29
tntIntArray tntMpsOpGetQN(tntNode op)
Definition: tntMpsUtil.c:51
tntNode tntNodeFindConn(tntNode A, tntLegLabel legA)
Definition: tntNodeInfo.c:29
tntNode tntSysBasisOpGet(void)
Definition: tntSys.c:407
tntNode tntNodeFindFirst(tntNetwork nw)
Definition: tntNodeInfo.c:50
tntNetwork tntMpsAdd(tntNetwork mpsA, tntNetwork mpsB, int orthresult)
Definition: tntMpsUtil.c:123