Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ class PlumedMDModule final : public IMDModule
notifier->simulationSetupNotifier_.subscribe(
[this](const StartingBehavior& startingBehavior)
{ this->options_.setStartingBehavior(startingBehavior); });
// Set checkpoint status before PLUMED updates the current step.
notifier->checkpointingNotifier_.subscribe(
[this](const MDModulesCheckpointingSignal& checkpointingSignal)
{
if (options_.active())
{
plumedForceProvider_->setCheckpointingThisStep(
checkpointingSignal.isCheckpointingStep_);
}
});
// writing checkpoint data
notifier->checkpointingNotifier_.subscribe(
[this](MDModulesWriteCheckpointData /*checkpointData*/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,33 @@ catch (const std::exception& ex)
std::string("An error occurred while initializing the PLUMED force provider:\n") + ex.what()));
}

void PlumedForceProvider::setPlumedCheckpointing(bool isCheckpointingStep)
{
if (plumedAPIversion_ > 3)
{
int checkpointing = isCheckpointingStep ? 1 : 0;
plumed_->cmd("doCheckPoint", &checkpointing);
}
}

void PlumedForceProvider::setCheckpointingThisStep(bool isCheckpointingStep)
try
{
hasCheckpointingStepNotifications_ = true;
setPlumedCheckpointing(isCheckpointingStep);
}
catch (const std::exception& ex)
{
GMX_THROW(InternalError(
std::string("An error occurred while PLUMED was setting checkpoint status:\n") + ex.what()));
}

void PlumedForceProvider::writeCheckpointData()
try
{
if (plumedAPIversion_ > 3)
if (!hasCheckpointingStepNotifications_)
{
int checkp = 1;
plumed_->cmd("doCheckPoint", &checkp);
setPlumedCheckpointing(true);
}
}
catch (const std::exception& ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ class PlumedForceProvider final : public IForceProvider
*/
PlumedForceProvider(const PlumedOptions& options);
~PlumedForceProvider();
/*! \brief Set whether PLUMED is updating a checkpointing step.
*
* Receiving this notification also disables the later checkpoint-writing
* fallback used by the modular simulator.
*
* \param[in] isCheckpointingStep Whether GROMACS will write a checkpoint
* for the current step.
*/
void setCheckpointingThisStep(bool isCheckpointingStep);
/*! \brief Tells PLUMED to output the checkpoint data
*
* If the PLUMED API version is not greater than 3 it will do nothing.
* This is a fallback for simulation paths that do not provide an early
* checkpoint-step notification. If the PLUMED API version is not greater
* than 3 it will do nothing.
*/
void writeCheckpointData();
/*! \brief Calculate the forces with PLUMED
Expand All @@ -77,9 +88,16 @@ class PlumedForceProvider final : public IForceProvider
ForceProviderOutput* forceProviderOutput) override;

private:
/*! \brief Pass checkpoint status to PLUMED.
*
* \param[in] isCheckpointingStep Whether the current step writes a checkpoint.
*/
void setPlumedCheckpointing(bool isCheckpointingStep);

std::unique_ptr<PLMD::Plumed> plumed_;
int plumedAPIversion_;
bool replex_;
bool hasCheckpointingStepNotifications_ = false;
};

} // namespace gmx
Expand Down
Loading