mc.h 1.82 KB
Newer Older
1
2
#pragma once

3
#include "evalable.h"
4
5
#include "measurements.h"
#include "parser.h"
6
7
8
9
#include "random.h"
#include <memory>
#include <string>
#include <vector>
Lukas Weber's avatar
Lukas Weber committed
10

11
12
13
namespace loadl {

class mc {
14
private:
Lukas Weber's avatar
Lukas Weber committed
15
16
	size_t sweep_{0};
	size_t therm_{0};
17
	int pt_sweeps_per_global_update_{-1};
18

19
20
protected:
	parser param;
Lukas Weber's avatar
Lukas Weber committed
21
	std::unique_ptr<random_number_generator> rng;
22

23
	virtual void init() = 0;
24
25
	virtual void checkpoint_write(const iodump::group &out) = 0;
	virtual void checkpoint_read(const iodump::group &in) = 0;
26
	virtual void do_update() = 0;
27
	virtual void do_measurement() = 0;
Lukas Weber's avatar
Lukas Weber committed
28
	virtual void pt_update_param(const std::string & /*param_name*/, double /*new_param*/) {
29
30
		throw std::runtime_error{"running parallel tempering, but pt_update_param not implemented"};
	}
Lukas Weber's avatar
Lukas Weber committed
31
	virtual double pt_weight_ratio(const std::string & /*param_name*/, double /*new_param*/) {
Lukas Weber's avatar
Lukas Weber committed
32
33
34
		throw std::runtime_error{"running parallel tempering, but pt_weight_ratio not implemented"};
		return 1;
	}
35

Lukas Weber's avatar
Lukas Weber committed
36
37
38
39
	double random01() {
		return rng->random_double();
	}

40
public:
41
42
	bool pt_mode_{};

Lukas Weber's avatar
Lukas Weber committed
43
	size_t sweep() const;
44

45
46
47
	// implement this static function in your class!
	//static void register_evalables(evaluator &evalables);

48
	virtual void write_output(const std::string &filename);
49

50
51
52
	// these functions do a little more, like taking care of the
	// random number generator state, then call the child class versions.
	void _init();
Lukas Weber's avatar
Lukas Weber committed
53

54
	void _write(const std::string &dir);
55
	void _write_finalize(const std::string &dir);
56
	bool _read(const std::string &dir);
57

58
	void _do_update();
59
	void _do_measurement();
Lukas Weber's avatar
Lukas Weber committed
60
61
	void _pt_update_param(int target_rank, const std::string &param_name, double new_param);
	double _pt_weight_ratio(const std::string &param_name, double new_param);
62

63
	bool is_thermalized();
64
65
	measurements measure;

Lukas Weber's avatar
wrong &    
Lukas Weber committed
66
	mc(const parser &p);
67
	virtual ~mc() = default;
68
};
Lukas Weber's avatar
Lukas Weber committed
69

Lukas Weber's avatar
wrong &    
Lukas Weber committed
70
typedef std::function<mc *(const parser &)> mc_factory;
71
}