Loading...
Searching...
No Matches
PLMD::Checkpointing Class Reference

Exact-restart checkpoint of a PLUMED run, configured by the CHECKPOINT action. More...

#include <Checkpointing.h>

Public Member Functions

 Checkpointing (PlumedMain &plumed)
 
 ~Checkpointing ()
 
void atRunEnd (bool fromDestructor=false)
 At the end of the run (cmd "runFinalJobs", before the final jobs, or, if it was not called, when PLUMED is finalized, fromDestructor): if the MD engine never sent the checkpointing signal, write the state after the last step, i.e.
 
void atStepEnd ()
 To be called at the end of the update of a step.
 
void atStepStart (bool signal)
 To be called before any computation of the current step, possibly more than once per step.
 
void disableTrimming ()
 RESTART NO_TRIM: the files are appended as they are.
 
bool enabled () const
 
long long int getEngineRestartStep () const
 
const std::string & getPath () const
 
bool isRestartingFromCheckpoint () const
 True after restartFrom() has been called (a checkpoint restart is in progress or done).
 
void markSnapshotFile (const std::string &fileName)
 Mark a file as rewritten from scratch at every write (called by OFile::rewind).
 
void registerOutputFile (OFile &file)
 Record a file opened for writing (called by OFile::open) and, after a restart, restore the header of its last line so that it is not printed again.
 
void restartFrom (const std::string &fileName)
 Read a checkpoint, trim the output files and switch restart on (called by the CHECKPOINT action, before any other action opens a file).
 
void restoreLastFields (OFile &file) const
 After a restart, restore the field header of the last line of a file appended to (from the checkpoint, or found when trimming it), so that it is not printed again.
 
void setEngineRestartStep (long long int step)
 Step from which the MD engine restarts (cmd "setRestartStep", before init).
 
void setup (const std::string &fileName, long long int checkpointStride)
 Configure checkpoint writing (called by the CHECKPOINT action).
 
std::string suffixedPath (const std::string &fileName) const
 Full path of the checkpoint file for this replica, given its base name.
 
void trimAtRestart (const std::string &fileName, bool keepRestartStep=false)
 Remove from a file the lines written at or after the restart step, i.e.
 
void trimOutputFileAtRestart (Action &action, const std::string &name, bool nosuffix=false)
 For an action that reads one of its output files at restart before appending to it (e.g.
 
bool trimsAtRestart () const
 True when the files appended at restart are trimmed at the restart step: the MD engine gave the step, trimming was not switched off, and the run does not restart from a checkpoint (which trims the files to the recorded sizes).
 

Static Public Member Functions

static std::string finalName (const std::string &fileName)
 Name of the checkpoint written at the end of the run (plumed_final.cpt), without the replica suffix.
 
static std::string taggedName (const std::string &fileName, const std::string &tag)
 plumed.cpt -> plumed_prev.cpt for the tag _prev (without the replica suffix)
 

Private Member Functions

void restore ()
 
void trimFiles (CheckpointReader &reader)
 
void write (long long int step, const std::string &outPath, const std::string &outPrevPath)
 

Static Private Member Functions

static std::string crcOfTail (const std::string &fname, unsigned long long size)
 

Private Attributes

long long int engineRestartStep =-1
 Step from which the MD engine restarts (cmd "setRestartStep"), -1 if not given.
 
bool engineRestartStepChecked =false
 The first step presented after a restart has been compared with engineRestartStep.
 
std::string file
 Base name given by the user (empty: checkpointing is off)
 
std::string finalPath
 Path of the checkpoint written at the end of the run (atRunEnd)
 
std::map< std::string, std::string > lastFields
 Field headers recorded in the checkpoint being restored, or found when trimming a file at the restart step, by path.
 
long long int lastStep =-1
 Last step presented and difference between the last two steps (to know the next one)
 
long long int lastWrittenStep =-1
 
std::vector< std::string > outputFiles
 Paths of all the files opened for writing in this run.
 
std::string path
 Full path (with the replica suffix) and path of the previous checkpoint.
 
std::unique_ptr< CheckpointReader > pending
 Checkpoint being restored, consumed at the first step.
 
PlumedMain & plumed
 
std::string prevPath
 
long long int restartStep =-1
 Step stored in the checkpoint being restored (-1: no restart)
 
bool runEndHandled =false
 The end of the run has been handled (atRunEnd called)
 
bool signalReceived =false
 A checkpointing signal was received from the MD engine in this run.
 
std::set< std::string > snapshotFiles
 Files rewritten from scratch at every write (OFile::rewind): they are not trimmed at restart, since the next write replaces them anyway.
 
bool stepComplete =false
 The last step presented has been completed (update done)
 
long long int stepIncrement =1
 
long long int stride =0
 
bool trimEnabled =true
 False with RESTART NO_TRIM.
 
std::set< std::string > trimmedFiles
 Files already trimmed at the restart step (or left as they are)
 
bool warnedAboutUnportedState =false
 

Detailed Description

Exact-restart checkpoint of a PLUMED run, configured by the CHECKPOINT action.

The checkpoint for step S captures the state at the start of S (after the update of step S-1 and before anything of S is computed) together with the sizes of all the output files after a flush at that moment. On restart the files are truncated to those sizes and the MD engine presents step S again, which is replayed in full. No action needs to know that a step is repeated.

The checkpoint is written when the MD engine sends the checkpointing signal (cmd "doCheckPoint") or, with STRIDE, every STRIDE steps. It is a separate file, one per replica (usual suffix), written atomically; the previous one is kept with a _prev suffix. If the MD engine never sends the signal, a checkpoint of the state after the last step (i.e. for the next step) is written at the end of the run (cmd "runFinalJobs", or the destructor of PlumedMain), with a _final suffix.

Constructor & Destructor Documentation

◆ Checkpointing()

PLMD::Checkpointing::Checkpointing ( PlumedMain & plumed)
explicit

◆ ~Checkpointing()

PLMD::Checkpointing::~Checkpointing ( )
default

Member Function Documentation

◆ atRunEnd()

void PLMD::Checkpointing::atRunEnd ( bool fromDestructor = false)

At the end of the run (cmd "runFinalJobs", before the final jobs, or, if it was not called, when PLUMED is finalized, fromDestructor): if the MD engine never sent the checkpointing signal, write the state after the last step, i.e.

at the start of the next one, to FILE with the suffix _final (plumed_final.cpt). Only the first call does something; nothing is written if the last step was not completed or, from the destructor, if MPI is already finalized.

◆ atStepEnd()

void PLMD::Checkpointing::atStepEnd ( )
inline

To be called at the end of the update of a step.

◆ atStepStart()

void PLMD::Checkpointing::atStepStart ( bool signal)

To be called before any computation of the current step, possibly more than once per step.

Restores the pending checkpoint at the first step after a restart, and writes a checkpoint when requested by the signal or by the stride.

◆ crcOfTail()

std::string PLMD::Checkpointing::crcOfTail ( const std::string & fname,
unsigned long long size )
staticprivate

◆ disableTrimming()

void PLMD::Checkpointing::disableTrimming ( )
inline

RESTART NO_TRIM: the files are appended as they are.

◆ enabled()

bool PLMD::Checkpointing::enabled ( ) const
inline

◆ finalName()

std::string PLMD::Checkpointing::finalName ( const std::string & fileName)
static

Name of the checkpoint written at the end of the run (plumed_final.cpt), without the replica suffix.

◆ getEngineRestartStep()

long long int PLMD::Checkpointing::getEngineRestartStep ( ) const
inline

◆ getPath()

const std::string & PLMD::Checkpointing::getPath ( ) const
inline

◆ isRestartingFromCheckpoint()

bool PLMD::Checkpointing::isRestartingFromCheckpoint ( ) const
inline

True after restartFrom() has been called (a checkpoint restart is in progress or done).

◆ markSnapshotFile()

void PLMD::Checkpointing::markSnapshotFile ( const std::string & fileName)

Mark a file as rewritten from scratch at every write (called by OFile::rewind).

◆ registerOutputFile()

void PLMD::Checkpointing::registerOutputFile ( OFile & file)

Record a file opened for writing (called by OFile::open) and, after a restart, restore the header of its last line so that it is not printed again.

◆ restartFrom()

void PLMD::Checkpointing::restartFrom ( const std::string & fileName)

Read a checkpoint, trim the output files and switch restart on (called by the CHECKPOINT action, before any other action opens a file).

◆ restore()

void PLMD::Checkpointing::restore ( )
private

◆ restoreLastFields()

void PLMD::Checkpointing::restoreLastFields ( OFile & file) const

After a restart, restore the field header of the last line of a file appended to (from the checkpoint, or found when trimming it), so that it is not printed again.

◆ setEngineRestartStep()

void PLMD::Checkpointing::setEngineRestartStep ( long long int step)

Step from which the MD engine restarts (cmd "setRestartStep", before init).

◆ setup()

void PLMD::Checkpointing::setup ( const std::string & fileName,
long long int checkpointStride )

Configure checkpoint writing (called by the CHECKPOINT action).

◆ suffixedPath()

std::string PLMD::Checkpointing::suffixedPath ( const std::string & fileName) const

Full path of the checkpoint file for this replica, given its base name.

◆ taggedName()

std::string PLMD::Checkpointing::taggedName ( const std::string & fileName,
const std::string & tag )
static

plumed.cpt -> plumed_prev.cpt for the tag _prev (without the replica suffix)

◆ trimAtRestart()

void PLMD::Checkpointing::trimAtRestart ( const std::string & fileName,
bool keepRestartStep = false )

Remove from a file the lines written at or after the restart step, i.e.

the last lines whose time is not smaller than the time of the restart step (the earlier lines, also those of earlier runs whose time restarted from zero, are kept). Files without a time field, compressed files, and files where the time of these lines is not increasing are left as they are, with a line in the log. Each file is processed only once. To be called by one process only, before the file is read or written by this run (see OFile). keepRestartStep: the lines of the restart step itself are kept (e.g. the hill of that step, when the bias is read from a grid written at the checkpoint).

◆ trimFiles()

void PLMD::Checkpointing::trimFiles ( CheckpointReader & reader)
private

◆ trimOutputFileAtRestart()

void PLMD::Checkpointing::trimOutputFileAtRestart ( Action & action,
const std::string & name,
bool nosuffix = false )

For an action that reads one of its output files at restart before appending to it (e.g.

the hills of METAD): trim the file at the restart step first, if it is trimmed (see trimAtRestart and NO_TRIM). The path is the one the action writes: name with the replica suffix, unless nosuffix. To be called by all the processes of the action.

◆ trimsAtRestart()

bool PLMD::Checkpointing::trimsAtRestart ( ) const
inline

True when the files appended at restart are trimmed at the restart step: the MD engine gave the step, trimming was not switched off, and the run does not restart from a checkpoint (which trims the files to the recorded sizes).

◆ write()

void PLMD::Checkpointing::write ( long long int step,
const std::string & outPath,
const std::string & outPrevPath )
private

Member Data Documentation

◆ engineRestartStep

long long int PLMD::Checkpointing::engineRestartStep =-1
private

Step from which the MD engine restarts (cmd "setRestartStep"), -1 if not given.

◆ engineRestartStepChecked

bool PLMD::Checkpointing::engineRestartStepChecked =false
private

The first step presented after a restart has been compared with engineRestartStep.

◆ file

std::string PLMD::Checkpointing::file
private

Base name given by the user (empty: checkpointing is off)

◆ finalPath

std::string PLMD::Checkpointing::finalPath
private

Path of the checkpoint written at the end of the run (atRunEnd)

◆ lastFields

std::map<std::string,std::string> PLMD::Checkpointing::lastFields
private

Field headers recorded in the checkpoint being restored, or found when trimming a file at the restart step, by path.

◆ lastStep

long long int PLMD::Checkpointing::lastStep =-1
private

Last step presented and difference between the last two steps (to know the next one)

◆ lastWrittenStep

long long int PLMD::Checkpointing::lastWrittenStep =-1
private

◆ outputFiles

std::vector<std::string> PLMD::Checkpointing::outputFiles
private

Paths of all the files opened for writing in this run.

◆ path

std::string PLMD::Checkpointing::path
private

Full path (with the replica suffix) and path of the previous checkpoint.

◆ pending

std::unique_ptr<CheckpointReader> PLMD::Checkpointing::pending
private

Checkpoint being restored, consumed at the first step.

◆ plumed

PlumedMain& PLMD::Checkpointing::plumed
private

◆ prevPath

std::string PLMD::Checkpointing::prevPath
private

◆ restartStep

long long int PLMD::Checkpointing::restartStep =-1
private

Step stored in the checkpoint being restored (-1: no restart)

◆ runEndHandled

bool PLMD::Checkpointing::runEndHandled =false
private

The end of the run has been handled (atRunEnd called)

◆ signalReceived

bool PLMD::Checkpointing::signalReceived =false
private

A checkpointing signal was received from the MD engine in this run.

◆ snapshotFiles

std::set<std::string> PLMD::Checkpointing::snapshotFiles
private

Files rewritten from scratch at every write (OFile::rewind): they are not trimmed at restart, since the next write replaces them anyway.

◆ stepComplete

bool PLMD::Checkpointing::stepComplete =false
private

The last step presented has been completed (update done)

◆ stepIncrement

long long int PLMD::Checkpointing::stepIncrement =1
private

◆ stride

long long int PLMD::Checkpointing::stride =0
private

◆ trimEnabled

bool PLMD::Checkpointing::trimEnabled =true
private

False with RESTART NO_TRIM.

◆ trimmedFiles

std::set<std::string> PLMD::Checkpointing::trimmedFiles
private

Files already trimmed at the restart step (or left as they are)

◆ warnedAboutUnportedState

bool PLMD::Checkpointing::warnedAboutUnportedState =false
private

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