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
tntSys.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 Date: $LastChangedDate: 2015-10-30 18:48:42 +0000 (Fri, 30 Oct 2015) $
4 (c) University of Oxford 2014 */
5 
6 #include "../headers/tnt_int.h"
7 #include "../headers/dec_public.h"
8 #include "../headers/dec_tnode.h"
9 
12 tntSystem systype; /* Which system type has been chosen? */
13 
17 void tntInitialize(void)
18 {
19 
20  extern tntSystem systype;
21  int i;
22  extern struct tnt_error_info tnt_err;
23 
24  /* Print out the version number of the library */
26 
27  /* Initialise the system type */
28  systype.basisOp = NULL; /* No basis operator yet assigned */
29  systype.symm_type = TNT_SYMM_NONE; /* No symmetry type set yet */
30  systype.symm_num_qn = 0; /* No symmetry type set yet */
31 
32  /* Set the default parameters for SVDs and tolerances:
33  * Set the relative truncation tolerance to 1e-16
34  * SA has found that when it is not set, some numerical instabilities can come in
35  * e.g. finding ground states which are a product state
36  * and multiplying product state MPS with an MPO */
37  systype.rel_trunc_tol = 1.0e-16;
38  systype.abs_trunc_tol = -1.0;
39  systype.zero_tol = 1.0e-14;
40  systype.trunc_err_tol = -1.0;
41  systype.trunc_err_func = _tnt_matrix_trunc_2norm;
42 #ifdef TNTMAGMAAVAIL
43  systype.svdtype = TNT_MAGMA_SDD;
44 #else
45  systype.svdtype = TNT_LAPACK_SDD;
46 #endif
47  systype.reshape_reuse = 0;
48  systype.maxeigiter = 300;
49 
50  /* Print out the system information */
51  //_tnt_print_sysinfo("(default initial values)");
52 
53  /* Initialise error info */
54  tnt_err.numfuncs = 0;
55  for (i = 0; i < TNT_ERR_MAXFUNCNAMES; i++) {
56  tnt_err.funcnames[i] = malloc(TNT_ERR_MAXFUNCNAMESIZE*sizeof(char));
57  }
58  tnt_err.tnsr = NULL;
59  tnt_err.dblarray.vals = NULL;
60  tnt_err.cmparray.vals = NULL;
61  tnt_err.block = -1;
62  strcpy(tnt_err.outputfile,"");
63 
64  return;
65 }
66 
70 void tntSysInfoPrint(void) {
71  _tnt_print_sysinfo("");
72 }
73 
89 void tntFinalize(void)
90 {
91 
92  extern tntSystem systype;
93  extern struct tnt_error_info tnt_err;
94  extern double _tnt_num_tot_svd;
95  extern double _tnt_num_mag_zsdd;
96  extern double _tnt_num_lap_zsdd;
97  extern double _tnt_num_lap_zsvd;
98  extern double _tnt_num_mag_dsdd;
99  extern double _tnt_num_lap_dsdd;
100  extern double _tnt_num_lap_dsvd;
101  unsigned i;
102  double frac_sdd, frac_svd, frac_gpusdd;
103 
104  _tnt_tensor_reshape_free();
105 
106  if (NULL != systype.basisOp)
107  tntNodeFree(&systype.basisOp);
108 
109  for (i = 0; i < TNT_ERR_MAXFUNCNAMES; i++) {
110  free(tnt_err.funcnames[i]);
111  }
112  frac_sdd = 100*(_tnt_num_lap_zsdd+_tnt_num_lap_dsdd)/_tnt_num_tot_svd;
113  frac_svd = 100*(_tnt_num_lap_zsvd+_tnt_num_lap_dsvd)/_tnt_num_tot_svd;
114  frac_gpusdd = 100*(_tnt_num_mag_zsdd+_tnt_num_mag_dsdd)/_tnt_num_tot_svd;
115  _tnt_printf("%g SVDs performed during the routine: %g%% SDD, %g%% SVD, %g%% GPU SDD.\n", _tnt_num_tot_svd, frac_sdd, frac_svd, frac_gpusdd);
116 
117  return;
118 }
119 
165 void tntTruncType(const char *funcname)
166 {
167  extern tntSystem systype;
168  char err_msg[TNT_STRLEN];
169  TNT_ERR_RET_DEFS
170 
171  ret = _tnt_trunctype_set(funcname);
172  if (TNT_SUCCESS != ret) {
173  sprintf(err_msg, "Error setting truncation type: - truncation function %s unknown",funcname); /*NO_COVERAGE */
174  sprintf(tnt_err.errinfostr,"%s",err_msg); /* NO_COVERAGE */
175  sprintf(tnt_err.pubfuncname,__FUNCTION__); /* NO_COVERAGE */
176  _tnt_print_error(); /* NO_COVERAGE */
177  }
178 
179  _tnt_printf("The current truncation type is %s.\n",funcname);
180 
181  return;
182 }
183 
192 void tntSVDTolSet(double inpTOL)
193 {
194  extern tntSystem systype;
195 
196  systype.zero_tol = inpTOL;
197 
198  return;
199 }
200 
206 double tntSVDTolGet(void)
207 {
208  extern tntSystem systype;
209 
210  return systype.zero_tol;
211 }
212 
221 void tntSVDRoutineSet(int svdtype)
222 {
223  extern tntSystem systype;
224 
225  systype.svdtype = svdtype;
226 }
227 
232 void tntMaxEigIterSet(int maxnum)
233 {
234  extern tntSystem systype;
235 
236  systype.maxeigiter = maxnum;
237 }
238 
253 void tntSVDTruncTolSet(double truncTol)
254 {
255  extern tntSystem systype;
256 
257  systype.abs_trunc_tol = truncTol;
258 }
259 
273 void tntSVDRelTruncTolSet(double relTruncTol)
274 {
275  extern tntSystem systype;
276 
277  systype.rel_trunc_tol = relTruncTol;
278 }
279 
293 void tntSVDTruncErrTolSet(double truncErrTol)
294 {
295  extern tntSystem systype;
296 
297  systype.trunc_err_tol = truncErrTol;
298 }
299 
300 
312 double tntSVDTruncTolGet(void)
313 {
314  extern tntSystem systype;
315 
316  return systype.abs_trunc_tol;
317 }
318 
330 double tntSVDRelTruncTolGet(void)
331 {
332  extern tntSystem systype;
333 
334  return systype.rel_trunc_tol;
335 }
336 
337 
347 double tntSVDTruncErrTolGet(void)
348 {
349  extern tntSystem systype;
350 
351  return systype.trunc_err_tol;
352 }
353 
361 void tntSysTypeSet(int sysnum)
362 {
363  extern tntSystem systype; /* Internal decleration of global variable for system type */
364 
365  systype.sysnum = sysnum;
366 
367 }
368 
376 int tntSysTypeGet(void) {
377 
378  extern tntSystem systype; /* Internal decleration of global variable for system type */
379 
380  return systype.sysnum;
381 }
382 
389 void tntSysBasisOpSet(tntNode basisOp)
390 {
391  TNT_ERR_RET_DEFS
392  extern tntSystem systype; /* Internal decleration of global variable for system type */
393 
394  ret = _tnt_tnode_copy(&(systype.basisOp),basisOp, 0);
395  TNT_PUB_ERR_CHK /* NO_COVERAGE */
396 
397 }
398 
407 tntNode tntSysBasisOpGet(void) {
408 
409  extern tntSystem systype; /* Internal decleration of global variable for system type */
410 
411  return systype.basisOp;
412 }
413 
417 void tntSysBasisOpFree(void) {
418 
419  TNT_ERR_RET_DEFS
420  extern tntSystem systype; /* Internal decleration of global variable for system type */
421 
422  ret = _tnt_tnode_free(&systype.basisOp);
423  TNT_PUB_ERR_CHK /* NO_COVERAGE */
424 }
425 
439 void tntSymmTypeSet(const char *symmTypeStr,
440  unsigned num_qn)
441 {
442  TNT_ERR_RET_DEFS
443  char msg[TNT_STRLEN]; /* Error or warning message */
444 
445  if (0 == strcmp("U(1)",symmTypeStr)) {
446  ret = _tnt_symmtypeset(TNT_SYMM_U1, num_qn);
447  TNT_PUB_ERR_CHK /* NO_COVERAGE */
448 
449  } else { /* NO_COVERAGE */
450  sprintf(msg,"Symmetry type %s is not recognised or is not yet supported. No symmetry is being applied.\n", symmTypeStr); /* NO_COVERAGE */
451  tntWarningPrint(msg); /* NO_COVERAGE */
452  } /* NO_COVERAGE */
453 
454 }
455 
470 {
471  extern tntSystem systype; /* Internal decleration of global variable for system type */
472  TNT_ERR_RET_DEFS /* Return value from tnt internal functions */
473 
474  /* Only do someting if the symmetry type is currently set anyway */
475  if (TNT_SYMM_NONE != tntSymmTypeGet()) {
476  tntNode basisOp = tntSysBasisOpGet();
477 
478  systype.symm_type = TNT_SYMM_NONE;
479  systype.symm_num_qn = 0;
480  tntSVDTolSet(TNT_DEFAULT_TOL);
481 
482  if (basisOp != NULL) {
483  ret = _tnt_tnode_clearqn(basisOp);
484  TNT_PUB_ERR_CHK /* NO_COVERAGE */
485  }
486  }
487 }
488 
498 int tntSymmTypeGet(void) {
499 
500  extern tntSystem systype; /* Internal decleration of global variable for system type */
501 
502  return systype.symm_type;
503 }
504 
512 unsigned tntSymmNumGet(void) {
513 
514  extern tntSystem systype; /* Internal decleration of global variable for system type */
515 
516  return systype.symm_num_qn;
517 }
518 
519 
520 
533 {
534  TNT_ERR_RET_DEFS /* Return value from tnt internal functions */
535 
536  ret = reshape_reuse_disable();
537  TNT_PUB_ERR_CHK /* NO_COVERAGE */
538 }
539 
550 {
551  TNT_ERR_RET_DEFS /* Return value from tnt internal functions */
552 
553  ret = reshape_reuse_enable();
554  TNT_PUB_ERR_CHK /* NO_COVERAGE */
555 }
void tntSysInfoPrint(void)
Definition: tntSys.c:70
void tntReshapeReuseDisable(void)
Definition: tntSys.c:532
int tntSysTypeGet(void)
Definition: tntSys.c:376
tntSystem systype
Definition: tntSys.c:12
unsigned tntSymmNumGet(void)
Definition: tntSys.c:512
void tntSVDTolSet(double inpTOL)
Definition: tntSys.c:192
void tntSVDRoutineSet(int svdtype)
Definition: tntSys.c:221
void tntSVDTruncErrTolSet(double truncErrTol)
Definition: tntSys.c:293
void tntMaxEigIterSet(int maxnum)
Definition: tntSys.c:232
void tntSVDTruncTolSet(double truncTol)
Definition: tntSys.c:253
void tntSysTypeSet(int sysnum)
Definition: tntSys.c:361
void tntSVDRelTruncTolSet(double relTruncTol)
Definition: tntSys.c:273
void tntTruncType(const char *funcname)
Definition: tntSys.c:165
void tntSymmTypeUnset(void)
Definition: tntSys.c:469
void tntNodeFree(tntNode *A)
Definition: tntNodeUtil.c:275
double tntSVDTolGet(void)
Definition: tntSys.c:206
double tntSVDTruncTolGet(void)
Definition: tntSys.c:312
void tntSymmTypeSet(const char *symmTypeStr, unsigned num_qn)
Definition: tntSys.c:439
void tntFinalize(void)
Definition: tntSys.c:89
void tntReshapeReuseEnable(void)
Definition: tntSys.c:549
tntNode tntSysBasisOpGet(void)
Definition: tntSys.c:407
void tntSysBasisOpSet(tntNode basisOp)
Definition: tntSys.c:389
double tntSVDTruncErrTolGet(void)
Definition: tntSys.c:347
void tntPrintVersion(void)
Definition: tntUtil.c:64
int tntSymmTypeGet(void)
Definition: tntSys.c:498
void tntInitialize(void)
Definition: tntSys.c:17
void tntSysBasisOpFree(void)
Definition: tntSys.c:417
double tntSVDRelTruncTolGet(void)
Definition: tntSys.c:330