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
tntMpsOptions.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 $LastChangedDate: 2016-04-21 11:59:27 +0100 (Thu, 21 Apr 2016) $
4 (c) University of Oxford 2013
5 */
6 
12 /* Include the header for the TNT library */
13 #include "tntMpsInternal.h"
14 
15 #include <getopt.h>
16 #include <ctype.h>
17 
61  char **argv,
62  int *numsteps,
63  int *tbigstep,
64  int *update_chi,
65  double *emax,
66  int *delta_chi,
67  int *max_chi)
68 {
69 
70 
71  static struct option long_options[] = {
72  {"timesteps", required_argument, 0, 't'},
73  {"tbigstep", required_argument, 0, 'b'},
74  {"trunc-type", required_argument, 0, 1},
75  {"update-chi", no_argument, 0, 'u'},
76  {"error-tol", required_argument, 0, 2},
77  {"delta-chi", required_argument, 0, 3},
78  {"max-chi", required_argument, 0, 4},
79  {"help-tebd", no_argument, 0, 5},
80  {0, 0, 0, 0}
81  };
82  int option_index;
83  int c;
84  char **argv_cp;
85 
86  /* Make a copy of argv - getopt_long will permute the arguments, and they may be required by another processing function */
87  argv_cp = (char **) malloc(argc*sizeof(char *));
88  for (c = 0; c<argc; c++) {
89  argv_cp[c] = argv[c];
90  }
91 
92  /* Set optind to 1 in case it has already been called previously */
93  optind = 1;
94 
95  /* Set opterr to zero to prevent error message for unknown erguments, since they may be being treated by another process options function */
96  opterr = 0;
97 
98  /* Set variables to a preset value, so can check if it is unset at the end */
99  if (numsteps != NULL) *numsteps = 0;
100  if (update_chi != NULL) *update_chi = 0;
101  if (tbigstep != NULL) *tbigstep = 0;
102  if (emax != NULL) *emax = -100.0;
103  if (delta_chi != NULL) *delta_chi = 0;
104  if (max_chi != NULL) *max_chi = 0;
105 
106  /* Loop over all input arguments */
107  while ((c = getopt_long (argc, argv_cp, "ht:b:u", long_options, &option_index)) != -1) {
108  switch (c) {
109  case 't':
110  if (numsteps != NULL) {
111  *numsteps = atoi(optarg);
112  tntPrintf("numsteps : <<<%d>>>\n", *numsteps);
113  }
114  break;
115  case 'b' :
116  if (tbigstep != NULL) {
117  *tbigstep = atoi(optarg);
118  tntPrintf("tbigstep: <<<%d>>>\n", *tbigstep);
119  }
120  break;
121  case 1 :
122  tntTruncType(optarg);
123  tntPrintf("Truncation errors will be calculated using %s.\n", optarg);
124  break;
125  case 'u' :
126  if (update_chi != NULL) {
127  *update_chi = 1;
128  tntPrintf("Enabling automatic chi updating based on truncation error.\n");
129  }
130  break;
131  case 2 :
132  if (emax != NULL) {
133  *emax = atof(optarg);
134  tntPrintf("Truncation error tolerance per sweep for updating chi set to <<<%7.2e>>>\n", *emax);
135  }
136  break;
137  case 3 :
138  if (delta_chi != NULL) {
139  *delta_chi = atoi(optarg);
140  tntPrintf("Amount by which to change chi when updating chi set to <<<%d>>>\n", *delta_chi);
141  }
142  break;
143  case 4 :
144  if (max_chi != NULL) {
145  *max_chi = atoi(optarg);
146  tntPrintf("Maximum value of chi to use when updating chi set to <<<%d>>>\n", *max_chi);
147  }
148  break;
149 /* START_NOCOV */
150  case 5 :
151  tntPrintf("\nOptions for TNT TEBD routines\n");
152  tntPrintf("--help-tebd | : Print this help.\n");
153  tntPrintf("--timesteps <n> | -t <n> : Number of timesteps to be performed. If not given default 50 is set. \n");
154  tntPrintf("--tbigstep <n> | -b <n> : Number of timesteps to be performed between each calculation of expectation values. \n");
155  tntPrintf(" If not given, then expectation values are calculated at the end of the routine only.\n");
156  tntPrintf("--trunc-type <str> | : How to calculate the truncation error using the discarded singular values.\n");
157  tntPrintf("--update-chi | -u : Update chi with increasing truncation error. Turned off by default. \n");
158  tntPrintf("--error-tol <val> | : Truncation error tolerance for increasing chi. Default is 1e-6. \n");
159  tntPrintf("--delta-chi | : Amount by which to increase chi. Default value 50. \n");
160  tntPrintf("--max-chi | : Value at which to stop increasing chi, even if the error exceeds error-tol. Default value 500. \n");
161 
162  free(argv_cp);
163 
164  tntFinalize();
165 
166  exit(0);
167 /* END_NOCOV */
168  default: /* '?' Do nothing since argument may be treated by another function */
169  break;
170  }
171 
172  }
173 
174 
175  /* Set unset variables to default values */
176  if ((numsteps != NULL ) && (0 == *numsteps)) {
177  *numsteps = 50;
178  tntPrintf("numsteps: Using default <<<%d>>>\n", *numsteps);
179  }
180  if ((tbigstep != NULL ) && (0 == *tbigstep)) {
181  *tbigstep = *numsteps;
182  tntPrintf("tbigstep: Using default <<<%d>>>\n", *tbigstep);
183  }
184  if ((update_chi != NULL) && (1 == *update_chi)) {
185  if ((emax != NULL) && (*emax < -99.0)) {
186  *emax = 1e-6;
187  tntPrintf("Truncation error tolerance per sweep for updating chi set to default <<<%7.2e>>>\n", *emax);
188  }
189  if ((delta_chi != NULL ) && (0 == *delta_chi)) {
190  *delta_chi = 50;
191  tntPrintf("Amount by which to change chi when updating chi set to default <<<%d>>>\n", *delta_chi);
192  }
193  if ((max_chi != NULL ) && (0 == *max_chi)) {
194  *max_chi = 500;
195  tntPrintf("Maximum value of chi to use when updating chi set to default <<<%d>>>\n", *max_chi);
196  }
197  }
198 
199  free(argv_cp);
200 
201  return;
202 }
203 
239  char **argv,
240  int *max_it,
241  double *precision)
243 {
244 
245  static struct option long_options[] = {
246  {"max-it", required_argument, 0, 1},
247  {"precision", required_argument, 0, 2},
248  {"trunc-type", required_argument, 0, 3},
249  {"max-eig-it", required_argument, 0, 4},
250  {"help-dmrg", no_argument, 0, 5},
251  {0, 0, 0, 0}
252  };
253  int option_index;
254  int c;
255  char **argv_cp;
256 
257  /* Make a copy of argv - getopt_long will permute the arguments, and they may be required by another processing function */
258  argv_cp = (char **) malloc(argc*sizeof(char *));
259  for (c = 0; c<argc; c++) {
260  argv_cp[c] = argv[c];
261  }
262 
263  /* Set optind to 1 in case it has already been called previously */
264  optind = 1;
265 
266  /* Set opterr to zero to prevent error message for unknown erguments, since they may be being treated by another process options function */
267  opterr = 0;
268 
269  /* Set variables to a preset value, so can check if it is unset at the end */
270  if (max_it != NULL) *max_it = 0;
271  if (precision != NULL) *precision = -100.0;
272 
273  /* Loop over all input arguments */
274  while ((c = getopt_long (argc, argv_cp, "", long_options, &option_index)) != -1) {
275  switch (c) {
276  case 1 :
277  if (max_it != NULL) {
278  *max_it = atoi(optarg);
279  tntPrintf("Maximum number of DMRG iterations <<<%d>>>\n", *max_it);
280  }
281  break;
282  case 2 :
283  if (precision != NULL) {
284  *precision = atof(optarg);
285  tntPrintf("Maximum difference in energy between DMRG iterations <<<%7.2e>>>\n", *precision);
286  }
287  break;
288  case 3 :
289  tntTruncType(optarg);
290  tntPrintf("Truncation errors will be calculated using %s.\n", optarg);
291  break;
292  case 4 :
293  tntMaxEigIterSet(atoi(optarg));
294  tntPrintf("Maximum number of iterations for eigenvalue solver <<<%d>>>\n", atoi(optarg));
295  break;
296 /* START_NOCOV */
297  case 5 :
298  tntPrintf("\nOptions for TNT DMRG routines\n");
299  tntPrintf("--help-dmrg | : Print this help.\n");
300  tntPrintf("--max-it <n> | : Maximum number of DMRG iterations. If not given default 50 is set. \n");
301  tntPrintf("--max-eig-it <n> | : Maximum number of iterations used by eigenvalue solver. \n");
302  tntPrintf("--precision <val> | : When energy difference between successive DMRG iterations is smaller than this value, the calculation ends. \n");
303  tntPrintf(" If not given default 1e-4 is used. \n");
304  tntPrintf("--trunc-type <str> | : How to calculate the truncation error using the discarded singular values.\n");
305 
306  free(argv_cp);
307 
308  tntFinalize();
309 
310  exit(0);
311 /* END_NOCOV */
312  default: /* '?' Do nothing since argument may be treated by another function */
313  break;
314  }
315 
316  }
317 
318 
319  /* Set unset variables to default values */
320  if ((max_it != NULL ) && (0 == *max_it)) {
321  *max_it = 50;
322  tntPrintf("max_it: Using default <<<%d>>>\n", *max_it);
323  }
324  if ((precision != NULL) && (*precision < -99.0)) {
325  *precision = 1e-4;
326  tntPrintf("precision: using default <<<%7.2e>>>\n", *precision);
327  }
328 
329  free(argv_cp);
330 
331  return;
332 
333 }
334 
void tntMpsProcessTebdCLOptions(int argc, char **argv, int *numsteps, int *tbigstep, int *update_chi, double *emax, int *delta_chi, int *max_chi)
Definition: tntMpsOptions.c:60
void tntMpsProcessDmrgCLOptions(int argc, char **argv, int *max_it, double *precision)
void tntMaxEigIterSet(int maxnum)
Definition: tntSys.c:232
void tntTruncType(const char *funcname)
Definition: tntSys.c:165
void tntFinalize(void)
Definition: tntSys.c:89
int tntPrintf(const char *format,...)
Definition: tntPrint.c:77