Bridge++  Ver. 2.0.3
sample_HMC_Wilson_Leapfrog_Nf2.cpp
Go to the documentation of this file.
1 
14 #include "bridge.h"
15 using Bridge::vout;
16 
17 
18 namespace {
19  const std::string test_name = "sample_HMC_Wilson_Leapfrog_Nf2";
20  const std::string parameter_file = "sample_HMC_Wilson_Leapfrog_Nf2.yaml";
21 }
22 
23 //====================================================================
25 
35 //====================================================================
36 int leapfrog_Nf2(const Parameters& params_all)
37 {
38  // ##### parameter setup #####
39  const int Nc = CommonParameters::Nc();
40  const int Nvol = CommonParameters::Nvol();
41  const int Ndim = CommonParameters::Ndim();
42 
43  // const Parameters params_all = ParameterManager::read(filename_input);
44  const Parameters params_test = params_all.lookup("Test_HMC_Wilson");
45  const Parameters params_action_G = params_all.lookup("Action_G");
46  const Parameters params_fopr = params_all.lookup("Fopr");
47  const Parameters params_proj = params_all.lookup("Projection");
48  const Parameters params_smear = params_all.lookup("Smear");
49  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
50  const Parameters params_solver_MD = params_all.lookup("Solver_MD");
51  const Parameters params_solver_H = params_all.lookup("Solver_H");
52  const Parameters params_hmc = params_all.lookup("HMC_Leapfrog");
53 
54  const string str_gconf_status = params_test.get_string("gauge_config_status");
55  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
56  const string readfile = params_test.get_string("config_filename_input");
57  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
58  const string writefile = params_test.get_string("config_filename_output");
59  const string str_rand_type = params_test.get_string("random_number_type");
60  const string rand_readfile = params_test.get_string("rand_filename_input");
61  const string rand_writefile = params_test.get_string("rand_filename_output");
62  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
63  int i_conf = params_test.get_int("trajectory_number");
64  const int Ntraj = params_test.get_int("trajectory_number_step");
65  const int i_save_conf = params_test.get_int("save_config_interval");
66  const string str_vlevel = params_test.get_string("verbose_level");
67 
68  // const bool do_check = params_test.is_set("expected_result");
69  // const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
70 
71  const string str_action_G_type = params_action_G.get_string("action_type");
72  const string str_fopr_type = params_fopr.get_string("fermion_type");
73  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
74  const string str_proj_type = params_proj.get_string("projection_type");
75  const string str_smear_type = params_smear.get_string("smear_type");
76  // const int Nsmear = params_dr_smear.get_int("number_of_smearing");
77  const string str_solver_MD_type = params_solver_MD.get_string("solver_type");
78  const string str_solver_H_type = params_solver_H.get_string("solver_type");
79 
80  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
81 
82  //- print input parameters
83  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
84  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
85  vout.general(vl, " readfile = %s\n", readfile.c_str());
86  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
87  vout.general(vl, " writefile = %s\n", writefile.c_str());
88  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
89  vout.general(vl, " rand_readfile = %s\n", rand_readfile.c_str());
90  vout.general(vl, " rand_writefile = %s\n", rand_writefile.c_str());
91  vout.general(vl, " seed = %lu\n", seed);
92  vout.general(vl, " i_conf = %d\n", i_conf);
93  vout.general(vl, " Ntraj = %d\n", Ntraj);
94  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
95  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
96  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
97  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
98  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
99  vout.general(vl, " solver_MD_type = %s\n", str_solver_MD_type.c_str());
100  vout.general(vl, " solver_H_type = %s\n", str_solver_H_type.c_str());
101  vout.general(vl, "\n");
102 
103  //- input parameter check
104  int err = 0;
105  err += ParameterCheck::non_NULL(str_gconf_status);
106  err += ParameterCheck::non_negative(i_conf);
107  err += ParameterCheck::non_negative(Ntraj);
108  err += ParameterCheck::non_negative(i_save_conf);
109 
110  if (err) {
111  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
112  exit(EXIT_FAILURE);
113  }
114 
115  // if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
116  if (str_proj_type == "Stout_SU3") {
117  if (CommonParameters::Nc() != 3) {
118  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
119  return EXIT_FAILURE;
120  }
121  }
122 
123 
124  RandomNumberManager::initialize(str_rand_type, seed);
125 
126 
127  // ##### object setup #####
128  Field_G U(Nvol, Ndim);
129 
130  if (str_gconf_status == "Continue") {
131  GaugeConfig(str_gconf_read).read(U, readfile);
132  if (rand_readfile != "None") RandomNumberManager::restore_state(rand_readfile);
133  } else if (str_gconf_status == "Cold_start") {
134  GaugeConfig("Unit").read(U);
135  } else if (str_gconf_status == "Hot_start") {
136  GaugeConfig("Random").read(U);
137  } else {
138  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
139  exit(EXIT_FAILURE);
140  }
141 
142  GaugeConfig gconf_write(str_gconf_write);
143 
144 
145  unique_ptr<Action> action_G(Action::New(str_action_G_type, params_action_G));
146 
147  //-- N_f=2 part
148  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, params_fopr));
149 
150  // define fermion force (SA)
151  unique_ptr<Force> force_fopr(new Force_F_Wilson_Nf2(params_fopr));
152 
153  // define smearing method (SA)
154  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_proj));
155  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_smear));
156 
157  // define force smearing method (SA)
158  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj.get(), params_smear));
159 
160  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_dr_smear));
161 
162  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr.get(), dr_smear.get()));
163  // define smeared fermion operator (SA)
164  unique_ptr<Force> force_fopr_smear(new Force_F_Smeared(force_fopr.get(), force_smear.get(), dr_smear.get()));
165  // define smeared fermion force (SA)
166 
167  unique_ptr<Solver> solver_MD(Solver::New(str_solver_MD_type, fopr_smear.get(), params_solver_MD));
168  unique_ptr<Fprop> fprop_MD(new Fprop_Standard_lex(solver_MD.get()));
169 
170  unique_ptr<Solver> solver_H(Solver::New(str_solver_H_type, fopr_smear.get(), params_solver_H));
171  unique_ptr<Fprop> fprop_H(new Fprop_Standard_lex(solver_H.get()));
172 
173  unique_ptr<Action> action_F(new Action_F_Standard_lex(fopr_smear.get(), force_fopr_smear.get(), fprop_MD.get(), fprop_H.get()));
174  // define fermion action (SA)
175 
176 
177  ActionList actions(1); // one level
178  actions.append(0, action_F.get()); // register actions at level0
179  actions.append(0, action_G.get());
180 
181  std::vector<Director *> directors(1);
182  directors[0] = static_cast<Director *>(dr_smear.get()); // register director[0] (SA)
183 
184  unique_ptr<RandomNumbers> rand;
185  if (rand_readfile == "None") {
186  //- Random number is initialized with a parameter specified by i_conf
187  rand.reset(new RandomNumbers_Mseries(i_conf));
188  } else {
189  rand.reset(RandomNumberManager::getInstance());
190  }
191 
192  // define hmc_leapfrog (SA)
193  HMC_Leapfrog hmc(actions, directors, rand.get(), params_hmc);
194 
195  Timer timer(test_name);
196 
197 
198  // #### Execution main part ####
199  timer.start();
200 
201  vout.general(vl, "HMC: Ntraj = %d\n", Ntraj); // a number of trajectory (SA)
202 
203  double result = 0.0;
204  for (int traj = 0; traj < Ntraj; ++traj) {
205  vout.general(vl, "\n");
206  vout.general(vl, "traj = %d\n", traj);
207 
208  result = hmc.update(U); // hmc update (SA)
209 
210  if ((i_conf + traj + 1) % i_save_conf == 0) {
211  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
212  gconf_write.write_file(U, filename);
213  }
214  }
215 
216  gconf_write.write_file(U, writefile);
217  if (rand_writefile != "None") RandomNumberManager::save_state(rand_writefile);
218 
219  timer.report();
220 
221  if (rand_readfile == "None") RandomNumberManager::finalize();
222 
223 
224  // if (do_check) {
225  // return Test::verify(result, expected_result);
226  // } else {
227  // vout.detailed(vl, "check skipped: expected_result not set.\n\n");
228  // return EXIT_SKIP;
229  // }
230  return EXIT_SUCCESS;
231 }
232 
233 
234 //====================================================================
235 int main(int argc, char *argv[])
236 {
237  bridge_initialize(&argc, &argv);
238 
239  Parameters params = ParameterManager::read(parameter_file);
240  bridge_setup(params.lookup("Main"));
241 
242  Timer timer("Main");
243  timer.start();
244 
245  leapfrog_Nf2(params);
246 
247  timer.stop();
248  timer.report();
249 
250  bridge_finalize();
251 
252  return EXIT_SUCCESS;
253 }
Test_Eigensolver::test_name
const std::string test_name
Definition: test_Eigensolver.cpp:40
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
Fprop_Standard_lex
Get quark propagator for Fopr with lexical site index.
Definition: fprop_Standard_lex.h:33
HMC_Leapfrog
HMC with single level leapfrog intetgrator.
Definition: hmc_Leapfrog.h:44
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Parameters
Class for parameters.
Definition: parameters.h:46
Parameters::get_int
int get_int(const string &key) const
Definition: parameters.cpp:192
GaugeConfig::read
void read(Field_G &U, const string &filename=string())
Definition: gaugeConfig.cpp:121
GaugeConfig::write_file
void write_file(Field_G &U, const string &filename)
Definition: gaugeConfig.h:103
main
int main(int argc, char *argv[])
Definition: sample_HMC_Wilson_Leapfrog_Nf2.cpp:235
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
Force_F_Smeared
Force calculation for smeared fermion operators.
Definition: force_F_Smeared.h:39
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
RandomNumberManager::save_state
static void save_state(const std::string &filename)
Definition: randomNumberManager.cpp:116
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
ActionList
lists of actions at respective integrator levels.
Definition: action_list.h:40
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Timer::start
void start()
Definition: timer.cpp:44
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
RandomNumbers_Mseries
Random number generator base on M-series.
Definition: randomNumbers_Mseries.h:46
bridge_finalize
int bridge_finalize()
Definition: bridge_setup.cpp:94
bridge_initialize
int bridge_initialize(int *pargc, char ***pargv)
Definition: bridge_setup.cpp:32
ParameterManager::read
static void read(const std::string &params_file, Parameters &params)
Definition: parameterManager.cpp:33
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:39
bridge.h
compilation of Bridge++ header files
RandomNumberManager::getInstance
static RandomNumbers * getInstance()
Definition: randomNumberManager.cpp:45
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
ActionList::append
bool append(const int level, Action *action)
Definition: action_list.cpp:27
FileUtils::generate_filename
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
GaugeConfig
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:80
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
bridge_setup
void bridge_setup(const Parameters &params)
Definition: bridge_setup.cpp:106
Director
Manager of commonly used data object in HMC.
Definition: director.h:37
Force_F_Wilson_Nf2
Force for the standard Wilson fermion operator.
Definition: force_F_Wilson_Nf2.h:38
HMC_Leapfrog::update
double update(Field_G &)
Definition: hmc_Leapfrog.cpp:323
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
leapfrog_Nf2
int leapfrog_Nf2(const Parameters &params_all)
An example code for HMC with Leapfrog using N_f=2 Wilson fermion.
Definition: sample_HMC_Wilson_Leapfrog_Nf2.cpp:36
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Action_F_Standard_lex
Standard fermion action for HMC.
Definition: action_F_Standard_lex.h:37
Timer::stop
void stop()
Definition: timer.cpp:69
Parameters::lookup
Parameters lookup(const string &key) const
Definition: parameters.h:79
Timer::report
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
RandomNumberManager::restore_state
static void restore_state(const std::string &filename)
Definition: randomNumberManager.cpp:103