Skip to content

Commit

Permalink
Fixed config writing
Browse files Browse the repository at this point in the history
  • Loading branch information
mb2055 committed Nov 3, 2023
1 parent 16f7d86 commit c8e9f52
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/somd2/runner/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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})"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c8e9f52

Please sign in to comment.