Skip to content

Refactor runner module code - #248

Merged
lohedges merged 14 commits into
develfrom
feature_refactor_runner
Oct 15, 2026
Merged

lohedges merged 14 commits into
develfrom
feature_refactor_runner

Conversation

@lohedges

Copy link
Copy Markdown
Contributor

This PR splits the long functions in the runners into smaller steps, moves the adaptive replica exchange ranking and the dynamics cache into their own modules, and fixes several bugs in the standard runner that the refactor uncovered.

Bug fixes (standard runner)

  • When the runtime wasn't a multiple of the checkpoint_frequency, the final block ran a single integration step rather than the remaining time, since the remaining fraction of a checkpoint interval was passed to Sire as a number of steps. It also ran without GCMC moves or energy components, and appended energies that had already been saved.
  • Each checkpoint now appends exactly the energies sampled since the last one, counted from the energy trajectory. Previously a fixed number of rows was appended, which duplicated energies after a partial block and lost them on restart when checkpoint_frequency is zero.
  • GCMC and terminal flip moves are scheduled from the start of the simulation, so they keep their frequency across checkpoints, and blocks that aren't a whole number of move intervals no longer overrun.
  • Energy components are time stamped from the simulation clock, so they are correct after a restart.
  • The standard runner now requires the runtime, checkpoint_frequency, energy_frequency, frame_frequency, gcmc_frequency and terminal_flip_frequency to be multiples of the timestep, since it runs in whole integration steps.

Other fixes

  • GCMC and terminal flip options are validated before anything is written to the output directory, so an invalid configuration no longer leaves a config file or restores backups first.
  • Windows refilled on a legacy restart take the reference system's time.
  • The REST2 error message for a rest2_scale of the wrong length is no longer truncated.

Refactoring

  • Runner._run (about 1,060 lines) and RepexRunner._run (about 460 lines) are split into a method per step. The standard runner's duplicated sub-block loop, checkpoint write and dynamics call now exist once.
  • RunnerBase.__init__ (about 1,050 lines) is split into logical steps, called in the same order.
  • The adaptive replica exchange ranking moved to _adaptive.py, as a WindowRanker class and plain functions for the statistics.
  • DynamicsCache moved to _dynamics_cache.py, so that it can be reused, and RepexRunner now uses it only through methods and properties. Checkpoints written before the move still load, and the viewer reads both.
  • Unused code was removed: RepexRunner._compute_energies, a duplicate ring-break flag, and several unused variables and imports.

Tests

New tests cover the final block with and without terminal flips and GCMC, move frequencies across checkpoints, energy component time stamps after a restart, the timestep constraint, restoring the adaptive data through the runner, and loading checkpoints pickled before the dynamics cache moved, by both the runner and the viewer. The full suite passes.

This PR was generated with the aid of Claude Code (Opus 5.5).

@lohedges lohedges added the enhancement New feature or request label Oct 15, 2026
@lohedges
lohedges deployed to somd2-build October 15, 2026 13:06 — with GitHub Actions Active
@lohedges
lohedges deployed to somd2-build October 15, 2026 13:06 — with GitHub Actions Active
@lohedges
lohedges deployed to somd2-build October 15, 2026 13:06 — with GitHub Actions Active
@lohedges
lohedges deployed to somd2-build October 15, 2026 13:06 — with GitHub Actions Active
@lohedges
lohedges merged commit e19af2a into devel Oct 15, 2026
4 checks passed
@lohedges
lohedges deleted the feature_refactor_runner branch October 15, 2026 13:18

This branch was successfully deployed

1 active deployment
somd2-build — 310ad2f2 Deployed Oct 15, 2026 by lohedges via build (3.12, linux) #128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant