Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unformatted (binary) checkpointing #558

Merged
merged 63 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
236550d
Simplify formatted state writing
giacomofiorin Aug 22, 2023
32f0dba
Remove trivial derivations of base-class functions
giacomofiorin Jul 20, 2023
6f8ea4f
Initial implementation of memory_stream class
giacomofiorin Jun 23, 2023
791b6eb
Add missing const accessors
giacomofiorin Jun 23, 2023
6a687bf
Abstract the stream operators for colvarvalue
giacomofiorin Jun 23, 2023
166df95
Formatting tweaks
giacomofiorin Jun 23, 2023
8435763
Add unit test for memory stream
giacomofiorin Jun 24, 2023
062d9d3
Work around incomplete C++11 compliance for old GCC
giacomofiorin Jun 25, 2023
f1109c6
Refine compiler selection to address overlap between Clang and GCC ma…
giacomofiorin Jul 21, 2023
132dc37
MSVC fixes
giacomofiorin Jun 25, 2023
b71a6b0
Add template specializations to ignore formatting operators
giacomofiorin Jul 19, 2023
76cd13c
Do not specify the starting point if not needed
giacomofiorin Jul 19, 2023
12ba148
Move specializations to source file
giacomofiorin Jul 19, 2023
f621ab1
Make memory_stream compatible with STL streams in templates
giacomofiorin Jul 19, 2023
36d1ba5
Unformatted I/O for colvar objects
giacomofiorin Jul 19, 2023
50bcdaa
Implement read_block() for unformatted input streams
giacomofiorin Jul 19, 2023
f5e9b5c
Separate checking the name of the colvar from reading its state data
giacomofiorin Jul 20, 2023
9665ed6
Unformatted I/O for grid objects
giacomofiorin Jul 20, 2023
5827f34
Remove duplicate specialization specific to Visual Studio and Sun com…
giacomofiorin Jul 21, 2023
046f081
Unformatted I/O for colvarbias base class
giacomofiorin Aug 21, 2023
8a974e8
Unformatted I/O for colvarbias_abf and colvarbias_histogram
giacomofiorin Aug 21, 2023
2a7f42f
More formatting functions being ignored
giacomofiorin Aug 21, 2023
54f2956
Unformatted I/O for colvarbias_ti
giacomofiorin Aug 21, 2023
2c78dbb
Remove obsolete code block
giacomofiorin Aug 21, 2023
f168c1a
Forward declare STL streams in colvargrid template
giacomofiorin Aug 21, 2023
04ffe29
Small fixes
giacomofiorin Aug 22, 2023
d8cbd75
Remove declarations of functions that were never defined
giacomofiorin Aug 23, 2023
81fb6b1
Simplify and improve error handling
giacomofiorin Aug 23, 2023
bf432f8
More forward declarations of STL streams
giacomofiorin Aug 23, 2023
c024e3a
Unformatted I/O for reweightAMD
giacomofiorin Aug 23, 2023
7c2ab17
Condense and simplify metadynamics state reading
giacomofiorin Aug 23, 2023
c30ebcf
Refactor formatted I/O for metadynamics before adding unformatted ver…
giacomofiorin Aug 24, 2023
03b5f54
Unformatted state I/O for metadynamics
giacomofiorin Aug 25, 2023
0623ed9
Ensure that a string object is written
giacomofiorin Aug 31, 2023
d8ccd02
Unformatted I/O for colvarmodule
giacomofiorin Aug 25, 2023
e2a1e94
Always allow seeking in a memory buffer
giacomofiorin Aug 31, 2023
839653c
Stop using preprocessor macros for return codes
giacomofiorin Aug 25, 2023
66461d2
Open text files in binary mode (we are not using EOL conversion anyway)
giacomofiorin Aug 26, 2023
4b49671
Remove check no longer needed after #537
giacomofiorin Sep 1, 2023
e00358f
Enable binary restarts from environment variable
giacomofiorin Sep 1, 2023
7540c29
Fix forgotten renaming of functions
giacomofiorin Sep 1, 2023
b02fae0
Remove non-essential debug call to avoid segfault
giacomofiorin Sep 1, 2023
8f47227
Embed unformatted state in LAMMPS restart file
giacomofiorin Sep 8, 2023
c7b8841
Remove now unneeded LAMMPS proxy wrappers
giacomofiorin Sep 8, 2023
ef623ad
Auto-detect unformatted vs. formatted input
giacomofiorin Sep 9, 2023
a136ade
Cosmetic changes
giacomofiorin Sep 9, 2023
c756a59
Add warning about mismatched binary state versions
giacomofiorin Sep 9, 2023
1f05c89
Ignore unformatted input state buffer (e.g. LAMMPS restart) if explic…
giacomofiorin Sep 9, 2023
8bda90f
Only write output state if the prefix is not null
giacomofiorin Sep 9, 2023
aebc3d2
Clarify that an empty output prefix is allowed in LAMMPS
giacomofiorin Sep 9, 2023
09ae9d9
Document binary vs. formatted state file format
giacomofiorin Sep 9, 2023
8f6e03c
Remove last instance of #include <iostream> in widely included header
giacomofiorin Sep 9, 2023
8445e01
Move include to where it is required
giacomofiorin Sep 9, 2023
45f38c2
More consistent naming of stream I/O template functions
giacomofiorin Sep 9, 2023
e06fd28
Silence redundant Clang analyzer warning
giacomofiorin Sep 15, 2023
5d06e56
Support external output buffer in memory_stream
giacomofiorin Sep 15, 2023
73b7e4b
Silence compiler warning
giacomofiorin Sep 15, 2023
3e18a93
Add wrapper code to serialize/deserialize to std::vector<unsigned char>
giacomofiorin Sep 15, 2023
233c0ee
Simplify test
jhenin Sep 21, 2023
c3058c9
Expand doc on binary restart
jhenin Sep 21, 2023
6bb2333
Further improve doc
giacomofiorin Sep 25, 2023
fe116a5
Fix incomplete sections
giacomofiorin Sep 25, 2023
c05cbd4
Mini-edit in doc
jhenin Sep 25, 2023
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
51 changes: 39 additions & 12 deletions doc/colvars-refman-main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -958,13 +958,22 @@

\cvsubsec{Input state file}{sec:colvars_input}

Several of the sampling methods implemented in Colvars are time- or history-dependent, i.e.\ they work by accumulating data as a simulation progresses and use this data to change their biasing forces. When continuing a simulation over consecutive runs, a \emph{state file} needs to be loaded into Colvars.
Several of the sampling methods implemented in Colvars are time- or history-dependent, i.e.\ they work by accumulating data as a simulation progresses and use these data to determine their biasing forces.

This requires that the Colvars information

a standard method for checkpointing (currently, these are only GROMACS and LAMMPS)
giacomofiorin marked this conversation as resolved.
Show resolved Hide resolved

When continuing a simulation over consecutive runs, a \emph{state file} needs to be loaded into Colvars.

The Colvars state file may be in either one of two formats:
\begin{itemize}
\item Unformatted (binary) format, which is both space-efficient and quick to load/save, but requires that the same \MDENGINE{} build was used to save the file in the first place. Most importantly, no changes are allowed in the Colvars configuration between the original run. Binary state files are supported by Colvars versions starting late 2023. % TODO Add specific version?
Binary checkpointing is enabled by setting the environment variable COLVARS_BINARY_RESTART to 1.
\item Formatted (text) format, which takes more space and is slower to to load/save but is also portable across different platforms and even different engines (except for changes in physical units).
\item Unformatted, i.e.\ \emph{``binary''} format, which is both space-efficient and quick to load/save, but requires that the same \MDENGINE{} build was used to save the file in the first place, and the the Colvars configuration was the same. This format is supported by Colvars versions starting late 2023. % TODO Add specific version?
Binary checkpointing can b

enabled by setting the environment variable ``COLVARS_BINARY_RESTART'' to 1.
\item Formatted, i.e.\ \emph{``text''} format, which takes more space and is slower to to load/save but is also portable across different platforms and even different simulation engines (save for changes in physical units).
This format is supported by all versions of Colvars.
\end{itemize}

\cvsubsubsec{Contents of the state file.}{}
Expand All @@ -976,21 +985,39 @@
% \cvgromacsonly{\cvsubsubsec{Restarting in GROMACS.}{} TODO }

\cvlammpsonly{\cvsubsubsec{Restarting in LAMMPS.}{}
For continuing a Colvars-based simulation, the recommended method is using the standard LAMMPS \texttt{read\_restart} command, which effectively reads the Colvars state in unformatted (binary) format embedded in the LAMMPS restart file. Alternatively, restarting from a formatted Colvars-only state file is also possible by using the \texttt{input} keyword of the \texttt{fix colvars} command, which overrides the information read from the LAMMPS restart file.
Furthermore, a state file may also be loaded after initialization with the \texttt{fix\_modify <fix-ID> load <filename>} LAMMPS command.
}
For continuing a Colvars-based simulation, the recommended method is using the standard LAMMPS \texttt{read\_restart} command, which reads the Colvars state data from the LAMMPS restart file (in binary format).
\begin{mdexampleinput}{}
\-read\_restart~\emph{filename}
\end{mdexampleinput}
Alternatively, restarting from a Colvars-specific state file is also possible by providing the \texttt{input} keyword to the \texttt{fix colvars} command:
\begin{mdexampleinput}{}
\-fix~Colvars~all~colvars~\emph{configfile}~input~\emph{input\_prefix}
\end{mdexampleinput}
When the ``\texttt{input}'' keyword is used, the contents of the file \texttt{$<$\emph{input\_prefix}$>$.colvar.state} override the information read from the LAMMPS restart file. Finally, a state file may also be loaded after initialization through the ``\texttt{fix\_modify}'' command:
\begin{mdexampleinput}{%
}fix\_modify~Colvars~\texttt{input}~\emph{new\_input\_prefix}
\end{mdexampleinput}
} % end \cvlammpsonly


\cvnamdonly{\cvsubsubsec{Restarting in NAMD.}{}
Before the Colvars module is initialized in NAMD, the \texttt{colvarsInput} keyword can be used to give the name of a state file.
After initialization of the Colvars module, a state file may be loaded at any time with the Tcl command \texttt{cv load}.}
After initialization of the Colvars module, a state file may be loaded at any time with the Tcl command \texttt{cv load}.
Both versions support loading Colvars state files in either format (binary or text).
} % end \cvnamdonly


\cvsubsubsec{Restarting after a change in Colvars configuration.}{}
A unique advantage of the formatted Colvars state files is that they can be loaded even if the configuration has changed.
For example, new restraints may have been added or removed from the Colvars configuration between consecutive runs.
It useful in some cases to modify the configuration of variables or biases between consecutive runs: a typical example would the addition or removal of a restraint in a simulation.
By restarting using formatted (i.e.\ text) Colvars state files, it is possible to read previous data while allowing for changes in configuration.
For each newly defined variable or bias, no information will be read from the state file if this is unavailable: such new objects will remain uninitialized until the first compute step.
Conversely, any information that the state file has about variables or biases that are no longer defined is silently ignored.
\emph{Because these checks are performed based solely on the names of variables and biases, it is your responsibility to ensure that these names correspond to consistent definitions between runs.}

When restarting using unformatted (i.e.\ binary) state files, configuration changes are not allowed. The easiest solution would be to produce a formatted (i.e.\ text) state file specifically for that purpose.
\ifdefined\cvscriptapi{%
Alternatively, after restarting Colvars using a state file consistent with the previous configuration, the configuration may be changed using the scripting interface (see \ref{sec:cv_scripting}).
}\fi


\cvsubsec{Output files}{sec:colvars_output}
Expand All @@ -1000,8 +1027,8 @@
\begin{itemize}

\item A \emph{state file}, named \outputName\texttt{.colvars.state}, which is written at the end of the specified run\cvscriptonly{, and can also be written at any time with the scripting command \texttt{save} (\ref{sec:cv_command_loadsave})}.
This file is in plain text format by default\cvnamdonly{, regardless of the value of \texttt{binaryOutput} of the NAMD coordinate and velocity files}, or in binary format if the environment variable \texttt{COLVARS\_BINARY\_RESTART} is set to a non-zero integer.
\emph{The state is the only Colvars output file needed to continue a simulation.}
This file is in plain text format by default\cvnamdonly{, regardless of the value of \texttt{binaryOutput} of the NAMD coordinate and velocity files}, or in unformatted (i.e.\ binary) format if the environment variable \texttt{COLVARS\_BINARY\_RESTART} is set to a non-zero integer.
The state file is used to continue a simulation, and is required to restart a simulation unless the engine supports embedding information into their checkpoint file (as GROMACS or LAMMPS currently do).

\item If the parameter \refkey{colvarsRestartFrequency}{Colvars-global|colvarsRestartFrequency} is larger than zero, a \emph{restart file} is written every that many steps: this file is fully equivalent to the final state file.
The name of this file is \restartName\texttt{.colvars.state}.
Expand Down