Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HMC_Clover_RHMC_Nf2p1_eo.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
19 
20 #include "Fopr/fopr_Clover_eo.h"
21 #include "Fopr/fopr_Smeared_eo.h"
22 #include "Fopr/fopr_Smeared.h"
23 
26 
27 #include "HMC/hmc_General.h"
28 #include "HMC/builder_Integrator.h"
29 
30 #include "IO/gaugeConfig.h"
31 
33 
34 #include "Tools/file_utils.h"
37 
38 //====================================================================
40 
56 namespace Test_HMC_Clover {
57  const std::string test_name = "HMC.Clover.RHMC_Nf2p1_eo";
58 
59  //- test-private parameters
60  namespace {
61  const std::string filename_input = "test_HMC_Clover_RHMC_Nf2p1.yaml";
62  }
63 
64  //- prototype declaration
65  int RHMC_Nf2p1_eo(void);
66 
67 #ifdef USE_TESTMANAGER_AUTOREGISTER
68  namespace {
69 #if defined(USE_GROUP_SU2)
70  // Nc=2 is not available.
71 #else
72  static const bool is_registered = TestManager::RegisterTest(
73  test_name,
75  );
76 #endif
77  }
78 #endif
79 
80  //====================================================================
81  int RHMC_Nf2p1_eo(void)
82  {
83  // ##### parameter setup #####
84  const int Nc = CommonParameters::Nc();
85  const int Nvol = CommonParameters::Nvol();
86  const int Ndim = CommonParameters::Ndim();
87 
88  const Parameters params_all = ParameterManager::read(filename_input);
89 
90  const Parameters params_test = params_all.lookup("Test_HMC_Clover");
91  const Parameters params_action_G = params_all.lookup("Action_G");
92  const Parameters params_fopr_Nf2 = params_all.lookup("Fopr_Nf2");
93  const Parameters params_fopr_Nf2_prec = params_all.lookup("Fopr_Nf2_prec");
94  const Parameters params_fopr_Nf1 = params_all.lookup("Fopr_Nf1");
95  const Parameters params_proj = params_all.lookup("Projection");
96  const Parameters params_smear = params_all.lookup("Smear");
97  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
98  const Parameters params_rational_MD = params_all.lookup("Fopr_Rational_MD");
99  const Parameters params_rational_H = params_all.lookup("Fopr_Rational_H");
100  const Parameters params_solver_Nf2_MD = params_all.lookup("Solver_Nf2_MD");
101  const Parameters params_solver_Nf2_H = params_all.lookup("Solver_Nf2_H");
102  const Parameters params_solver_Nf2_MD_prec = params_all.lookup("Solver_Nf2_MD_prec");
103  const Parameters params_solver_Nf2_H_prec = params_all.lookup("Solver_Nf2_H_prec");
104  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
105  const Parameters params_hmc = params_all.lookup("HMC_General");
106 
107  const string str_gconf_status = params_test.get_string("gauge_config_status");
108  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
109  const string readfile = params_test.get_string("config_filename_input");
110  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
111  const string writefile = params_test.get_string("config_filename_output");
112  const string str_rand_type = params_test.get_string("random_number_type");
113  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
114  int i_conf = params_test.get_int("trajectory_number");
115  const int Ntraj = params_test.get_int("trajectory_number_step");
116  const int i_save_conf = params_test.get_int("save_config_interval");
117  const string str_vlevel = params_test.get_string("verbose_level");
118 
119  const bool do_check = params_test.is_set("expected_result");
120  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
121 
122  const string str_action_G_type = params_action_G.get_string("action_type");
123  const string str_fopr_Nf2_type = params_fopr_Nf2.get_string("fermion_type");
124  const string str_fopr_Nf2_prec_type = params_fopr_Nf2_prec.get_string("fermion_type");
125  const string str_fopr_Nf1_type = params_fopr_Nf1.get_string("fermion_type");
126  const string str_gmset_type = params_fopr_Nf2.get_string("gamma_matrix_type");
127  const string str_proj_type = params_proj.get_string("projection_type");
128  const string str_smear_type = params_smear.get_string("smear_type");
129  const string str_solver_Nf2_MD_type = params_solver_Nf2_MD.get_string("solver_type");
130  const string str_solver_Nf2_H_type = params_solver_Nf2_H.get_string("solver_type");
131  const string str_solver_Nf2_MD_prec_type = params_solver_Nf2_MD_prec.get_string("solver_type");
132  const string str_solver_Nf2_H_prec_type = params_solver_Nf2_H_prec.get_string("solver_type");
133  const int Nlevels = params_integrator.get_int("number_of_levels");
134  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
135 
136  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
137 
138  //- print input parameters
139  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
140  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
141  vout.general(vl, " readfile = %s\n", readfile.c_str());
142  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
143  vout.general(vl, " writefile = %s\n", writefile.c_str());
144  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
145  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
146  vout.general(vl, " seed = %lu\n", seed);
147  vout.general(vl, " i_conf = %d\n", i_conf);
148  vout.general(vl, " Ntraj = %d\n", Ntraj);
149  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
150  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
151  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
152  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
153  vout.general(vl, " solver_Nf2_MD_type = %s\n", str_solver_Nf2_MD_type.c_str());
154  vout.general(vl, " solver_Nf2_H_type = %s\n", str_solver_Nf2_H_type.c_str());
155  vout.general(vl, " solver_Nf2_MD_prec_type = %s\n", str_solver_Nf2_MD_prec_type.c_str());
156  vout.general(vl, " solver_Nf2_H_prec_type = %s\n", str_solver_Nf2_H_prec_type.c_str());
157  vout.general(vl, "\n");
158 
159  //- input parameter check
160  int err = 0;
161  err += ParameterCheck::non_NULL(str_gconf_status);
162  err += ParameterCheck::non_negative(i_conf);
163  err += ParameterCheck::non_negative(Ntraj);
164  err += ParameterCheck::non_negative(i_save_conf);
165 
166  if (err) {
167  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
168  exit(EXIT_FAILURE);
169  }
170 
171  if ((str_solver_Nf2_MD_type == "CG") || (str_solver_Nf2_H_type == "CG") ||
172  (str_solver_Nf2_MD_prec_type == "CG") || (str_solver_Nf2_H_prec_type == "CG")) {
173  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
174  exit(EXIT_FAILURE);
175  }
176 
177  RandomNumberManager::initialize(str_rand_type, seed);
178 
179 
180  // ##### object setup #####
181  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
182 
183  if (str_gconf_status == "Continue") {
184  GaugeConfig(str_gconf_read).read(U, readfile);
185  } else if (str_gconf_status == "Cold_start") {
186  GaugeConfig("Unit").read(U);
187  } else if (str_gconf_status == "Hot_start") {
188  GaugeConfig("Random").read(U);
189  } else {
190  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
191  exit(EXIT_FAILURE);
192  }
193 
194  const unique_ptr<GaugeConfig> gconf_write(new GaugeConfig(str_gconf_write));
195 
196 
197  unique_ptr<Action> action_G(Action::New(str_action_G_type));
198  action_G->set_parameters(params_action_G);
199 
200 
201  //-- smear part
202  unique_ptr<Projection> proj(Projection::New(str_proj_type));
203  proj->set_parameters(params_proj);
204 
205  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
206  smear->set_parameters(params_smear);
207 
208  unique_ptr<ForceSmear> force_smear(ForceSmear::New(str_smear_type, proj));
209  force_smear->set_parameters(params_smear);
210 
211  unique_ptr<Director> dr_smear(new Director_Smear(smear));
212  dr_smear->set_parameters(params_dr_smear);
213 
214 
215  //-- N_f=2 part
216  unique_ptr<Fopr> fopr_Nf2(Fopr::New(str_fopr_Nf2_type, str_gmset_type));
217  fopr_Nf2->set_parameters(params_fopr_Nf2);
218 
219  unique_ptr<Force> force_fopr_Nf2(new Force_F_Clover_Nf2(str_gmset_type));
220  force_fopr_Nf2->set_parameters(params_fopr_Nf2);
221 
222  unique_ptr<Fopr> fopr_smear_Nf2(Fopr::New("Smeared", fopr_Nf2, dr_smear));
223  unique_ptr<Force> force_fopr_smear_Nf2(new Force_F_Smeared(force_fopr_Nf2, force_smear, dr_smear));
224 
225  //- NB1 fopr_Nf2_eo->set_config is performed in Action_F_Standard_eo.
226  // NB2 fopr_Nf2_eo->set_mode is performed in fprop.
227  unique_ptr<Fopr> fopr_Nf2_eo(Fopr::New(str_fopr_Nf2_type + "_eo", str_gmset_type));
228  fopr_Nf2_eo->set_parameters(params_fopr_Nf2);
229 
230  unique_ptr<Fopr> fopr_smear_Nf2_eo(Fopr::New("Smeared_eo", fopr_Nf2_eo, dr_smear));
231 
232  unique_ptr<Solver> solver_Nf2_eo_MD(Solver::New(str_solver_Nf2_MD_type, fopr_smear_Nf2_eo));
233  solver_Nf2_eo_MD->set_parameters(params_solver_Nf2_MD);
234  unique_ptr<Fprop> fprop_Nf2_eo_MD(new Fprop_Standard_eo(solver_Nf2_eo_MD));
235 
236  unique_ptr<Solver> solver_Nf2_eo_H(Solver::New(str_solver_Nf2_H_type, fopr_smear_Nf2_eo));
237  solver_Nf2_eo_H->set_parameters(params_solver_Nf2_H);
238  unique_ptr<Fprop> fprop_Nf2_eo_H(new Fprop_Standard_eo(solver_Nf2_eo_H));
239 
240 
241  //-- N_f=2 part (preconditioner)
242  unique_ptr<Fopr> fopr_Nf2_prec(Fopr::New(str_fopr_Nf2_prec_type, str_gmset_type));
243  fopr_Nf2_prec->set_parameters(params_fopr_Nf2_prec);
244 
245  unique_ptr<Force> force_fopr_Nf2_prec(new Force_F_Clover_Nf2(str_gmset_type));
246  force_fopr_Nf2_prec->set_parameters(params_fopr_Nf2_prec);
247 
248  unique_ptr<Fopr> fopr_smear_Nf2_prec(Fopr::New("Smeared", fopr_Nf2_prec, dr_smear));
249  unique_ptr<Force> force_fopr_smear_Nf2_prec(new Force_F_Smeared(force_fopr_Nf2_prec, force_smear, dr_smear));
250 
251  //- NB1 fopr_Nf2_eo_prec->set_config is performed in Action_F_Standard_eo.
252  // NB2 fopr_Nf2_eo_prec->set_mode is performed in fprop.
253  unique_ptr<Fopr> fopr_Nf2_eo_prec(Fopr::New(str_fopr_Nf2_prec_type + "_eo", str_gmset_type));
254  fopr_Nf2_eo_prec->set_parameters(params_fopr_Nf2_prec);
255 
256  unique_ptr<Fopr> fopr_smear_Nf2_eo_prec(Fopr::New("Smeared_eo", fopr_Nf2_eo_prec, dr_smear));
257 
258  unique_ptr<Solver> solver_Nf2_eo_MD_prec(Solver::New(str_solver_Nf2_MD_type, fopr_smear_Nf2_eo_prec));
259  solver_Nf2_eo_MD_prec->set_parameters(params_solver_Nf2_MD);
260  unique_ptr<Fprop> fprop_Nf2_eo_MD_prec(new Fprop_Standard_eo(solver_Nf2_eo_MD_prec));
261 
262  unique_ptr<Solver> solver_Nf2_eo_H_prec(Solver::New(str_solver_Nf2_H_type, fopr_smear_Nf2_eo_prec));
263  solver_Nf2_eo_H_prec->set_parameters(params_solver_Nf2_H);
264  unique_ptr<Fprop> fprop_Nf2_eo_H_prec(new Fprop_Standard_eo(solver_Nf2_eo_H_prec));
265 
266 
267  unique_ptr<Action> action_F_Nf2_prec(
268  new Action_F_Standard_eo(fopr_smear_Nf2_prec, force_fopr_smear_Nf2_prec,
269  fprop_Nf2_eo_MD_prec, fprop_Nf2_eo_H_prec));
270 
271  unique_ptr<Action> action_F_Nf2_d(
272  new Action_F_Ratio_eo(fopr_smear_Nf2_prec, force_fopr_smear_Nf2_prec,
273  fopr_smear_Nf2, force_fopr_smear_Nf2,
274  fprop_Nf2_eo_H_prec,
275  fprop_Nf2_eo_MD, fprop_Nf2_eo_H));
276 
277 
278  //-- N_f=1 part
279  unique_ptr<Fopr> fopr_Nf1(Fopr::New(str_fopr_Nf1_type, str_gmset_type));
280  fopr_Nf1->set_parameters(params_fopr_Nf1);
281 
282  //- NB. create Force_F_Nf2, then apply rational approximation
283  unique_ptr<Force> force_fopr_Nf1(new Force_F_Clover_Nf2(str_gmset_type));
284  force_fopr_Nf1->set_parameters(params_fopr_Nf1);
285 
286  //- NB. Langevin needs params_rational_H
287  unique_ptr<Fopr> fopr_r1(Fopr::New("Rational", fopr_Nf1));
288  fopr_r1->set_parameters(params_rational_H);
289  unique_ptr<Fopr> fopr_smear_Nf1_langev(Fopr::New("Smeared", fopr_r1, dr_smear));
290 
291  //- NB. Hamiltonian needs params_rational_MD
292  unique_ptr<Fopr> fopr_r2(Fopr::New("Rational", fopr_Nf1));
293  fopr_r2->set_parameters(params_rational_MD);
294  unique_ptr<Fopr> fopr_smear_Nf1_H(Fopr::New("Smeared", fopr_r2, dr_smear));
295 
296  unique_ptr<Force> force_fopr_Nf1_MD(new Force_F_Rational(fopr_Nf1, force_fopr_Nf1));
297  force_fopr_Nf1_MD->set_parameters(params_rational_MD);
298  unique_ptr<Force> force_fopr_smear_Nf1_MD(new Force_F_Smeared(force_fopr_Nf1_MD, force_smear, dr_smear));
299 
300 
301  unique_ptr<Action> action_F_Nf1(
302  new Action_F_Rational(fopr_smear_Nf1_langev, fopr_smear_Nf1_H, force_fopr_smear_Nf1_MD));
303 
304 
305  ActionList actions(Nlevels);
306  actions.append(level_action[0], action_F_Nf2_d);
307  actions.append(level_action[1], action_F_Nf2_prec);
308  actions.append(level_action[2], action_F_Nf1);
309  actions.append(level_action[3], action_G);
310 
311  std::vector<Director *> directors(1);
312  directors[0] = (Director *)dr_smear.get();
313 
314  const unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions, directors));
315  builder->set_parameters(params_integrator);
316  Integrator *integrator = builder->build();
317 
318 
319  //- Random number is initialized with a parameter specified by i_conf
321 
322 
323  HMC_General hmc(actions, directors, integrator, rand);
324  hmc.set_parameters(params_hmc);
325 
326  const unique_ptr<Timer> timer(new Timer(test_name));
327 
328 
329  // #### Execution main part ####
330  timer->start();
331 
332  vout.general(vl, "HMC start: Ntraj = %d\n", Ntraj);
333 
334  double result = 0.0;
335  for (int traj = 0; traj < Ntraj; ++traj) {
336  vout.general(vl, "\n");
337  vout.general(vl, "---------------------------------------------------\n");
338  vout.general(vl, "traj = %d\n", traj);
339 
340  result = hmc.update(*U);
341 
342  if ((i_conf + traj + 1) % i_save_conf == 0) {
343  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
344  gconf_write->write_file(U, filename);
345  }
346  }
347 
348  gconf_write->write_file(U, writefile);
349 
350  timer->report();
351 
353 
354 
355  if (do_check) {
356  return Test::verify(result, expected_result);
357  } else {
358  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
359  return EXIT_SKIP;
360  }
361  }
362 } // namespace Test_HMC_Clover
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
Standard even-odd preconditioned fermion action for HMC.
virtual void set_parameters(const Parameters &param)=0
void set_parameters(const Parameters &params)
void general(const char *format,...)
Definition: bridgeIO.cpp:197
HMC action for Hasenbusch preconditioned fermions.
General HMC update class.
Definition: hmc_General.h:45
virtual void set_parameters(const Parameters &)=0
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
bool append(const int level, Action *action)
Definition: action_list.cpp:27
virtual void set_parameters(const Parameters &param)=0
Base class of Integrator class family.
Definition: integrator.h:29
virtual void set_parameters(const Parameters &params)=0
Parameters lookup(const string &key) const
Definition: parameters.h:79
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69
static bool initialize(const std::string &rng_type, unsigned long seed)
SU(N) gauge field.
Definition: field_G.h:38
void set_parameters(const Parameters &params)
Manager of commonly used data object in HMC.
Definition: director.h:37
void read(Field_G *U, const string &filename=string())
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
double get_double(const string &key) const
Definition: parameters.cpp:175
std::string generate_filename(const char *fmt,...)
Definition: file_utils.cpp:17
Get quark propagator for Fopr with even-odd site index.
Force calculation for clover quark action.
pointer get() const
virtual void set_parameters(const Parameters &)=0
action class for RHMC, with externally constructed Fopr_Rational.
int non_NULL(const std::string v)
bool is_set(const string &key) const
Definition: parameters.cpp:528
void start()
Definition: timer.cpp:44
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
virtual void set_parameters(const Parameters &params)=0
static void read(const std::string &params_file, Parameters &params)
const std::string test_name
lists of actions at respective integrator levels.
Definition: action_list.h:40
Manager of smeared configurations.
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
double update(Field_G &)
void write_file(Field_G *U, const string &filename)
Definition: gaugeConfig.h:109
Force calculation for smeared fermion operators.
int non_negative(const int v)
virtual void set_parameters(const Parameters &)=0
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:221
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
virtual void set_parameters(const Parameters &)=0
Builder of MD integrator for HMC.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
Force calculation for smeared fermion operators.