-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.cpp
566 lines (466 loc) · 16.5 KB
/
options.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
/*
* Copyright (c) 2013, Robert Rueger <[email protected]>
*
* This file is part of hVMC.
*
* hVMC is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* hVMC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with hVMC. If not, see <http://www.gnu.org/licenses/>.
*/
#include "options.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
#include <boost/program_options.hpp>
#include <boost/filesystem/path.hpp>
#include "analysis.hpp"
#include "obs.hpp"
#include "lattice.hpp"
#include "utils.hpp"
using namespace std;
namespace po = boost::program_options;
namespace fs = boost::filesystem;
Options read_options( int argc, char* argv[], bool is_master )
{
Options vm;
// define command line only options
po::options_description clionly( "command line options" );
clionly.add_options()
( "help,h", "print this help message and exit" )
( "version,V", "print hVMC's version and exit" )
( "verbose,v", "makes hVMC write additional information to stdout and disk" )
( "job-file,J", po::value<fs::path>(), "job file to execute" );
po::positional_options_description p;
p.add( "job-file", -1 );
// define command line and jobfile options
po::options_description physparam( "physical parameters" );
physparam.add_options()
( "phys.nn-hopping,1",
po::value<double>()->required(),
"nearest neighbor hopping matrix element t" )
( "phys.2nd-nn-hopping,2",
po::value<double>()->default_value( 0.0 ),
"2nd nearest neighbor hopping matrix element t'" )
( "phys.3rd-nn-hopping,3",
po::value<double>()->default_value( 0.0 ),
"3rd nearest neighbor hopping matrix element t''" )
( "phys.onsite-energy,U",
po::value<double>()->required(),
"on-site energy U" )
( "phys.lattice,l",
po::value<Lattice::type>()->required(),
"lattice type (1dchain, 2dsquare, 2dsquare2layer)" )
( "phys.num-lattice-sites,L",
po::value<unsigned int>()->required(),
"number of lattice sites" )
( "phys.num-electrons,N",
po::value<unsigned int>()->required(),
"total number of electrons" )
( "phys.pairing-symmetry,y",
po::value<optpairsym_t>()->default_value( OPTION_PAIRING_SYMMETRY_SWAVE ),
"symmetry of the pairing term (swave, dwave, dwave_twisted)" )
( "phys.vpar-file,P",
po::value<fs::path>(),
"file to load the variational parameters from" )
( "phys.vpar-ovwrt-t2",
po::value<double>(),
"variational parameter overwrite: t'" )
( "phys.vpar-ovwrt-t3",
po::value<double>(),
"variational parameter overwrite: t''" )
( "phys.vpar-ovwrt-D0",
po::value<double>(),
"variational parameter overwrite: Delta_onsite" )
( "phys.vpar-ovwrt-D1",
po::value<double>(),
"variational parameter overwrite: Delta" )
( "phys.vpar-ovwrt-D2",
po::value<double>(),
"variational parameter overwrite: Delta'" )
( "phys.vpar-ovwrt-D3",
po::value<double>(),
"variational parameter overwrite: Delta""'" )
( "phys.vpar-ovwrt-mu",
po::value<double>(),
"variational parameter overwrite: mu" )
( "phys.vpar-ovwrt-mu-m",
po::value<double>(),
"variational parameter overwrite: mu_m" )
( "phys.vpar-ovwrt-J0",
po::value<double>(),
"variational parameter overwrite: J_00" );
po::options_description calcset( "calculation settings" );
calcset.add_options()
( "calc.mode,m",
po::value<optmode_t>()->required(),
"mode (optimization, simulation, analysis)" )
( "calc.working-dir,D",
po::value<fs::path>()->default_value( "." ),
"[opt+sim+ana]: input/output directory" )
( "calc.observable,O",
po::value< std::vector<observables_t> >(),
"[sim]: measured observables "
"(E, Dk, DkDkp, DkE, dblocc, nncorr, sscorr, pconfs)" )
( "calc.analysis,A",
po::value< std::vector<analysis_t> >(),
"[ana]: selected analysis modules (ssfac)" )
( "calc.update-hop-maxdistance,H",
po::value<unsigned int>()->default_value( 1 ),
"[opt+sim]: maximum hopping distance for electronic configuration updates" )
( "calc.num-mcs-equil,E",
po::value<unsigned int>()->default_value( 100 ),
"[opt+sim]: number of Monte Carlo steps for equilibration" )
( "calc.num-bins,B",
po::value<unsigned int>()->default_value( 50 ),
"[opt+sim]: number of measurement bins" )
( "calc.num-binmcs,M",
po::value<unsigned int>()->default_value( 50 ),
"[opt+sim]: number of Monte Carlo steps per bin" )
( "calc.rng-seed,S",
po::value<unsigned int>(),
"[opt+sim]: random number generator seed" )
( "calc.optimizers,Z",
po::value<unsigned int>()->default_value( 511 ),
"[opt]: which variational parameters to optimize" )
( "calc.sr-dt,d",
po::value<double>()->default_value( 1.0 ),
"[opt]: controls the SR convergence: vpar += dt * dvpar" )
( "calc.sr-dt-Jboost,J",
po::value<double>()->default_value( 1.0 ),
"[opt]: factor to boost the convergence speed of the Jastrow" )
( "calc.sr-mkthreshold,T",
po::value<double>()->default_value( 0.5 ),
"[opt]: Mann-Kendall threshold for convergence detection" )
( "calc.sr-max-refinements,R",
po::value<unsigned int>()->default_value( 4 ),
"[opt]: number of refinements during the SR cycle" )
( "calc.sr-averaging-cycles,A",
po::value<unsigned int>()->default_value( 10 ),
"[opt]: number of SR cycles to average the converged variational parameters" )
( "calc.vpar-minabs-select",
po::value<unsigned int>()->default_value( 0 ),
"[opt]: variational parameters that have a fixed minimum absolute value" )
( "calc.vpar-minabs-value",
po::value<double>()->default_value( 0.001 ),
"[opt]: fixed minimum absolute value for the selected parameters" );
po::options_description fpctrl( "[opt+sim]: floating point precision control" );
fpctrl.add_options()
( "fpctrl.W-deviation-target",
po::value<double>()->default_value( 0.001, "0.001" ),
"deviation target for the matrix W" )
( "fpctrl.W-updates-until-recalc",
po::value<unsigned int>()
#ifdef USE_FP_DBLPREC
->default_value( 5000 ),
#else
->default_value( 500 ),
#endif
"number of quick updates until recalculation of the matrix W" )
( "fpctrl.T-deviation-target",
po::value<double>()->default_value( 0.001, "0.001" ),
"deviation target for the vector T" )
( "fpctrl.T-updates-until-recalc",
po::value<unsigned int>()->default_value( 500000 ),
"number of quick updates until recalculation of the vector T" );
// define option groups for cli and jobfile
po::options_description cmdline_options;
cmdline_options.add( clionly ).add( physparam ).add( calcset ).add( fpctrl );
po::options_description jobfile_options;
jobfile_options.add( physparam ).add( calcset ).add( fpctrl );
try {
// parse options from the command line
if ( is_master ) {
cout << ":: Parsing command line ..." << endl;
}
po::store( po::command_line_parser( argc, argv ).
options( cmdline_options ).positional( p ).run(), vm );
} catch ( const po::error& e ) {
if ( is_master ) {
cerr << "Error while parsing the command line: " << e.what() << endl;
}
exit( 1 );
}
// display help or hVMC version information
if ( vm.count( "help" ) ) {
if ( is_master ) {
cout << endl;
cout << "usage: hVMC [OPTIONS] JOBFILE -o OUTDIR" << endl;
cout << cmdline_options << endl;
}
exit( 0 );
}
if ( vm.count( "version" ) ) {
if ( is_master ) {
cout << endl;
cout << "hVMC - built from git commit " << GIT_HASH << endl;
#ifndef NDEBUG
cout << "=========== DEBUG BUILD ============" << endl;
#else
cout << "========== RELEASE BUILD ===========" << endl;
#endif
cout << "compiled " << __DATE__ " with ";
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
# if defined(__GNUC_PATCHLEVEL__)
cout << "GCC " << __GNUC__ << "." << __GNUC_MINOR__
<< "." << __GNUC_PATCHLEVEL__;
# else
cout << "GCC " << __GNUC__ << "." << __GNUC_MINOR__;
# endif
#elif defined(__INTEL_COMPILER)
cout << "ICC " << __INTEL_COMPILER;
#elif defined(_MSC_VER)
cout << "MSC " << _MSC_VER;
#else
cout << "unknown compiler";
#endif
cout << endl;
#ifdef USE_FP_DBLPREC
cout << "WMatrix implementation: double prec." << endl;
#else
cout << "WMatrix implementation: single prec." << endl;
#endif
#ifdef USE_CBLAS
cout << "external CBLAS: enabled" << endl;
#else
cout << "external CBLAS: disabled" << endl;
#endif
#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
cout << "matrix storage order: row major" << endl;
#else
cout << "matrix storage order: column major" << endl;
#endif
cout << endl;
cout
<< "Copyright (C) 2013, Robert Rueger <[email protected]>"
<< endl
<< "License GPLv3+: GNU GPL version 3 or later"
" <http://gnu.org/licenses/gpl.html>" << endl
<< "This is free software: you are free to change and redistribute it."
<< endl
<< "There is NO WARRANTY, to the extent permitted by law."
<< endl << endl;
}
exit( 0 );
}
if ( vm.count( "job-file" ) ) {
// parse the jobfile
if ( is_master ) {
cout << ":: Parsing jobfile ..." << endl;
}
ifstream jobifs( vm["job-file"].as<fs::path>().string() );
if ( jobifs.is_open() ) {
try {
po::store( po::parse_config_file( jobifs, jobfile_options ), vm );
} catch ( const po::error& e ) {
if ( is_master ) {
cerr << "Error while parsing the job file: " << e.what() << endl;
}
exit( 1 );
}
} else {
if ( is_master ) {
cerr << "Error: unable to open jobfile " << vm["job-file"].as<string>()
<< endl;
}
exit( 1 );
}
}
try {
// finalize the variable map
// (will throw exception on missing options)
po::notify( vm );
} catch ( const po::error& e ) {
if ( is_master ) {
cerr << "Error in program options: " << e.what() << endl;
}
exit( 1 );
}
// manual modifications of the options
// set phys.vpar-file to working dir / opt_vpar_final.dat
// (can't be a default value because the working dir is not known
// before the command line is parsed)
// (insert will do nothing if vpar-file is already set ...)
vm.insert(
make_pair(
"phys.vpar-file",
po::variable_value(
vm["calc.working-dir"].as<fs::path>() / "opt_vpar_final.dat",
true
)
)
);
// check for logical errors in the physical parameters
try {
if ( vm["phys.num-electrons"].as<unsigned int>() % 2 != 0 ) {
throw logic_error( "electron number must be even" );
}
if ( vm["phys.num-electrons"].as<unsigned int>() >
2 * vm["phys.num-lattice-sites"].as<unsigned int>() ) {
throw logic_error(
"too many electrons (num-electrons > 2 * num-lattice-sites) "
);
}
if ( vm["phys.lattice"].as<Lattice::type>() == Lattice::type::square2d &&
!is_perfect_square( vm["phys.num-lattice-sites"].as<unsigned int>() ) ) {
throw logic_error( "the number of lattice sites must be a perfect square" );
}
if ( vm["phys.lattice"].as<Lattice::type>() == Lattice::type::square2d2layer &&
!is_perfect_square( vm["phys.num-lattice-sites"].as<unsigned int>() / 2 ) ) {
throw logic_error(
"the number of lattice sites must be two times a perfect square"
);
}
if ( vm["phys.lattice"].as<Lattice::type>() == Lattice::type::square2d2layer &&
vm["phys.3rd-nn-hopping"].as<double>() == 0.0 ) {
throw logic_error(
"running the square lattice bilayer model with no interplane hopping does not make sense, use the monolayer instead"
);
}
// TODO: minimum lattice size checks (Robert Rueger, 2012-11-17 22:57)
} catch ( const logic_error& e ) {
if ( is_master ) {
cerr << "Logical error in physical parameters: " << e.what() << endl;
}
exit( 1 );
}
// check for logical errors in the calculation settings
try {
if ( vm["calc.update-hop-maxdistance"].as<unsigned int>() == 0 ) {
throw logic_error(
"electronic configuration updates need at least nearest neighbor hopping"
);
}
if ( vm["calc.update-hop-maxdistance"].as<unsigned int>() > 3 ) {
throw logic_error(
"electronic configuration updates with hopping > 3rd nearest neighbors"
"are not supported"
);
}
if ( vm["calc.mode"].as<optmode_t>() == OPTION_MODE_OPTIMIZATION &&
vm["calc.optimizers"].as<unsigned int>() == 0 ) {
throw logic_error( "you need to optimize at least one variational parameter" );
}
if ( vm["calc.mode"].as<optmode_t>() == OPTION_MODE_OPTIMIZATION &&
vm["calc.optimizers"].as<unsigned int>() > 511 ) {
throw logic_error(
"hVMC only has 8+Jastrow variational parameters "
"-> calc.optimizers can not be larger than 511"
);
}
if ( vm["calc.mode"].as<optmode_t>() == OPTION_MODE_OPTIMIZATION &&
vm["calc.vpar-minabs-select"].as<unsigned int>() > 255 ) {
throw logic_error(
"the minimum vpar threshold is only intended for the det. parameters "
"-> calc.vpar-minabs-select can not be larger than 255"
);
}
if ( vm["calc.mode"].as<optmode_t>() == OPTION_MODE_SIMULATION &&
vm.count( "calc.observable" ) == 0 ) {
throw logic_error( "you need to measure at least one observable" );
}
if ( vm["calc.mode"].as<optmode_t>() == OPTION_MODE_ANALYSIS &&
vm.count( "calc.analysis" ) == 0 ) {
throw logic_error( "you need to select at least one analysis module" );
}
} catch ( const logic_error& e ) {
if ( is_master ) {
cerr << "Logical error in calculation settings: " << e.what() << endl;
}
exit( 1 );
}
if ( is_master ) {
cout << endl;
}
return vm;
}
istream& operator>>( std::istream& in, Lattice::type& lat )
{
string token;
in >> token;
if ( token == "1dchain" ) {
lat = Lattice::type::chain1d;
} else if ( token == "2dsquare" ) {
lat = Lattice::type::square2d;
} else if ( token == "2dsquare2layer" ) {
lat = Lattice::type::square2d2layer;
} else {
throw po::validation_error( po::validation_error::invalid_option_value );
}
return in;
}
istream& operator>>( std::istream& in, optmode_t& m )
{
string token;
in >> token;
if ( token == "opt" || token == "optimization" ) {
m = OPTION_MODE_OPTIMIZATION;
} else if ( token == "sim" || token == "simulation" ) {
m = OPTION_MODE_SIMULATION;
} else if ( token == "ana" || token == "analysis" ) {
m = OPTION_MODE_ANALYSIS;
} else {
throw po::validation_error( po::validation_error::invalid_option_value );
}
return in;
}
istream& operator>>( std::istream& in, optpairsym_t& s )
{
string token;
in >> token;
if ( token == "s" || token == "swave" ) {
s = OPTION_PAIRING_SYMMETRY_SWAVE;
} else if ( token == "d" || token == "dwave" ) {
s = OPTION_PAIRING_SYMMETRY_DWAVE;
} else if ( token == "dt" || token == "dwave_twisted" ) {
s = OPTION_PAIRING_SYMMETRY_DWAVE_TWISTED;
} else {
throw po::validation_error( po::validation_error::invalid_option_value );
}
return in;
}
istream& operator>>( std::istream& in, analysis_t& a )
{
string token;
in >> token;
if ( token == "ssfac" ) {
a = ANALYSIS_STATIC_STRUCTURE_FACTOR;
} else {
throw po::validation_error( po::validation_error::invalid_option_value );
}
return in;
}
istream& operator>>( std::istream& in, observables_t& obs )
{
string token;
in >> token;
if ( token == "E" ) {
obs = OBSERVABLE_E;
} else if ( token == "Dk" ) {
obs = OBSERVABLE_DELTAK;
} else if ( token == "DkDkp" ) {
obs = OBSERVABLE_DELTAK_DELTAKPRIME;
} else if ( token == "DkE" ) {
obs = OBSERVABLE_DELTAK_E;
} else if ( token == "dblocc" ) {
obs = OBSERVABLE_DOUBLE_OCCUPANCY_DENSITY;
} else if ( token == "nncorr" ) {
obs = OBSERVABLE_DENSITY_DENSITY_CORRELATION;
} else if ( token == "sscorr" ) {
obs = OBSERVABLE_SPIN_SPIN_CORRELATION;
} else if ( token == "pconfs" ) {
obs = OBSERVABLE_PARTICLE_CONFIGURATIONS;
} else {
throw po::validation_error( po::validation_error::invalid_option_value );
}
return in;
}