From c8e9f5206c9392ea477b4350e21f3df42f4d00b3 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 3 Nov 2023 16:42:32 +0000 Subject: [PATCH] Fixed config writing --- src/somd2/runner/_runner.py | 38 ++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/somd2/runner/_runner.py b/src/somd2/runner/_runner.py index 6fc6f27..927e239 100644 --- a/src/somd2/runner/_runner.py +++ b/src/somd2/runner/_runner.py @@ -119,9 +119,16 @@ def __init__(self, system, config): if self._config.h_mass_factor > 1: self._repartition_h_mass() + # Check the output directories and create names of output files. + self._check_directory() + # Save config whenever 'configure' is called to keep it up to date if self._config.write_config: - _dict_to_yaml(self._config.as_dict(), self._config.output_directory) + _dict_to_yaml( + self._config.as_dict(), + self._config.output_directory, + self._fnames[self._lambda_values[0]]["config"], + ) # Flag whether this is a GPU simulation. self._is_gpu = self._config.platform in ["cuda", "opencl", "hip"] @@ -138,8 +145,6 @@ def __init__(self, system, config): enqueue=True, ) - self._check_directory() - def __str__(self): """Return a string representation of the object.""" return f"Runner(system={self._system}, config={self._config})" @@ -203,14 +208,33 @@ def _check_directory(self): if __Path.exists(fullpath): deleted.append(fullpath) if len(deleted) > 0: - _logger.warning( - f"The following files already exist and will be overwritten: {deleted}" - ) - input("Press Enter to erase and continue...") + if not self._config.supress_overwrite_warning: + _logger.warning( + f"The following files already exist and will be overwritten: {deleted}" + ) + input("Press Enter to erase and continue...") for file in deleted: file.unlink() self._fnames = fnames + def _verify_restart_config(self): + """ + Verify that the config file matches the config file used to create the + checkpoint file. + """ + import yaml as _yaml + + with open( + self._config.output_directory + / self._fnames[self._lambda_values[0]]["config"] + ) as file: + config = _yaml.safe_load(file) + if config != self._config.as_dict(): + raise ValueError( + "The configuration file does not match the configuration used to create the " + "checkpoint file." + ) + def get_options(self): """ Returns a dictionary of simulation options.