Skip to content

Commit

Permalink
Add a timeout to the minimiser. [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Oct 3, 2024
1 parent ae6b07c commit f05f142
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/somd2/config/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def __init__(
somd1_compatibility=False,
pert_file=None,
save_energy_components=False,
timeout="300s",
):
"""
Constructor.
Expand Down Expand Up @@ -301,6 +302,9 @@ def __init__(
save_energy_components: bool
Whether to save the energy contribution for each force when checkpointing.
This is useful when debugging crashes.
timeout: str
Timeout for the minimiser.
"""

# Setup logger before doing anything else
Expand Down Expand Up @@ -350,6 +354,7 @@ def __init__(
self.somd1_compatibility = somd1_compatibility
self.pert_file = pert_file
self.save_energy_components = save_energy_components
self.timeout = timeout

self.write_config = write_config

Expand Down Expand Up @@ -1267,6 +1272,29 @@ def save_energy_components(self, save_energy_components):
raise ValueError("'save_energy_components' must be of type 'bool'")
self._save_energy_components = save_energy_components

@property
def timeout(self):
return self._timeout

@timeout.setter
def timeout(self, timeout):
if not isinstance(timeout, str):
raise TypeError("'timeout' must be of type 'str'")

from sire.units import second

try:
t = _sr.u(timeout)
except:
raise ValueError(
f"Unable to parse 'timeout' as a Sire GeneralUnit: {timeout}"
)

if t.value() != 0 and not t.has_same_units(second):
raise ValueError("'timeout' units are invalid.")

self._timeout = t

@property
def output_directory(self):
return self._output_directory
Expand Down
4 changes: 2 additions & 2 deletions src/somd2/runner/_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _minimisation(
shift_delta=self._config.shift_delta,
map=self._config._extra_args,
)
m.run()
m.run(timeout=self._config.timeout)
self._system = m.commit()
except:
raise
Expand All @@ -280,7 +280,7 @@ def _minimisation(
shift_delta=self._config.shift_delta,
map=self._config._extra_args,
)
m.run()
m.run(timeout=self._config.timeout)
self._system = m.commit()
except:
raise
Expand Down

0 comments on commit f05f142

Please sign in to comment.