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