|
TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
|
#include <triqs/mc_tools/mc_generic.hpp>
Generic Monte Carlo class.
This class provides a generic Monte Carlo simulation framework. It allows to register MC moves and measures that fulfill the triqs::mc_tools::MCMove and triqs::mc_tools::MCMeasure concepts, respectively. Additionally, one can register auxiliary measures that are callable objects (see triqs::mc_tools::measure_aux).
Most MC simulations consist of two phases:
Both phases follow the same overall procedure:
As you can see, a cycle consists of cycle_length MC steps each of which does a single Metropolis accept/reject step. The after-cycle duties depend on the phase of the simulation and on input parameters. For example, in the accumulation phase, measurements are performed after each cycle, while in the warmup phase, moves might be calibrated to optimize the sampling procedure.
The simulation stops when one of the following conditions is met:
| MCSignType | Type of the sign/weight of a MC configuration (triqs::mc_tools::DoubleOrComplex). |
Definition at line 96 of file mc_generic.hpp.
Classes | |
| struct | run_param_t |
| User-provided MC simulation parameters for the run() method. More... | |
Public Member Functions | |
| mc_generic (const std::string &rng_name, int rng_seed, int verbosity_lvl) | |
| Construct a generic Monte Carlo class. | |
| int | accumulate (run_param_t const ¶ms) |
| Run the accumulations phase of the MC simulation. | |
| int | accumulate (std::int64_t ncycles, std::int64_t cycle_length, std::function< bool()> stop_callback, mpi::communicator c=mpi::communicator{}) |
| Run the accumulation phase of the MC simulation. | |
| template<typename T> | |
| auto | add_measure (T &&m, std::string name, bool enable_timer=true, bool enable_report=false) |
| Register a new MC measure. | |
| template<typename T> | |
| void | add_measure_aux (std::shared_ptr< T > const &m_ptr) |
| Register a new auxiliary MC measure. | |
| template<typename T> | |
| void | add_move (T &&m, std::string name, double weight=1.0) |
| Register a new MC move. | |
| void | clear_measures () |
| Remove all registered measures. | |
| void | collect_results (mpi::communicator const &c) |
| Collect results from multiple MPI processes. | |
| std::map< std::string, double > | get_acceptance_rates () const |
| Get the acceptance rates of all MC moves (see move_set::get_acceptance_rates). | |
| double | get_accumulation_time () const |
| Get the time spent in the accumulation phase in seconds. | |
| std::string | get_accumulation_time_HHMMSS () const |
| Get the time spent in the accumulation phase in hours, minutes and seconds. | |
| int | get_config_id () const |
| Get the ID of the current MC configuration. | |
| int | get_current_cycle_number () const |
| Get the number of cycles done. | |
| double | get_duration () const |
| Get the total time, i.e. the sum of the warmup and accumulation times, in seconds. | |
| int | get_nmeasures () const |
| Get the number of measurements done. | |
| double | get_percent () const |
| Get the percentage of the requested number of cycles done. | |
| random_generator & | get_rng () |
| Get a reference to the random number generator. | |
| auto | get_run_params () const |
| Get the default run parameters. | |
| MCSignType | get_sign () const |
| Get the current sign of the MC configuration. | |
| double | get_total_time () const |
| Get the total time, i.e. the sum of the warmup and accumulation times, in seconds. | |
| double | get_warmup_time () const |
| Get the time spent in the warmup phase in seconds. | |
| auto | get_warmup_time_HHMMSS () const |
| Get the time spent in the warmup phase in hours, minutes, and seconds. | |
| void | rm_measure (typename measure_set< MCSignType >::measure_itr_t const &it) |
| Remove a registered MC measure. | |
| int | run (run_param_t const ¶ms) |
| Run a generic MC simulation. | |
| int | run (std::int64_t ncycles, std::int64_t cycle_length, std::function< bool()> stop_callback, bool enable_measures, mpi::communicator c=mpi::communicator{}, bool enable_calibration=false) |
| Run a generic MC simulation. | |
| void | set_verbosity (int v) |
| Set the verbosity level. | |
| int | warmup (run_param_t const ¶ms) |
| Run the warumup phase of the MC simulation. | |
| int | warmup (std::int64_t ncycles, std::int64_t cycle_length, std::function< bool()> stop_callback, MCSignType initial_sign, mpi::communicator c=mpi::communicator{}) |
| Run the warumup phase of the MC simulation. | |
| int | warmup (std::int64_t ncycles, std::int64_t cycle_length, std::function< bool()> stop_callback, mpi::communicator c=mpi::communicator{}) |
| int | warmup_and_accumulate (std::int64_t ncycles_warmup, std::int64_t ncycles_acc, std::int64_t cycle_length, std::function< bool()> stop_callback, MCSignType initial_sign, mpi::communicator c=mpi::communicator{}) |
| Run the warumup and accumulation phases of the MC simulation. | |
| int | warmup_and_accumulate (std::int64_t ncycles_warmup, std::int64_t ncycles_acc, std::int64_t cycle_length, std::function< bool()> stop_callback, mpi::communicator c=mpi::communicator{}) |
Friends | |
| void | h5_read (h5::group g, std::string const &name, mc_generic &mc) |
| Read the MC simulation object from HDF5. | |
| void | h5_write (h5::group g, std::string const &name, mc_generic const &mc) |
| Write the MC simulation object to HDF5. | |
|
inline |
Construct a generic Monte Carlo class.
| rng_name | Name of the RNG to be used (see triqs::mc_tools::random_generator). |
| rng_seed | Seed for the RNG. |
| verbosity_lvl | Verbosity level (see triqs::utility::report_stream). |
Definition at line 174 of file mc_generic.hpp.
| int triqs::mc_tools::mc_generic< MCSignType >::accumulate | ( | run_param_t const & | params | ) |
Run the accumulations phase of the MC simulation.
Measurements are always enabled and calibration is always disabled, even if the corresponding parameters are set to true.
| params | User-provided MC simulation parameters (see run_param_t). |
Definition at line 193 of file mc_generic.cpp.
| int triqs::mc_tools::mc_generic< MCSignType >::accumulate | ( | std::int64_t | ncycles, |
| std::int64_t | cycle_length, | ||
| std::function< bool()> | stop_callback, | ||
| mpi::communicator | c = mpi::communicator{} ) |
Run the accumulation phase of the MC simulation.
| ncycles | Number of accumulation cycles to run ( \( < 1 \) to run indefinitely). |
| cycle_length | Number of MC steps per cycle ( \( > 0 \)). |
| stop_callback | Callback function to check if the simulation should be stopped (returns true to stop). |
| c | MPI communicator. |
Definition at line 226 of file mc_generic.cpp.
|
inline |
Register a new MC measure.
| T | triqs::mc_tools::MCMeasure type. |
| m | MC measure to register. |
| name | Name of the measure. |
| enable_timer | Enable the timer in the measure::accumulate and measure::collect_results methods. |
| enable_report | Enable the measure::report method. |
Definition at line 206 of file mc_generic.hpp.
|
inline |
Register a new auxiliary MC measure.
| T | Type of the auxiliary measure. |
| m_ptr | Shared pointer to the auxiliary MC measure to register. |
Definition at line 216 of file mc_generic.hpp.
|
inline |
Register a new MC move.
| T | triqs::mc_tools::MCMove type. |
| m | MC move to register. |
| name | Name of the move. |
| weight | Weight of the move which is proportional to its proposal probability ( \( \geq 0 \)). |
Definition at line 194 of file mc_generic.hpp.
| void triqs::mc_tools::mc_generic< MCSignType >::collect_results | ( | mpi::communicator const & | c | ) |
Collect results from multiple MPI processes.
| c | MPI communicator. |
Definition at line 245 of file mc_generic.cpp.
|
inline |
Remove a registered MC measure.
| it | Iterator to the measure to remove. |
Definition at line 222 of file mc_generic.hpp.
| int triqs::mc_tools::mc_generic< MCSignType >::run | ( | run_param_t const & | params | ) |
Run a generic MC simulation.
| params | User-provided MC simulation parameters (see run_param_t). |
Definition at line 48 of file mc_generic.cpp.
| int triqs::mc_tools::mc_generic< MCSignType >::run | ( | std::int64_t | ncycles, |
| std::int64_t | cycle_length, | ||
| std::function< bool()> | stop_callback, | ||
| bool | enable_measures, | ||
| mpi::communicator | c = mpi::communicator{}, | ||
| bool | enable_calibration = false ) |
Run a generic MC simulation.
| ncycles | Number of MC cycles to run ( \( < 1 \) to run indefinitely). |
| cycle_length | Number of MC steps per cycle ( \( > 0 \)). |
| stop_callback | Callback function to check if the simulation should be stopped (returns true to stop). |
| enable_measures | Enable measurements at the end of each cycle (false during warmup phase). |
| c | MPI communicator. |
| enable_calibration | Enable calibration of the moves after each cycle (false during accumulation phase). |
Definition at line 203 of file mc_generic.cpp.
| int triqs::mc_tools::mc_generic< MCSignType >::warmup | ( | run_param_t const & | params | ) |
Run the warumup phase of the MC simulation.
Measurements are always disabled, even if the enable_measures parameter is set to true.
| params | User-provided MC simulation parameters (see run_param_t). |
Definition at line 185 of file mc_generic.cpp.
| int triqs::mc_tools::mc_generic< MCSignType >::warmup | ( | std::int64_t | ncycles, |
| std::int64_t | cycle_length, | ||
| std::function< bool()> | stop_callback, | ||
| MCSignType | initial_sign, | ||
| mpi::communicator | c = mpi::communicator{} ) |
Run the warumup phase of the MC simulation.
| ncycles | Number of warumup cycles to run ( \( < 1 \) to run indefinitely). |
| cycle_length | Number of MC steps per cycle ( \( > 0 \)). |
| stop_callback | Callback function to check if the simulation should be stopped (returns true to stop). |
| initial_sign | Sign of the initial MC configuration. |
| c | MPI communicator. |
Definition at line 215 of file mc_generic.cpp.
| int triqs::mc_tools::mc_generic< MCSignType >::warmup | ( | std::int64_t | ncycles, |
| std::int64_t | cycle_length, | ||
| std::function< bool()> | stop_callback, | ||
| mpi::communicator | c = mpi::communicator{} ) |
The same as warmup(std::int64_t, std::int64_t, std::function<bool()>, MCSignType, mpi::communicator) but without specifying the initial sign.
Definition at line 221 of file mc_generic.cpp.
| int triqs::mc_tools::mc_generic< MCSignType >::warmup_and_accumulate | ( | std::int64_t | ncycles_warmup, |
| std::int64_t | ncycles_acc, | ||
| std::int64_t | cycle_length, | ||
| std::function< bool()> | stop_callback, | ||
| MCSignType | initial_sign, | ||
| mpi::communicator | c = mpi::communicator{} ) |
Run the warumup and accumulation phases of the MC simulation.
| ncycles_warmup | Number of warumup cycles to run ( \( < 1 \) to run indefinitely). |
| ncycles_acc | Number of accumulation cycles to run ( \( < 1 \) to run indefinitely). |
| cycle_length | Number of MC steps per cycle ( \( > 0 \)). |
| stop_callback | Callback function to check if the simulation should be stopped (returns true to stop). |
| initial_sign | Sign of the initial MC configuration. |
| c | MPI communicator. |
Definition at line 231 of file mc_generic.cpp.
| int triqs::mc_tools::mc_generic< MCSignType >::warmup_and_accumulate | ( | std::int64_t | ncycles_warmup, |
| std::int64_t | ncycles_acc, | ||
| std::int64_t | cycle_length, | ||
| std::function< bool()> | stop_callback, | ||
| mpi::communicator | c = mpi::communicator{} ) |
The same as warmup_and_accumulate(std::int64_t, std::int64_t, std::int64_t, std::function<bool()>, MCSignType, mpi::communicator) but without specifying the initial sign.
Definition at line 240 of file mc_generic.cpp.
|
friend |
Read the MC simulation object from HDF5.
It reads the registered moves and measures as well as the number of cycles and measures that have been done and the sign of the last configuration.
| g | h5::group to be read from. |
| name | Name of the subgroup. |
| mc | MC simulation object to be read into. |
Definition at line 398 of file mc_generic.hpp.
|
friend |
Write the MC simulation object to HDF5.
It writes the registered moves and measures as well as the number of cycles and measures that have been done and the sign of the current configuration.
| g | h5::group to be written to. |
| name | Name of the subgroup. |
| mc | MC simulation object to be written. |
Definition at line 379 of file mc_generic.hpp.