TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
triqs::mc_tools::move< MCSignType >

#include <triqs/mc_tools/mc_move.hpp>

Detailed Description

template<DoubleOrComplex MCSignType>
class triqs::mc_tools::move< MCSignType >

Type erasure class for MC moves.

It takes any type that models the triqs::mc_tools::MCMove concept and erases its type.

The sign of the new configuration, if accepted, is calculated as new_sign = old_sign * sgn(attempt()) * accept(). If attempt() returns the full MC acceptance ratio (including all signs), then accept() should always return \( 1 \). Otherwise, the calculation of the sign can be partially or fully done in the accept() method.

Optionally, the following methods can be defined:

  • reject(): Callback function if the previously proposed move is rejected.
  • calibrate(mpi::communicator const &): Calibrates the move. Usually done during the warm-up phase.
  • collect_statistics(mpi::communicator const &): Collects statistics from multiple MPI processes.

Optionally, the following free functions can be defined:

  • h5_write(h5::group, std::string const &, T const &) const: Writes the move object of type T to HDF5.
  • h5_read(h5::group, std::string const &, T &): Reads the move object of type T from HDF5.
Template Parameters
MCSignTypeType of the sign/weight of a MC configuration (triqs::mc_tools::DoubleOrComplex).

Definition at line 68 of file mc_move.hpp.

Public Member Functions

 move (move &&)=default
 Default move constructor leaves the moved from object in an empty state.
 move (move const &)=delete
 Deleted copy constructor.
template<typename T>
requires (MCMove<T, MCSignType> && !std::is_same_v<T, move>)
 move (T m)
 Constructor takes an object that models the triqs::mc_tools::MCMove concept and erases its type.
MCSignType accept ()
 Accept the new MC configuration.
auto acceptance_rate () const
 Get the acceptance rate of the move. You need to call collect_statistics() first.
MCSignType attempt ()
 Propose a new MC configuration.
void calibrate (mpi::communicator const &c)
 Optional callback function to calibrate the move.
void clear_statistics ()
 Reset the gathered statistics to their initial states.
void collect_statistics (mpi::communicator const &c)
 Collect statistics from multiple MPI processes.
double duration () const
 Get the duration of the cumulative attempt(), accept(), and reject() calls.
std::map< std::string, double > get_acceptance_rates () const
 Get the acceptance rates of all moves in case it is a move set.
std::string get_statistics (std::string const &name, std::string const &prefix="") const
 Get a formatted string showing the statistics of the move (and other moves if it is a move set).
std::string get_timings (std::string const &name, std::string const &prefix="") const
 Get a formatted string showing the runtime of the move.
auto is_set () const
 Is the move object a move set?
auto n_accepted_config () const
 Get the number of accepted configurations, i.e. the number of times accept() has been called.
auto n_proposed_config () const
 Get the number of proposed configurations, i.e. the number of times attempt() has been called.
moveoperator= (move &&)=default
 Default move assignment operator leaves the moved from object in an empty state.
moveoperator= (move const &)=delete
 Deleted copy assignment operator.
void reject ()
 Optional callback function if the proposed move is rejected.

Friends

void h5_read (h5::group g, std::string const &name, move &m)
 Read the move object from HDF5.
void h5_write (h5::group g, std::string const &name, move const &m)
 Write the move object to HDF5.

Constructor & Destructor Documentation

◆ move()

template<DoubleOrComplex MCSignType>
template<typename T>
requires (MCMove<T, MCSignType> && !std::is_same_v<T, move>)
triqs::mc_tools::move< MCSignType >::move ( T m)
inline

Constructor takes an object that models the triqs::mc_tools::MCMove concept and erases its type.

Template Parameters
TOriginal type of the MC move object.
Parameters
mMC move object to have its type erased.

Definition at line 140 of file mc_move.hpp.

Member Function Documentation

◆ accept()

template<DoubleOrComplex MCSignType>
MCSignType triqs::mc_tools::move< MCSignType >::accept ( )
inline

Accept the new MC configuration.

Returns
A possible sign correction to the acceptance ratio returned by attempt().

Definition at line 170 of file mc_move.hpp.

◆ attempt()

template<DoubleOrComplex MCSignType>
MCSignType triqs::mc_tools::move< MCSignType >::attempt ( )
inline

Propose a new MC configuration.

Returns
The acceptance ratio of the proposed move.

Definition at line 158 of file mc_move.hpp.

◆ calibrate()

template<DoubleOrComplex MCSignType>
void triqs::mc_tools::move< MCSignType >::calibrate ( mpi::communicator const & c)
inline

Optional callback function to calibrate the move.

Does nothing if the original type does not implement a calibrate(mpi::communicator const &) method.

Parameters
cMPI communicator.

Definition at line 193 of file mc_move.hpp.

◆ clear_statistics()

template<DoubleOrComplex MCSignType>
void triqs::mc_tools::move< MCSignType >::clear_statistics ( )

Reset the gathered statistics to their initial states.

If the move is a move set, it calls the clear_statistics() method for all moves in the set.

Definition at line 44 of file mc_move.cpp.

◆ collect_statistics()

template<DoubleOrComplex MCSignType>
void triqs::mc_tools::move< MCSignType >::collect_statistics ( mpi::communicator const & c)

Collect statistics from multiple MPI processes.

It sets the total (over all MPI processes) acceptance rate and optionally calls the collect_statistics(mpi::communicator const &) method of the original type.

Parameters
cMPI communicator.

Definition at line 37 of file mc_move.cpp.

◆ get_acceptance_rates()

template<DoubleOrComplex MCSignType>
std::map< std::string, double > triqs::mc_tools::move< MCSignType >::get_acceptance_rates ( ) const
inlinenodiscard

Get the acceptance rates of all moves in case it is a move set.

Returns
std::map containing the names of the moves and their acceptance rates if the move is a move set, otherwise an empty map.

Definition at line 246 of file mc_move.hpp.

◆ get_statistics()

template<DoubleOrComplex MCSignType>
std::string triqs::mc_tools::move< MCSignType >::get_statistics ( std::string const & name,
std::string const & prefix = "" ) const
nodiscard

Get a formatted string showing the statistics of the move (and other moves if it is a move set).

Parameters
nameName of the move.
prefixPrefix string to be added to the beginning of each line.
Returns
String containing the number of proposed and accepted configurations and the acceptance rate.

Definition at line 52 of file mc_move.cpp.

◆ get_timings()

template<DoubleOrComplex MCSignType>
std::string triqs::mc_tools::move< MCSignType >::get_timings ( std::string const & name,
std::string const & prefix = "" ) const
nodiscard

Get a formatted string showing the runtime of the move.

Parameters
nameName of the move.
prefixPrefix string to be added to the beginning of each line.
Returns
String containing the duration of the move calls.

Definition at line 61 of file mc_move.cpp.

◆ reject()

template<DoubleOrComplex MCSignType>
void triqs::mc_tools::move< MCSignType >::reject ( )
inline

Optional callback function if the proposed move is rejected.

Does nothing if the original type does not implement a reject() method.

Definition at line 182 of file mc_move.hpp.

◆ h5_read

template<DoubleOrComplex MCSignType>
void h5_read ( h5::group g,
std::string const & name,
move< MCSignType > & m )
friend

Read the move object from HDF5.

Does nothing if there is no specialized h5_read function for the original move object.

Parameters
gh5::group to be read from.
nameName of the dataset/subgroup.
mMove object to be read into.

Definition at line 271 of file mc_move.hpp.

◆ h5_write

template<DoubleOrComplex MCSignType>
void h5_write ( h5::group g,
std::string const & name,
move< MCSignType > const & m )
friend

Write the move object to HDF5.

Does nothing if there is no specialized h5_write function for the original move object.

Parameters
gh5::group to be written to.
nameName of the dataset/subgroup.
mMove object to be written.

Definition at line 260 of file mc_move.hpp.


The documentation for this class was generated from the following files: