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