Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
tntMpsCreateRandom.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
31 tntNetwork tntMpsCreateRandom(unsigned L,
32  unsigned D)
33 {
34
35  tntNetwork mps; /* The mps network to create */
36  tntNode A, U; /* The current node, unitary node */
37  unsigned d, Dr=1; /* Dimension of the physical leg and the right internal leg */
38  unsigned loop; /* used for looping */
39  double normsq; /* Norm squared */
40
41  /* First create the empty network */
42  mps = tntNetworkCreate();
43
44  /* Get the dimension of the physical leg */
45  if (NULL == tntSysBasisOpGet()) {
46  tntErrorPrint("Cannot create random wave function as the basis operator for the system has not yet been set"); /* NO_COVERAGE */
47  } else { /* NO_COVERAGE */
49  }
50
51  /* Keep inserting random nodes at the start, making sure all nodes are right orthonormalised. */
52  for (loop = 0; loop < L-1; loop++) {
53
54  /* Create the node */
55  A = tntNodeCreate(NULL, "LRD", D, Dr, d);
56
57  /* Take an untruncated SVD of the node to make it right orthonormalised */
58  U = tntNodeSVD(A, "RD", "L", "R", "L", "R", -1, NULL);
59
60  /* Get the dimension of the left leg (which may be different from D due to truncation tolerances) */
61  /* This will be the dimension of the right leg of the next node to insert */
62  Dr = tntNodeGetLegDim(U, "L");
63
64  /* Insert a copy of the node into the network */
65  A = tntNodeCopy(U);
66  tntNodeInsertAtStart(A, "L", "R", mps);
67
68  /* Discard the U, S, V */
69  tntNodeGroupFree(&U);
70  }
71
72  /* Insert the left-most node, which will contain the orthogonality twist */
73  A = tntNodeCreate(NULL, "LRD", 1, Dr, d);
74  tntNodeInsertAtStart(A, "L", "R", mps);
75
76  /* Find the norm of the network */
77  normsq = tntMpsSelfProduct(mps,0);
78
79  /* Divide the first node by the square root of the norm */
80  tntNodeScaleReal(A,1.0/sqrt(normsq));
81
82  return mps;
83 }
tntNode tntNodeCopy(tntNode A)
Definition: tntNodeUtil.c:304
void tntNodeGroupFree(tntNode *A)
Definition: tntNodeUtil.c:288
tntNetwork tntNetworkCreate(void)
Definition: tntNetwork.c:92
tntNode tntNodeSVD(tntNode A, tntLegLabel Ulegs, tntLegLabel legUS, tntLegLabel legSU, tntLegLabel legSV, tntLegLabel legVS, int chi, double *err, tntLegLabel legmap)
double tntMpsSelfProduct(tntNetwork mps, int orth_centre)
Definition: tntMpsMps.c:544
tntNetwork tntMpsCreateRandom(unsigned L, unsigned D)
tntNode tntSysBasisOpGet(void)
Definition: tntSys.c:407
tntNode tntNodeCreate(tntComplexArray *nodeVals, tntLegLabel leglabels, unsigned dimleg1, unsigned dim...)
Definition: tntNodeUtil.c:354
void tntNodeScaleReal(tntNode A, double val)
void tntNodeInsertAtStart(tntNode I, tntLegLabel legInwstart, tntLegLabel legIfirst, tntNetwork nw)
Definition: tntNodeConn.c:213
unsigned tntNodeGetLegDim(tntNode A, tntLegLabel legA)
Definition: tntNodeInfo.c:246