Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_HMC_Quenched.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "Action/action.h"
17 
18 #include "HMC/hmc_General.h"
19 #include "HMC/builder_Integrator.h"
20 
21 #include "IO/gaugeConfig.h"
22 
23 #include "Tools/file_utils.h"
26 
27 //====================================================================
29 
39 namespace Test_HMC_Quenched {
40  const std::string test_name = "HMC.Quenched.Nf0";
41 
42  //- test-private parameters
43  namespace {
44  const std::string filename_input = "test_HMC_Quenched.yaml";
45  }
46 
47  //- prototype declaration
48  int update_Nf0(void);
49 
50 #ifdef USE_TESTMANAGER_AUTOREGISTER
51  namespace {
52 #if defined(USE_GROUP_SU2)
53  // Nc=2 is not available.
54 #else
55  static const bool is_registered = TestManager::RegisterTest(
56  test_name,
58  );
59 #endif
60  }
61 #endif
62 
63  //====================================================================
64  int update_Nf0(void)
65  {
66  // #### parameter setup ####
67  const int Nc = CommonParameters::Nc();
68  const int Nvol = CommonParameters::Nvol();
69  const int Ndim = CommonParameters::Ndim();
70 
71  const Parameters params_all = ParameterManager::read(filename_input);
72 
73  const Parameters params_test = params_all.lookup("Test_HMC_Quenched");
74  const Parameters params_action_G = params_all.lookup("Action_G");
75  const Parameters params_integrator = params_all.lookup("Builder_Integrator");
76  const Parameters params_hmc = params_all.lookup("HMC_General");
77 
78  const string str_gconf_status = params_test.get_string("gauge_config_status");
79  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
80  const string readfile = params_test.get_string("config_filename_input");
81  const string str_gconf_write = params_test.get_string("gauge_config_type_output");
82  const string writefile = params_test.get_string("config_filename_output");
83  const string str_rand_type = params_test.get_string("random_number_type");
84  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
85  int i_conf = params_test.get_int("trajectory_number");
86  const int Ntraj = params_test.get_int("trajectory_number_step");
87  const int i_save_conf = params_test.get_int("save_config_interval");
88  const string str_vlevel = params_test.get_string("verbose_level");
89 
90  const bool do_check = params_test.is_set("expected_result");
91  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
92 
93  const string str_action_G_type = params_action_G.get_string("action_type");
94  const int Nlevels = params_integrator.get_int("number_of_levels");
95  const std::vector<int> level_action = params_integrator.get_int_vector("level_of_actions");
96 
97  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
98 
99  //- print input parameters
100  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
101  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
102  vout.general(vl, " readfile = %s\n", readfile.c_str());
103  vout.general(vl, " gconf_write = %s\n", str_gconf_write.c_str());
104  vout.general(vl, " writefile = %s\n", writefile.c_str());
105  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
106  vout.general(vl, " seed = %lu\n", seed);
107  vout.general(vl, " i_conf = %d\n", i_conf);
108  vout.general(vl, " Ntraj = %d\n", Ntraj);
109  vout.general(vl, " i_save_conf = %d\n", i_save_conf);
110  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
111  vout.general(vl, "\n");
112 
113  //- input parameter check
114  int err = 0;
115  err += ParameterCheck::non_NULL(str_gconf_status);
116  err += ParameterCheck::non_negative(i_conf);
117  err += ParameterCheck::non_negative(Ntraj);
118  err += ParameterCheck::non_negative(i_save_conf);
119 
120  if (err) {
121  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
122  exit(EXIT_FAILURE);
123  }
124 
125 
126  RandomNumberManager::initialize(str_rand_type, seed);
127 
128 
129  // ##### object setup #####
130  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
131 
132  if (str_gconf_status == "Continue") {
133  GaugeConfig(str_gconf_read).read(U, readfile);
134  } else if (str_gconf_status == "Cold_start") {
135  GaugeConfig("Unit").read(U);
136  } else if (str_gconf_status == "Hot_start") {
137  GaugeConfig("Random").read(U);
138  } else {
139  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
140  exit(EXIT_FAILURE);
141  }
142 
143  const unique_ptr<GaugeConfig> gconf_write(new GaugeConfig(str_gconf_write));
144 
145 
146  unique_ptr<Action> action_G(Action::New(str_action_G_type));
147  action_G->set_parameters(params_action_G);
148 
149  ActionList actions(Nlevels);
150  actions.append(level_action[0], action_G);
151 
152  const unique_ptr<Builder_Integrator> builder(new Builder_Integrator(actions));
153  builder->set_parameters(params_integrator);
154  Integrator *integrator = builder->build();
155 
157 
158  HMC_General hmc(actions, integrator, rand);
159  hmc.set_parameters(params_hmc);
160 
161  const unique_ptr<Timer> timer(new Timer(test_name));
162 
163 
164  // #### Execution main part ####
165  timer->start();
166 
167  vout.general(vl, "HMC: Ntraj = %d\n", Ntraj);
168 
169  double result = 0.0;
170  for (int traj = 0; traj < Ntraj; ++traj) {
171  vout.general(vl, "\n");
172  vout.general(vl, "traj = %d\n", traj);
173 
174  result = hmc.update(*U);
175 
176  if ((i_conf + traj + 1) % i_save_conf == 0) {
177  std::string filename = FileUtils::generate_filename("%s-%06d", writefile.c_str(), (i_conf + traj + 1));
178  gconf_write->write_file(U, filename);
179  }
180  }
181 
182  gconf_write->write_file(U, writefile);
183 
184  timer->report();
185 
187 
188 
189  if (do_check) {
190  return Test::verify(result, expected_result);
191  } else {
192  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
193  return EXIT_SKIP;
194  }
195  }
196 } // namespace Test_HMC_Quenched
#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
void set_parameters(const Parameters &params)
void general(const char *format,...)
Definition: bridgeIO.cpp:197
General HMC update class.
Definition: hmc_General.h:45
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
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)
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
const std::string test_name
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
static void read(const std::string &params_file, Parameters &params)
lists of actions at respective integrator levels.
Definition: action_list.h:40
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
int non_negative(const int v)
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
Builder of MD integrator for HMC.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131