Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Changelog
* Add a `chain_equilibration` option for replica exchange, which speeds up setup by starting each replica from a neighbour that has already been set up. Replicas in the first parallel batch, which is spread across lambda, are minimised and equilibrated from the input system. The rest skip minimisation and are equilibrated for `chain_equilibration_scale` times the `equilibration_time`, which defaults to a quarter [#273](https://github.com/OpenBioSim/somd2/pull/273).
* Pass `beutler_alpha` to the GCMC sampler, which otherwise used its own default for the Beutler soft-core form [#275](https://github.com/OpenBioSim/somd2/pull/275).
* Run GCMC simulations in the NVT ensemble, ignoring the pressure, since the osmotic ensemble isn't valid for GCMC of solvent water: the number of waters is barely fixed, so it drifts. GCMC runs started with a pressure can't be restarted [#281](https://github.com/OpenBioSim/somd2/pull/281).
* Added support for Python 3.13 and 3.14, and dropped support for Python 3.10 and 3.11.
* Added support for Python 3.13 and 3.14, and dropped support for Python 3.10 and 3.11 [#283](https://github.com/OpenBioSim/somd2/pull/283).
* Fixed the regular runner reporting success when a lambda window failed, unless it was the last to finish. The other windows still run, then `Runner.run()` raises an error listing the failed windows and `somd2` exits with a non-zero status. The overall performance is now summed over all windows rather than taken from the last to finish [#285](https://github.com/OpenBioSim/somd2/pull/285).

[2026.2.0](https://github.com/openbiosim/somd2/compare/2026.1.0...2026.2.0) - Sep 2026
--------------------------------------------------------------------------------------
Expand Down
51 changes: 33 additions & 18 deletions src/somd2/runner/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,16 @@ def run(self):

# All other platforms.
else:
self._max_workers = 1
self.max_workers = 1

self._add_boresch_restraint(device=self._gpu_pool[0] if self._is_gpu else None)

import concurrent.futures as _futures
import multiprocessing as _mp

success = True
failed = []
interrupted = False
total_time = 0
with _futures.ProcessPoolExecutor(
max_workers=self.max_workers, mp_context=_mp.get_context("spawn")
) as executor:
Expand All @@ -290,34 +292,47 @@ def run(self):
f"Exception raised for {_lam_sym} = {lambda_value}: {e}"
)
success = False
if success:
total_time += time.to("ns")
else:
failed.append(lambda_value)

# Kill all current and future jobs if keyboard interrupt.
except KeyboardInterrupt:
_logger.error("Cancelling job...")
for pid in executor._processes:
executor._processes[pid].terminate()
success = False
interrupted = True

if success:
# Record the end time.
end = _timer()
if interrupted:
raise RuntimeError("Simulation was cancelled.")

# Work how many fractional days the simulation took.
days = (end - start) / 86400
if failed:
failed = ", ".join(str(lam) for lam in sorted(failed))
raise RuntimeError(
f"Failed for {_lam_sym} = {failed}. These windows can be re-run "
"using '--lambda-values' with '--restart'."
)

# Calculate the speed in nanoseconds per day.
speed = time.to("ns") / days
# Record the end time.
end = _timer()

# Log the speed.
_logger.info(f"Overall performance: {speed:.2f} ns day-1")
# Work how many fractional days the simulation took.
days = (end - start) / 86400

# Log the run time in minutes.
_logger.success(
f"Simulation finished. Run time: {(end - start) / 60:.2f} minutes"
)
# Calculate the speed in nanoseconds per day, summed over all windows.
speed = total_time / days

# Log the speed.
_logger.info(f"Overall performance: {speed:.2f} ns day-1")

# Log the run time in minutes.
_logger.success(
f"Simulation finished. Run time: {(end - start) / 60:.2f} minutes"
)

# Cleanup backup files.
self._cleanup()
# Cleanup backup files.
self._cleanup()

def _check_restart(self):
"""
Expand Down
46 changes: 46 additions & 0 deletions tests/runner/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,52 @@ def test_runtime_remainder(ethane_methanol):
assert checkpoint_state["time_ps"].item() == pytest.approx(0.020)


def test_failed_window(ethane_methanol, monkeypatch):
"""
Validate that a failed window doesn't stop the others from running, and
that the run raises an error naming the failed window.
"""
import concurrent.futures

# Run windows in threads so that the patched _run is used.
monkeypatch.setattr(
concurrent.futures,
"ProcessPoolExecutor",
lambda max_workers, mp_context: concurrent.futures.ThreadPoolExecutor(
max_workers=max_workers
),
)

run = Runner._run

def failing_run(self, system, index, **kwargs):
if index == 0:
raise RuntimeError("Forced failure")
return run(self, system, index, **kwargs)

monkeypatch.setattr(Runner, "_run", failing_run)

with tempfile.TemporaryDirectory() as tmpdir:
config = {
"runtime": "4fs",
"restart": False,
"output_directory": tmpdir,
"energy_frequency": "4fs",
"checkpoint_frequency": "4fs",
"frame_frequency": "4fs",
"platform": "CPU",
"max_threads": 1,
"num_lambda": 2,
}

runner = Runner(ethane_methanol, Config(**config))
with pytest.raises(RuntimeError, match="Failed for λ = 0.0"):
runner.run()

assert not (Path(tmpdir) / "energy_traj_0.00000.parquet").exists()
assert (Path(tmpdir) / "energy_traj_1.00000.parquet").exists()


def test_equilibration_time_per_window(ethane_methanol):
"""Validate that only windows with a non-zero time are equilibrated."""
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down
Loading