Commit 9deeb292 authored by Lukas Weber's avatar Lukas Weber
Browse files

putting everything into the loadl namespace

parent a4216e44
......@@ -93,11 +93,12 @@ def ystatus():
if args.need_merge:
if job_prog.needs_merge():
print('Needs merge!')
return True
print('Job already merged.')
return False
for task, tp in zip(job_prog.tasks, job_prog.progress):
print('{t}: {tp.num_runs} runs, {tp.sweeps}/{tp.target_sweeps} sweeps, {tp.therm_sweeps}/{tp.target_therm} thermalization'.format(t=task,tp=tp))
print('{t}: {tp.num_runs} runs, {tp.sweeps}/{tp.target_sweeps} sweeps, {tp.therm_sweeps/tp.num_runs}/{tp.target_therm} thermalization'.format(t=task,tp=tp))
except FileNotFoundError as e:
print("Error: jobfile '{}' not found.".format(args.jobfile))
......@@ -5,6 +5,8 @@
#include <typeinfo>
#include <unistd.h>
namespace loadl {
static bool filter_available(H5Z_filter_t filter) {
htri_t avail = H5Zfilter_avail(filter);
if(avail == 0) {
......@@ -264,3 +266,4 @@ iodump::h5_handle::~h5_handle() {
hid_t iodump::h5_handle::operator*() {
return handle_;
}
}
......@@ -5,6 +5,8 @@
#include <string>
#include <vector>
namespace loadl {
class iodump_exception : public std::exception {
private:
std::string message_;
......@@ -253,3 +255,4 @@ void iodump::group::read(const std::string &name, T &value) const {
read(name, buf);
value = buf.at(0);
}
}
......@@ -3,6 +3,8 @@
#include <fmt/format.h>
#include <map>
namespace loadl {
evalable::evalable(std::string name, std::vector<std::string> used_observables, func fun)
: name_{std::move(name)}, used_observables_{std::move(used_observables)}, fun_{std::move(fun)} {
// evalable names also should be valid HDF5 paths
......@@ -134,3 +136,4 @@ void evalable::jackknife(const results &res, observable_result &obs_res) const {
obs_res.error[i] = sqrt((bin_count - 1) * obs_res.error[i] / bin_count);
}
}
}
......@@ -5,6 +5,8 @@
#include <string>
#include <vector>
namespace loadl {
class evalable {
public:
// Internally all observables are vectors, so you need a function
......@@ -26,3 +28,4 @@ private:
const std::vector<std::string> used_observables_;
const func fun_;
};
}
......@@ -5,7 +5,8 @@
#include "runner.h"
#include "runner_single.h"
namespace load_leveller {
namespace loadl {
inline int merge_only(jobinfo job, const mc_factory &mccreator, int, char **) {
for(size_t task_id = 0; task_id < job.task_names.size(); task_id++) {
std::vector<evalable> evalables;
......
#include "mc.h"
abstract_mc::abstract_mc(const std::string &jobfile, const std::string &taskname)
namespace loadl {
mc::mc(const std::string &jobfile, const std::string &taskname)
: param{parser{jobfile}["tasks"][taskname]} {
therm_ = param.get<int>("thermalization");
}
void abstract_mc::write_output(const std::string &) {}
void mc::write_output(const std::string &) {}
void abstract_mc::random_init() {
void mc::random_init() {
if(param.defined("seed")) {
rng.reset(new randomnumbergenerator(param.get<uint64_t>("seed")));
} else {
......@@ -15,15 +17,15 @@ void abstract_mc::random_init() {
}
}
double abstract_mc::random01() {
double mc::random01() {
return rng->d();
}
int abstract_mc::sweep() const {
int mc::sweep() const {
return sweep_;
}
void abstract_mc::_init() {
void mc::_init() {
// simple profiling support: measure the time spent for sweeps/measurements etc
measure.add_observable("_ll_checkpoint_read_time", 1);
measure.add_observable("_ll_checkpoint_write_time", 1);
......@@ -33,7 +35,7 @@ void abstract_mc::_init() {
init();
}
void abstract_mc::_do_measurement() {
void mc::_do_measurement() {
struct timespec tstart, tend;
clock_gettime(CLOCK_MONOTONIC_RAW, &tstart);
......@@ -44,7 +46,7 @@ void abstract_mc::_do_measurement() {
(tend.tv_sec - tstart.tv_sec) + 1e-9 * (tend.tv_nsec - tstart.tv_nsec));
}
void abstract_mc::_do_update() {
void mc::_do_update() {
struct timespec tstart, tend;
clock_gettime(CLOCK_MONOTONIC_RAW, &tstart);
sweep_++;
......@@ -55,7 +57,7 @@ void abstract_mc::_do_update() {
(tend.tv_sec - tstart.tv_sec) + 1e-9 * (tend.tv_nsec - tstart.tv_nsec));
}
void abstract_mc::_write(const std::string &dir) {
void mc::_write(const std::string &dir) {
struct timespec tstart, tend;
clock_gettime(CLOCK_MONOTONIC_RAW, &tstart);
......@@ -77,7 +79,7 @@ void abstract_mc::_write(const std::string &dir) {
(tend.tv_sec - tstart.tv_sec) + 1e-9 * (tend.tv_nsec - tstart.tv_nsec));
}
bool abstract_mc::_read(const std::string &dir) {
bool mc::_read(const std::string &dir) {
try {
struct timespec tstart, tend;
clock_gettime(CLOCK_MONOTONIC_RAW, &tstart);
......@@ -99,10 +101,11 @@ bool abstract_mc::_read(const std::string &dir) {
return true;
}
void abstract_mc::_write_output(const std::string &filename) {
void mc::_write_output(const std::string &filename) {
write_output(filename);
}
bool abstract_mc::is_thermalized() {
bool mc::is_thermalized() {
return sweep_ > therm_;
}
}
......@@ -8,7 +8,9 @@
#include <string>
#include <vector>
class abstract_mc {
namespace loadl {
class mc {
private:
void random_init();
......@@ -46,8 +48,9 @@ public:
bool is_thermalized();
measurements measure;
abstract_mc(const std::string &jobfile, const std::string &taskname);
virtual ~abstract_mc() = default;
mc(const std::string &jobfile, const std::string &taskname);
virtual ~mc() = default;
};
typedef std::function<abstract_mc *(const std::string &, const std::string &)> mc_factory;
typedef std::function<mc *(const std::string &, const std::string &)> mc_factory;
}
#include "measurements.h"
#include <fmt/format.h>
namespace loadl {
bool measurements::observable_name_is_legal(const std::string &obs_name) {
if(obs_name.find('/') != obs_name.npos) {
return false;
......@@ -40,3 +42,4 @@ void measurements::samples_write(const iodump::group &meas_file) {
obs.second.measurement_write(g);
}
}
}
......@@ -7,6 +7,8 @@
#include <valarray>
#include <vector>
namespace loadl {
class measurements {
public:
static bool observable_name_is_legal(const std::string &name);
......@@ -33,3 +35,4 @@ template<class T>
void measurements::add(const std::string name, T value) {
observables_.at(name).add(value);
}
}
......@@ -8,6 +8,8 @@
#include <string>
#include <vector>
namespace loadl {
static void evaluate_evalables(results &res, const std::vector<evalable> &evalables) {
std::vector<observable_result> evalable_results;
for(auto &eval : evalables) {
......@@ -187,3 +189,4 @@ results merge(const std::vector<std::string> &filenames, const std::vector<evala
return res;
}
}
......@@ -3,6 +3,9 @@
#include "evalable.h"
#include "results.h"
namespace loadl {
// if rebinning_bin_count is 0, cbrt(total_sample_count) is used as default.
results merge(const std::vector<std::string> &filenames, const std::vector<evalable> &evalables,
size_t rebinning_bin_count = 0);
}
#include "observable.h"
#include <fmt/format.h>
namespace loadl {
observable::observable(std::string name, size_t bin_length, size_t vector_length,
size_t initial_length)
: name_{std::move(name)}, bin_length_{bin_length}, vector_length_{vector_length},
......@@ -49,3 +51,4 @@ void observable::checkpoint_read(const iodump::group &d) {
d.read("samples", samples_);
current_bin_ = 0;
}
}
......@@ -6,6 +6,8 @@
#include <string>
#include <vector>
namespace loadl {
class observable {
public:
observable(std::string name, size_t bin_length = 1, size_t vector_length = 1,
......@@ -68,3 +70,4 @@ void observable::add(const std::vector<T> &val) {
current_bin_filling_ = 0;
}
}
}
#include "parser.h"
namespace loadl {
parser::iterator::iterator(std::string filename, YAML::Node::iterator it)
: filename_{std::move(filename)}, it_{std::move(it)} {}
......@@ -84,3 +86,4 @@ parser parser::operator[](const std::string &key) {
const YAML::Node &parser::get_yaml() {
return content_;
}
}
......@@ -3,6 +3,8 @@
#include <fmt/format.h>
#include <yaml-cpp/yaml.h>
namespace loadl {
// This is mostly a wrapper around yaml-cpp with more helpful error handling.
// For simplicity it does not support advanced yaml features such as complex-typed
// keys in maps.
......@@ -31,7 +33,7 @@ public:
parser(const std::string &filename);
template<typename T>
T get(const std::string &key) {
T get(const std::string &key) const {
if(!content_[key]) {
throw std::runtime_error(
fmt::format("YAML: {}: required key '{}' not found.", filename_, key));
......@@ -40,7 +42,7 @@ public:
}
template<typename T>
auto get(const std::string &key, T default_val) -> decltype(default_val) {
auto get(const std::string &key, T default_val) -> decltype(default_val) const {
return content_[key].as<T>(default_val);
}
......@@ -55,3 +57,4 @@ public:
// This function is needed to dump the task settings into the result file for example.
const YAML::Node &get_yaml();
};
}
#include "random.h"
namespace loadl {
#ifdef MCL_RNG_MT
randomnumbergenerator::randomnumbergenerator() {
seed_ = mtrand_.get_seed();
......@@ -110,3 +112,4 @@ randomnumbergenerator::randomnumbergenerator(int seed) {
seed_ = seed;
}
#endif
}
......@@ -8,13 +8,17 @@
// in that case, also get rid of the macros and use templates to switch between different generators
// or so.
#ifdef MCL_RNG_MT
namespace loadl {
enum rng_type {
RNG_MersenneTwister = 0,
};
}
#ifdef MCL_RNG_MT
#include "MersenneTwister.h"
namespace loadl {
class randomnumbergenerator {
public:
randomnumbergenerator();
......@@ -37,6 +41,8 @@ private:
MTRand mtrand_;
uint64_t seed_;
};
}
#endif
#ifdef MCL_RNG_SPRNG_4
......
......@@ -3,6 +3,8 @@
#include <fstream>
#include <yaml-cpp/yaml.h>
namespace loadl {
void results::write_yaml(const std::string &filename, const std::string &taskdir,
const YAML::Node &params) {
YAML::Emitter out;
......@@ -37,3 +39,4 @@ void results::write_yaml(const std::string &filename, const std::string &taskdir
std::ofstream file(filename);
file << out.c_str();
}
}
......@@ -2,6 +2,12 @@
#include <map>
#include <vector>
namespace YAML {
class Node;
}
namespace loadl {
struct observable_result {
std::string name;
......@@ -24,9 +30,6 @@ struct observable_result {
std::vector<double> autocorrelation_time;
};
namespace YAML {
class Node;
}
// results holds the means and errors merged from all the runs belonging to a task
// this includes both regular observables and evalables.
......@@ -37,3 +40,4 @@ struct results {
void write_yaml(const std::string &filename, const std::string &taskdir,
const YAML::Node &params);
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment