Rosetta Protocols  2014.16.56682
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
protocols::canonical_sampling::MpiParallelTempering Class Reference

Manage several replicas with periodic temperature swapping. More...

#include <MpiParallelTempering.hh>

Public Member Functions

 MpiParallelTempering ()
 Default constructor. More...
 
 ~MpiParallelTempering ()
 Non-trivial destructor used to free some C-style arrays. More...
 
 MpiParallelTempering (MpiParallelTempering const &)
 Copy constructor. More...
 
MpiParallelTemperingoperator= (MpiParallelTempering const &)
 Assignment operator. More...
 
std::string get_name () const
 Each derived class must specify its name. The class name. More...
 
protocols::moves::MoverOP clone () const
 Return a clone of the Mover object. More...
 
virtual protocols::moves::MoverOP fresh_instance () const
 Generates a new Mover object freshly created with the default ctor. More...
 
virtual void initialize_simulation (core::pose::Pose &pose, MetropolisHastingsMover const &mover, core::Size cycle)
 Callback executed before any Monte Carlo trials are attempted. More...
 
core::Real temperature_move (core::pose::Pose &pose, MetropolisHastingsMover &mover, core::Real score)
 Execute a temperature move if necessary. More...
 
virtual void finalize_simulation (core::pose::Pose &pose, MetropolisHastingsMover const &metropolis_hastings_mover)
 Callback executed after all Monte Carlo trials are completed. More...
 
- Public Member Functions inherited from protocols::canonical_sampling::TemperatureController
 TemperatureController ()
 Default constructor. More...
 
 TemperatureController (TemperatureController const &other)
 Default constructor. More...
 
virtual void apply (core::pose::Pose &)
 No-op implemented only to satisfy the Mover interface. More...
 
virtual bool reinitialize_for_each_job () const
 Return false. This class does not need to be reinitialized for each job. More...
 
virtual bool reinitialize_for_new_input () const
 Return false. This class does not need to be reinitialized for new input. More...
 
virtual void parse_my_tag (utility::tag::TagCOP tag, basic::datacache::DataMap &data, protocols::filters::Filters_map const &filters, protocols::moves::Movers_map const &movers, core::pose::Pose const &pose)
 Called by MoverFactory when constructing new Movers. Takes care of the specific mover's parsing. More...
 
core::Real temperature () const
 Return the temperature of the underlying MonteCarlo object. More...
 
core::Real temperature (core::Size level) const
 Return the temperature of the given level. More...
 
core::Size temperature_level () const
 Return the current temperature level. More...
 
core::Size n_temp_levels () const
 Return the number of temperature levels used by this controller. More...
 
protocols::moves::MonteCarloCOP monte_carlo () const
 Return const access to the MonteCarlo object being controlled. More...
 
void set_monte_carlo (protocols::moves::MonteCarloOP monte_carlo)
 Set the MonteCarlo object to be controlled. More...
 
- Public Member Functions inherited from protocols::moves::Mover
 Mover ()
 
virtual ~Mover ()
 
virtual MoverSP create ()
 
virtual void apply (core::io::serialization::PipeMap &pmap)
 
virtual void parse_state (SerializableState const &state)
 
virtual void parse_def (utility::lua::LuaObject const &def, utility::lua::LuaObject const &score_fxns, utility::lua::LuaObject const &tasks, MoverCacheSP cache)
 
virtual void save_state (SerializableState &state)
 
 Mover (std::string const &type_name)
 sets the type for a mover; name_ has been removed (2010/05/14) More...
 
 Mover (Mover const &other)
 
Moveroperator= (Mover const &other)
 assignment operator More...
 
virtual core::Real last_proposal_density_ratio ()
 
std::string const & type () const
 
std::string get_current_tag () const
 A tag is a unique identifier used to identify structures produced by this Mover. get_current_tag() returns the tag, and set_current_tag( std::string tag ) sets the tag. This functionality is not intended for use with the 2008 job distributor. More...
 
void set_current_tag (std::string const &new_tag)
 
virtual void set_input_pose (PoseCOP pose)
 setter for poses contained for rms More...
 
virtual void set_native_pose (PoseCOP pose)
 setter for native poses contained for rms -— we should get rid of this method? it is widely used, but a bit unsafe More...
 
PoseCOP get_input_pose () const
 
PoseCOP get_native_pose () const
 
virtual void test_move (Pose &pose)
 : Unit test support function. Apply one move to a given pose. Allows extra test specific functions to be called before applying More...
 
void type (const std::string &type_in)
 
std::string get_type () const
 
MoverStatus get_last_move_status () const
 end parser interface, start Job Distributor interface///////////// More...
 
void reset_status ()
 resets status to SUCCESS, meant to be used before an apply(). The job distributor (august 08 vintage) uses this to ensure non-accumulation of status across apply()s. More...
 
virtual core::pose::PoseOP get_additional_output ()
 Mechanism by which a mover may return multiple output poses from a single input pose. More...
 
virtual void clear_info ()
 Strings container can be used to return miscellaneous info (as std::string) from a mover, such as notes about the results of apply(). The job distributor (Apr 09 vintage) will check this function to see if your protocol wants to add string info to the Job that ran this mover. One way this can be useful is that later, a JobOutputter may include/append this info to an output file. More...
 
virtual Stringsinfo ()
 non-const accessor More...
 
virtual Strings const & info () const
 const accessor More...
 
void set_current_job (protocols::jobdist::BasicJobCOP job)
 
jobdist::BasicJobCOP get_current_job () const
 
virtual void show (std::ostream &output=std::cout) const
 Outputs details about the Mover, including current settings. More...
 

Protected Member Functions

int rank ()
 Return the rank of the MPI process being used to simulate this specific temperature level. More...
 
- Protected Member Functions inherited from protocols::canonical_sampling::TemperatureController
protocols::moves::MonteCarloOP monte_carlo ()
 Return non-const access to the MonteCarlo object being controlled. More...
 
void set_defaults ()
 Help the constructor initialize new objects. More...
 
virtual void init_from_options ()
 Assign user-specified command-line values to data members. More...
 
virtual bool init_from_file (std::string const &filename)
 Initialize temperatures and weights from a file. More...
 
virtual void write_to_file (std::string const &file_in, std::string const &output_name, utility::vector1< core::Real > const &wcounts)
 Save temperatures and weights to a file. More...
 
void generate_temp_range (core::Real temp_low, core::Real temp_high, core::Size n_levels, InterpolationType interpolation=linear)
 Explicitly set the temperature levels by interpolating the given parameters. More...
 
void set_temperatures (utility::vector1< core::Real > const &)
 Explicitly set the temperature levels. More...
 
core::Size current_temp ()
 Return the current temperature level. Identical to temperature_level() as far as I can tell. More...
 
void set_current_temp (core::Size new_temp)
 Set the temperature to the given level. More...
 
bool check_temp_consistency ()
 Assert that the current temperature of the MonteCarlo object agrees with the current temperature level of this object. More...
 
void clear ()
 Forget all temperature levels and return to an uninitialized state. More...
 
bool time_for_temp_move ()
 Return true if a temperature move should be made on this iteration. More...
 
bool stats_line_output () const
 Return true if a statistics summary should be written. More...
 
bool stats_silent_output () const
 Return true if a statistics summary should be inserted into a silent file. More...
 
std::string const & stats_file () const
 Return the name of the silent file into which statistics should be recorded. More...
 
- Protected Member Functions inherited from protocols::moves::Mover
void set_last_move_status (MoverStatus status)
 nonvirtual setter for MoverStatus last_status_. Protected means that only the mover itself will be able to change its own status. The job distributor (august 08 vintage) is aware of status set with this function and will do what the MoverStatus says. More...
 

Private Types

typedef TemperatureController Parent
 
typedef utility::vector1
< std::pair< int, int > > 
ExchangeSchedule
 

Private Member Functions

void allocate_buffers (core::Size)
 Allocate the arrays used for MPI communication. More...
 
void deallocate_buffers ()
 Deallocate the arrays used for MPI communication. More...
 
void setup_exchange_schedule (Size nlevels)
 Setup the algorithm used to propose temperature swaps. More...
 
void shuffle_temperatures (MetropolisHastingsMover &mover, double *energies)
 Attempt swaps between half of the temperature level pairs. More...
 

Private Attributes

int rank_
 
utility::vector0
< ExchangeSchedule
exchange_schedules_
 
core::Size last_exchange_schedule_
 
doublelast_energies_
 
intrank2tlevel_
 
inttlevel2rank_
 
std::map< std::pair< int, int >
, core::Size
exchange_attempts_
 
std::map< std::pair< int, int >
, core::Size
exchange_accepts_
 
clock_t start_time_
 
clock_t total_mpi_wait_time_
 

Additional Inherited Members

- Public Types inherited from protocols::moves::Mover
typedef utility::tag::TagCOP TagCOP
 
typedef core::pose::Pose Pose
 
typedef core::pose::PoseCOP PoseCOP
 
typedef
protocols::filters::Filters_map 
Filters_map
 
typedef std::list< std::stringStrings
 
- Static Public Member Functions inherited from protocols::canonical_sampling::TemperatureController
static void register_options ()
 Register the options used by this mover with the global options system. More...
 
- Static Public Member Functions inherited from protocols::moves::Mover
static std::string name ()
 
static void register_options ()
 Overload this static method if you access options within the mover. More...
 

Detailed Description

Manage several replicas with periodic temperature swapping.

Parallel tempering is a standard Monte Carlo technique. The idea is to simulate the same system at several different temperatures, and to periodically swap the temperatures between the simulations. The simulations at higher temperatures sample more broadly, while the simulations at lower temperatures sample more deeply. By swapping temperatures (such that detailed balance is maintained) the best of both worlds is obtained. In order for a parallel tempering simulation to be successful, the replicas need to have good overlap. That is to say, there has to be a reasonable chance of observing the system at temperature levels one above and one below the current. If this is not the case, most of the temperature moves will be rejected and more levels need to be added.

This implementation requires multi-threading, as provided by the MPI library. In addition, the number of replicas must exactly match the number of threads available to the job. If there is a mismatch an error will be thrown. On some systems it can be very challenging to compile Rosetta with support for MPI, but you can usually find help on the RosettaCommons forum. Also be aware that not every class in this module is thread-safe. For example, the DbTrajectoryReporter will attempt to write to the database from several threads at once, which is forbidden when using SQLite.

Note that the only way to set the temperature range used for simulated annealing is to use the command line. This is something I'd be interested in changed at some point, but for right now it's not a deal-breaker. The relevant options are:

-tempering::temp::range <low> <high>
-tempering::temp::low <low> -tempering::temp::high <high>
-tempering::temp::levels <levels>

Member Typedef Documentation

Constructor & Destructor Documentation

protocols::canonical_sampling::MpiParallelTempering::MpiParallelTempering ( )
protocols::canonical_sampling::MpiParallelTempering::~MpiParallelTempering ( )

Non-trivial destructor used to free some C-style arrays.

References deallocate_buffers().

protocols::canonical_sampling::MpiParallelTempering::MpiParallelTempering ( MpiParallelTempering const &  other)

Copy constructor.

References utility_exit_with_message.

Member Function Documentation

void protocols::canonical_sampling::MpiParallelTempering::allocate_buffers ( core::Size  nlevels)
private

Allocate the arrays used for MPI communication.

Normally it's better to use vectors instead of C-style arrays, because manually allocating and deallocating arrays is error-prone. However, to use MPI there's no alternative.

References deallocate_buffers(), last_energies_, rank2tlevel_, tlevel2rank_, and protocols::canonical_sampling::tr.

Referenced by initialize_simulation(), and operator=().

MoverOP protocols::canonical_sampling::MpiParallelTempering::clone ( ) const
virtual

Return a clone of the Mover object.

clone is meant to return an OP'ed deep copy of this object. This really should be a pure virtual in the base class, but adding pure virtuals to Mover would massively disrupt the code. This default implementation crashes at runtime instead of compiletime if you try to call it. If this code is causing you problems, your Mover needs to override this function.

Reimplemented from protocols::moves::Mover.

References MpiParallelTempering().

void protocols::canonical_sampling::MpiParallelTempering::deallocate_buffers ( )
private

Deallocate the arrays used for MPI communication.

Normally it's better to use vectors instead of C-style arrays, because manually allocating and deallocating arrays is error-prone. However, to use MPI there's no alternative.

References last_energies_, rank2tlevel_, and tlevel2rank_.

Referenced by allocate_buffers(), finalize_simulation(), operator=(), and ~MpiParallelTempering().

void protocols::canonical_sampling::MpiParallelTempering::finalize_simulation ( core::pose::Pose pose,
MetropolisHastingsMover const &  mover 
)
virtual
MoverOP protocols::canonical_sampling::MpiParallelTempering::fresh_instance ( ) const
virtual

Generates a new Mover object freshly created with the default ctor.

fresh_instance is meant to return a new object of this class, created with the default constructor. This really should be a pure virtual in the base class, but adding pure virtuals to Mover would massively disrupt the code. This default implementation crashes at runtime instead of compiletime if you try to call it. If this code is causing you problems, your Mover needs to override this function. This is used by the August 08 job distributor.

Reimplemented from protocols::moves::Mover.

References MpiParallelTempering().

string protocols::canonical_sampling::MpiParallelTempering::get_name ( ) const
virtual

Each derived class must specify its name. The class name.

Implements protocols::moves::Mover.

void protocols::canonical_sampling::MpiParallelTempering::initialize_simulation ( core::pose::Pose pose,
MetropolisHastingsMover const &  mover,
core::Size  cycle 
)
virtual
MpiParallelTempering & protocols::canonical_sampling::MpiParallelTempering::operator= ( MpiParallelTempering const &  other)
int protocols::canonical_sampling::MpiParallelTempering::rank ( )
inlineprotected

Return the rank of the MPI process being used to simulate this specific temperature level.

References rank_.

Referenced by finalize_simulation(), setup_exchange_schedule(), and temperature_move().

void protocols::canonical_sampling::MpiParallelTempering::setup_exchange_schedule ( Size  nlevels)
private

Setup the algorithm used to propose temperature swaps.

This algorithm is surprisingly complex. The gist of it goes like this. Half of the time, swaps between levels 1->2, 3->4, and so on are considered. The other half of the time, swaps between levels 2->3, 4->5, and so on are considered. In this way, every swap is considered with the same frequency, and no level will ever get swapped twice in one move. This method setups up a data structure to implement this algorithm an populates it based on the number of replicas being used.

See also
shuffle_temperatures()

References exchange_accepts_, exchange_attempts_, exchange_schedules_, list, rank(), and protocols::canonical_sampling::tr.

Referenced by initialize_simulation().

void protocols::canonical_sampling::MpiParallelTempering::shuffle_temperatures ( MetropolisHastingsMover mover,
double energies 
)
private
Real protocols::canonical_sampling::MpiParallelTempering::temperature_move ( core::pose::Pose pose,
MetropolisHastingsMover mover,
core::Real  score 
)
virtual

Execute a temperature move if necessary.

This method blocks until it is reached by every thread. Then the last energies recorded in each replica are communicated to all the other replicas, and the root thread coordinates the temperature swap. Once all of this is done, the simulation continues. Note that this can produce a significant amount of dead time if called too often. At the end of the simulation, the amount of time spent waiting for MPI gets reported to the tracer. Use this information to decide how often temperature swaps should be attempted.

See also
shuffle_temperatures()

Implements protocols::canonical_sampling::TemperatureController.

References protocols::canonical_sampling::TemperatureController::check_temp_consistency(), last_energies_, MPI_ONLY, rank(), rank2tlevel_, score, protocols::canonical_sampling::TemperatureController::set_current_temp(), basic::SHRINK_FACTOR, shuffle_temperatures(), protocols::canonical_sampling::TemperatureController::temperature(), protocols::canonical_sampling::TemperatureController::time_for_temp_move(), and total_mpi_wait_time_.

Member Data Documentation

std::map<std::pair<int, int>, core::Size> protocols::canonical_sampling::MpiParallelTempering::exchange_accepts_
private
std::map<std::pair<int, int>, core::Size> protocols::canonical_sampling::MpiParallelTempering::exchange_attempts_
private
utility::vector0< ExchangeSchedule > protocols::canonical_sampling::MpiParallelTempering::exchange_schedules_
private
double* protocols::canonical_sampling::MpiParallelTempering::last_energies_
private
core::Size protocols::canonical_sampling::MpiParallelTempering::last_exchange_schedule_
private
int* protocols::canonical_sampling::MpiParallelTempering::rank2tlevel_
private
int protocols::canonical_sampling::MpiParallelTempering::rank_
private

Referenced by initialize_simulation(), and rank().

clock_t protocols::canonical_sampling::MpiParallelTempering::start_time_
private
int* protocols::canonical_sampling::MpiParallelTempering::tlevel2rank_
private
clock_t protocols::canonical_sampling::MpiParallelTempering::total_mpi_wait_time_
private

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