2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2021, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * \brief Defines functions of the AWH history used by modular checkpointing
39 * \author Pascal Merz <pascal.merz@me.com>
44 #include "awh_history.h"
46 #include "gromacs/utility/strconvert.h"
48 #include "checkpointdata.h"
56 * \brief Enum describing the contents all AWH history classes implemented in this file
57 * write to modular checkpoint
59 * When changing the checkpoint content, add a new element just above Count, and adjust the
60 * checkpoint functionality.
62 enum class CheckpointVersion
64 Base, //!< First version of modular checkpointing
65 Count //!< Number of entries. Add new versions right above this!
67 constexpr auto c_currentVersion = CheckpointVersion(int(CheckpointVersion::Count) - 1);
69 template<CheckpointDataOperation operation>
70 static void doCheckpoint(CheckpointData<operation> checkpointData, AwhPointStateHistory* awhPointStateHistory)
72 checkpointData.scalar("bias", &awhPointStateHistory->bias);
73 checkpointData.scalar("free_energy", &awhPointStateHistory->free_energy);
74 checkpointData.scalar("target", &awhPointStateHistory->target);
75 checkpointData.scalar("weightsum_iteration", &awhPointStateHistory->weightsum_iteration);
76 checkpointData.scalar("weightsum_covering", &awhPointStateHistory->weightsum_covering);
77 checkpointData.scalar("weightsum_tot", &awhPointStateHistory->weightsum_tot);
78 checkpointData.scalar("weightsum_ref", &awhPointStateHistory->weightsum_ref);
79 checkpointData.scalar("last_update_index", &awhPointStateHistory->last_update_index);
80 checkpointData.scalar("log_pmfsum", &awhPointStateHistory->log_pmfsum);
81 checkpointData.scalar("visits_iteration", &awhPointStateHistory->visits_iteration);
82 checkpointData.scalar("visits_tot", &awhPointStateHistory->visits_tot);
85 template<CheckpointDataOperation operation>
86 static void doCheckpoint(CheckpointData<operation> checkpointData, AwhBiasStateHistory* awhBiasStateHistory)
88 checkpointData.scalar("umbrellaGridpoint", &awhBiasStateHistory->umbrellaGridpoint);
89 checkpointData.scalar("origin_index_updatelist", &awhBiasStateHistory->origin_index_updatelist);
90 checkpointData.scalar("end_index_updatelist", &awhBiasStateHistory->end_index_updatelist);
91 checkpointData.scalar("in_initial", &awhBiasStateHistory->in_initial);
92 checkpointData.scalar("equilibrateHistogram", &awhBiasStateHistory->equilibrateHistogram);
93 checkpointData.scalar("histSize", &awhBiasStateHistory->histSize);
94 checkpointData.scalar("logScaledSampleWeight", &awhBiasStateHistory->logScaledSampleWeight);
95 checkpointData.scalar("maxLogScaledSampleWeight", &awhBiasStateHistory->maxLogScaledSampleWeight);
96 checkpointData.scalar("numUpdates", &awhBiasStateHistory->numUpdates);
99 template<CheckpointDataOperation operation>
100 void doCheckpoint(CheckpointData<operation> checkpointData,
101 CorrelationBlockDataHistory* correlationBlockDataHistory)
103 checkpointData.scalar("blockSumWeight", &correlationBlockDataHistory->blockSumWeight);
104 checkpointData.scalar("blockSumSquareWeight", &correlationBlockDataHistory->blockSumSquareWeight);
105 checkpointData.scalar("blockSumWeightX", &correlationBlockDataHistory->blockSumWeightX);
106 checkpointData.scalar("blockSumWeightY", &correlationBlockDataHistory->blockSumWeightY);
107 checkpointData.scalar("sumOverBlocksSquareBlockWeight",
108 &correlationBlockDataHistory->sumOverBlocksSquareBlockWeight);
109 checkpointData.scalar("sumOverBlocksBlockSquareWeight",
110 &correlationBlockDataHistory->sumOverBlocksBlockSquareWeight);
111 checkpointData.scalar("sumOverBlocksBlockWeightBlockWeightX",
112 &correlationBlockDataHistory->sumOverBlocksBlockWeightBlockWeightX);
113 checkpointData.scalar("sumOverBlocksBlockWeightBlockWeightY",
114 &correlationBlockDataHistory->sumOverBlocksBlockWeightBlockWeightY);
115 checkpointData.scalar("blockLength", &correlationBlockDataHistory->blockLength);
116 checkpointData.scalar("previousBlockIndex", &correlationBlockDataHistory->previousBlockIndex);
117 checkpointData.scalar("correlationIntegral", &correlationBlockDataHistory->correlationIntegral);
120 template<CheckpointDataOperation operation>
121 static void doCheckpoint(CheckpointData<operation> checkpointData, CorrelationGridHistory* correlationGridHistory)
123 checkpointData.scalar("numCorrelationTensors", &correlationGridHistory->numCorrelationTensors);
124 checkpointData.scalar("tensorSize", &correlationGridHistory->tensorSize);
125 checkpointData.scalar("blockDataListSize", &correlationGridHistory->blockDataListSize);
127 int blockDataBufferSize = correlationGridHistory->blockDataBuffer.size();
128 checkpointData.scalar("blockDataBufferSize", &blockDataBufferSize);
129 if (operation == CheckpointDataOperation::Read)
131 correlationGridHistory->blockDataBuffer.resize(blockDataBufferSize);
134 for (auto& buffer : correlationGridHistory->blockDataBuffer)
136 doCheckpoint(checkpointData.subCheckpointData("blockDataBuffer " + toString(counter)), &buffer);
141 template<CheckpointDataOperation operation>
142 void doCheckpointData(CheckpointData<operation> checkpointData, AwhBiasHistory* awhBiasHistory)
144 int pointStateSize = awhBiasHistory->pointState.size();
145 checkpointData.scalar("pointStateSize", &pointStateSize);
146 if (operation == CheckpointDataOperation::Read)
148 awhBiasHistory->pointState.resize(pointStateSize);
152 for (auto& point : awhBiasHistory->pointState)
154 doCheckpoint(checkpointData.subCheckpointData("pointState " + toString(counter)), &point);
157 doCheckpoint(checkpointData.subCheckpointData("state"), &awhBiasHistory->state);
158 doCheckpoint(checkpointData.subCheckpointData("forceCorrelationGrid"),
159 &awhBiasHistory->forceCorrelationGrid);
163 // This trips doxygen up
165 template<CheckpointDataOperation operation>
166 void AwhHistory::doCheckpoint(CheckpointData<operation> checkpointData)
168 // Keep one version for all objects in this file
169 checkpointVersion(&checkpointData, "AwhHistory version", c_currentVersion);
171 checkpointData.scalar("potentialOffset", &potentialOffset);
173 int biasSize = bias.size();
174 checkpointData.scalar("biasSize", &biasSize);
175 if (operation == CheckpointDataOperation::Read)
177 bias.resize(biasSize);
182 doCheckpointData(checkpointData.subCheckpointData("bias " + toString(counter)), &b);
187 // explicit template instantiation
188 template void AwhHistory::doCheckpoint(CheckpointData<CheckpointDataOperation::Read>);
189 template void AwhHistory::doCheckpoint(CheckpointData<CheckpointDataOperation::Write>);