31#include <fmt/format.h>
44namespace triqs::mc_tools {
63 template <DoubleOrComplex MCSignType>
class move_set {
98 void add(T &&m, std::string name,
double weight) {
99 if (weight < 0.0)
throw std::runtime_error(fmt::format(
"Error in move_set: Weight of move {} is negative: {} < 0", name, weight));
100 moves_.emplace_back(std::forward<T>(m));
101 weights_.emplace_back(weight);
102 names_.emplace_back(std::move(name));
119 MCSignType
accept() {
return moves_[current_].accept() * attempt_sign_; }
125 void reject() { moves_[current_].reject(); }
145 void calibrate(mpi::communicator
const &c);
159 [[nodiscard]] std::string
get_statistics(std::string
const &prefix =
"")
const;
166 [[nodiscard]] std::string
get_timings(std::string
const &prefix =
"")
const;
171 for (
auto const &m : moves_) total += m.duration();
176 [[nodiscard]]
auto current()
const {
return current_; }
185 [[nodiscard]]
static std::string
hdf5_format() {
return "move_set"; }
197 auto gr = g.create_group(name);
198 h5::write_hdf5_format(gr, ms);
199 for (std::size_t i = 0; i < ms.moves_.size(); ++i) h5::write(gr, ms.names_[i], ms.moves_[i]);
212 auto gr = g.open_group(name);
213 h5::assert_hdf5_format(gr, ms);
214 for (std::size_t i = 0; i < ms.moves_.size(); ++i) h5::read(gr, ms.names_[i], ms.moves_[i]);
222 double check_ratio(MCSignType ratio);
225 std::vector<move<MCSignType>> moves_;
226 std::vector<std::string> names_;
227 std::size_t current_{0};
228 std::reference_wrapper<random_generator> rng_;
229 std::vector<double> weights_;
230 std::vector<double> probs_;
231 std::vector<double> acc_probs_;
232 MCSignType attempt_sign_{1.0};
Provides type erasure for MC moves.
Provides a type erased random number generator.