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
tntMpsCreateConfig.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 $LastChangedDate$
4 (c) University of Oxford 2014
5 */
6 
7 /* Include the header for the TNT library */
8 #include "tntMpsInternal.h"
9 
35 tntNetwork tntMpsCreateConfig(unsigned L,
36  const char *config)
37 {
38 
40  tntNetwork mps; /* The mps network to create */
41  tntNode A; /* The current node */
42  tntComplexArray Aarr;
43  unsigned loop;
44  unsigned d; /* Dimension of the physical leg */
45  tntIntArray qnums_phys, qnums_int; /* Quantum numbers for the physical leg, and for the internal legs (1 internal leg only) */
46  unsigned config_length; /* Number of characters in the configuration */
47  unsigned bs; /* State for the current site */
48 
49  /* Get the dimension of the physical leg */
50  if (NULL == tntSysBasisOpGet()) {
51  tntErrorPrint("Cannot create wave function using configuration as the basis operator for the system has not yet been set"); /* NO_COVERAGE */
52  } else { /* NO_COVERAGE */
54  }
55 
56  /* Create the empty network */
57  mps = tntNetworkCreate();
58 
59  /* Get the quantum numbers for the physical leg and initialise internal QNs */
60  if (tntSymmTypeGet()) {
61  qnums_phys = tntNodeGetQN(tntSysBasisOpGet(), "D");
62  qnums_int = tntIntArrayAlloc(tntSymmNumGet());
63  }
64 
65  /* Initialise array for holding node values */
66  Aarr = tntComplexArrayAlloc(d);
67 
68  /* Find the length of the provided configuration */
69  config_length = _tnt_strlen(config);
70 
71  /* Keep inserting nodes at the end. */
72  for (loop = 0; loop < L; loop++) {
73 
74  /* Find the non-zero entry using the character array, and convert the single character to an integer */
75  /* If loop is larger than character array, then fill with 0 instead */
76  if (loop < config_length) {
77  bs = (unsigned) config[loop] - '0';
78 
79  /* Check that the basis is valid */
80  if (bs > d-1) tntErrorPrint("Invalid configuration %s|The character %d is larger than the physical dimension (%d) allows.",config,bs,d); /* NO_COVERAGE */
81 
82  } else {
83  bs = 0;
84  }
85 
86  /* Set the value in the array to form the node */
87  Aarr.vals[bs].re = 1.0;
88 
89  /* Create the node */
90  A = tntNodeCreate(&Aarr, "DLR", d);
91 
92  /* Insert the node in the network */
93  tntNodeInsertAtEnd(A, "L", "R", mps);
94 
95  /* Set the array back to all zeros */
96  Aarr.vals[bs].re = 0.0;
97 
98  /* Now set the quantum number information if there are symmetries in the sysem: */
99  if (TNT_SYMM_U1 == tntSymmTypeGet()) {
100  /* Physical leg is incoming leg and has same information as operator */
101  tntNodeSetQN(A,"D",&qnums_phys,TNT_QN_IN);
102 
103  /* Left leg is incoming leg, and has value = to current total charge */
104  tntNodeSetQN(A,"L",&qnums_int,TNT_QN_IN);
105 
106  /* make the node invariant, this will set QNs on the right internal leg (the only remaining leg that does not have QNs set) as an outgoing leg */
108 
109  /* Get the quantum numbers on the leg (freeing previous values first) */
110  tntIntArrayFree(&qnums_int);
111  qnums_int = tntNodeGetQN(A, "R");
112  }
113 
114  }
115 
116  /* Free the array for holding array values */
117  tntComplexArrayFree(&Aarr);
118 
119  /* Free the qn information if it was used */
120  if (TNT_SYMM_U1 == tntSymmTypeGet()) {
121  tntIntArrayFree(&qnums_phys);
122  tntIntArrayFree(&qnums_int);
123  }
124 
125  /* return the completed matrix product state */
126  return mps;
127 }
void tntNodeSetQN(tntNode A, tntLegLabel legA, tntIntArray *qvals, int legdir)
Definition: tntNodeQN.c:37
tntNetwork tntNetworkCreate(void)
Definition: tntNetwork.c:92
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
tntComplexArray tntComplexArrayAlloc(unsigned numrows, unsigned numcols)
Definition: tntArray.c:392
tntNetwork tntMpsCreateConfig(unsigned L, const char *config)
tntIntArray tntNodeGetQN(tntNode A, tntLegLabel legA)
Definition: tntNodeQN.c:155
void tntIntArrayFree(tntIntArray *arr)
Definition: tntArray.c:620
tntIntArray tntIntArrayAlloc(unsigned numrows, unsigned numcols)
Definition: tntArray.c:29
tntNode tntSysBasisOpGet(void)
Definition: tntSys.c:407
tntNode tntNodeCreate(tntComplexArray *nodeVals, tntLegLabel leglabels, unsigned dimleg1, unsigned dim...)
Definition: tntNodeUtil.c:354
void tntComplexArrayFree(tntComplexArray *arr)
Definition: tntArray.c:650
int tntSymmTypeGet(void)
Definition: tntSys.c:498
unsigned tntNodeGetLegDim(tntNode A, tntLegLabel legA)
Definition: tntNodeInfo.c:246