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