Fix modular simulator log writing in fresh simulation starts with nstlog == 0
authorPascal Merz <pascal.merz@me.com>
Tue, 19 Jan 2021 09:39:34 +0000 (09:39 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Tue, 19 Jan 2021 09:39:34 +0000 (09:39 +0000)
With nstlog = 0, legacy simulator writes log on the initial step, while
modular simulator wasn't. This adapts modular simulator to the legacy
approach.

src/gromacs/modularsimulator/signallers.cpp
src/gromacs/modularsimulator/signallers.h
src/gromacs/modularsimulator/simulatoralgorithm.cpp

index b8804d469b13d49a660cf184bc29ea19b45ddbfd..45edd4352efb54e96344a9d931a5946a57db9398 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -46,6 +46,7 @@
 
 #include "gromacs/mdlib/stat.h"
 #include "gromacs/mdlib/stophandler.h"
+#include "gromacs/mdrunutility/handlerestart.h"
 
 #include "modularsimulatorinterfaces.h"
 
@@ -122,11 +123,11 @@ std::optional<SignallerCallback> LastStepSignaller::registerNSCallback()
 LoggingSignaller::LoggingSignaller(std::vector<SignallerCallback> callbacks,
                                    Step                           nstlog,
                                    Step                           initStep,
-                                   Time                           initTime) :
+                                   StartingBehavior               startingBehavior) :
     callbacks_(std::move(callbacks)),
     nstlog_(nstlog),
     initStep_(initStep),
-    initTime_(initTime),
+    startingBehavior_(startingBehavior),
     lastStep_(-1),
     lastStepRegistrationDone_(false)
 {
@@ -134,7 +135,8 @@ LoggingSignaller::LoggingSignaller(std::vector<SignallerCallback> callbacks,
 
 void LoggingSignaller::signal(Step step, Time time)
 {
-    if (do_per_step(step, nstlog_) || step == lastStep_)
+    if (do_per_step(step, nstlog_) || step == lastStep_
+        || (step == initStep_ && startingBehavior_ == StartingBehavior::NewSimulation))
     {
         runAllCallbacks(callbacks_, step, time);
     }
index 2c74ab9454d1b92a3f8bf69fef552a2b70acd5a4..2fa20c51293e5f92d087735018674690141f4f2b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -54,6 +54,7 @@ namespace gmx
 {
 class StopHandler;
 class TrajectoryElement;
+enum class StartingBehavior;
 
 /*! \internal
  * \ingroup module_modularsimulator
@@ -228,12 +229,15 @@ public:
 private:
     /*! \brief Constructor
      *
-     * \param callbacks  A vector of pointers to callbacks
-     * \param nstlog     The logging frequency
-     * \param initStep   The first step of the simulation
-     * \param initTime   The start time of the simulation
+     * \param callbacks         A vector of pointers to callbacks
+     * \param nstlog            The logging frequency
+     * \param initStep          The first step of the simulation
+     * \param startingBehavior  Whether this is a new simulation or restarting from checkpoint
      */
-    LoggingSignaller(std::vector<SignallerCallback> callbacks, Step nstlog, Step initStep, Time initTime);
+    LoggingSignaller(std::vector<SignallerCallback> callbacks,
+                     Step                           nstlog,
+                     Step                           initStep,
+                     StartingBehavior               startingBehavior);
 
     //! Client callbacks
     std::vector<SignallerCallback> callbacks_;
@@ -242,8 +246,8 @@ private:
     const Step nstlog_;
     //! The initial step of the simulation
     const Step initStep_;
-    //! The initial time of the simulation
-    const Time initTime_;
+    //! How we are starting the simulation
+    const StartingBehavior startingBehavior_;
 
     //! ILastStepSignallerClient implementation
     std::optional<SignallerCallback> registerLastStepCallback() override;
index 4e0b71a9187b1ae4c33cdf5feae7d8b6867615f8..9b90fd16c916c228bf47df2c8d41110e505c2f9b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -578,7 +578,8 @@ ModularSimulatorAlgorithm ModularSimulatorAlgorithmBuilder::build()
                 inputrec->nstxout_compressed, trajectoryElement->tngBoxOut(),
                 trajectoryElement->tngLambdaOut(), trajectoryElement->tngBoxOutCompressed(),
                 trajectoryElement->tngLambdaOutCompressed(), inputrec->nstenergy));
-        addSignaller(loggingSignallerBuilder_.build(inputrec->nstlog, inputrec->init_step, inputrec->init_t));
+        addSignaller(loggingSignallerBuilder_.build(inputrec->nstlog, inputrec->init_step,
+                                                    legacySimulatorData_->startingBehavior));
         addSignaller(lastStepSignallerBuilder_.build(inputrec->nsteps, inputrec->init_step,
                                                      algorithm.stopHandler_.get()));
         addSignaller(neighborSearchSignallerBuilder_.build(inputrec->nstlist, inputrec->init_step,