Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
tntMpoTrace.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 $LastChangedDate: 2015-04-09 18:57:36 +0100 (Thu, 09 Apr 2015)$
4 (c) University of Oxford 2014
5 */
6
12 /* Include the header for the TNT MPS library */
13 #include "tntMpsInternal.h"
14
15
20 tntComplex tntMpoTrace(tntNetwork mpo)
21 {
22
23  tntNode M, alpha; /* The current MPO node, and the contracted MPO node */
24  tntNetwork mpoc; /* The copy of the MPO */
25  unsigned L, j; /* The number of MPO nodes in the network, and the site count */
26
27  /* Final results */
28  tntComplex contracted; /* The contracted network */
29
30  /* Determine the length of the MPO. */
31  L = tntMpoLength(mpo);
32
33  /* Make a copy of the MPO for contracting */
34  mpoc = tntNetworkCopy(mpo);
35
36  /* First loop through the network contracting away all the physical legs */
37  for (j = 0; j < L; j++) {
38  if (0 == j) M = tntNodeFindFirst(mpoc);
39  else M = tntNodeFindConn(M, "R");
40
41  /* Join the physical legs */
42  tntNodeJoin(M, "D", M, "U");
43
44  /* Perform the contraction */
45  tntNodeSelfContract(&M);
46
47  }
48
49  /* Now contract all the nodes together */
50  alpha = tntNodeFindFirst(mpoc);
51
52  /* Go through remaining sites, contracting them with alpha one by one */
53  for (j = 1; j < L; j++) {
54
55  /* Find the next node along in the unflipped wave function */
56  M = tntNodeFindConn(alpha, "R");
57
58  /* Contract alpha with M */
59  alpha = tntNodeContract(alpha,M);
60
61  }
62
63  /* Get the one remaining element */
64  contracted = tntNodeGetFirstEl(alpha);
65
66  /* Free the network */
67  tntNetworkFree(&mpoc);
68
69  /* Return the result of the contraction */
70  return contracted;
71
72 }
void tntNetworkFree(tntNetwork *nwp)
Definition: tntNetwork.c:118
void tntNodeJoin(tntNode A, tntLegLabel legA, tntNode B, tntLegLabel legB)
Definition: tntNodeConn.c:52
tntComplex tntMpoTrace(tntNetwork mpo)
Definition: tntMpoTrace.c:20
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 tntNodeGetFirstEl(tntNode A)
Definition: tntNodeInfo.c:86