Skip to content

Commit 1790cc7

Browse files
authored
Merge pull request #119 from OpenBioSim/backport_118
Backport fix from PR #118
2 parents e8faf98 + 9bf71c4 commit 1790cc7

3 files changed

Lines changed: 38 additions & 16 deletions

File tree

src/somd2/runner/_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,9 @@ def _checkpoint(
17611761
)
17621762
system.set_property("lambda", lam)
17631763

1764+
# Delete all frames from the system.
1765+
system.delete_all_frames()
1766+
17641767
# Stream the final system to file.
17651768
_sr.stream.save(system, self._filenames[index]["checkpoint"])
17661769

@@ -1795,6 +1798,9 @@ def _checkpoint(
17951798
)
17961799
system.set_property("lambda", lam)
17971800

1801+
# Delete all frames from the system.
1802+
system.delete_all_frames()
1803+
17981804
# Stream the checkpoint to file.
17991805
_sr.stream.save(system, self._filenames[index]["checkpoint"])
18001806

src/somd2/runner/_repex.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ def _create_dynamics(
247247
else:
248248
mols = system
249249

250+
# Delete an existing trajectory frames.
251+
mols.delete_all_frames()
252+
250253
# Overload the device and lambda value.
251254
dynamics_kwargs["device"] = device
252255
dynamics_kwargs["lambda_value"] = lam
@@ -667,11 +670,17 @@ def __init__(self, system, config):
667670
output_directory=self._config.output_directory,
668671
)
669672
else:
673+
_logger.debug("Restarting from file")
674+
670675
# Check to see if the simulation is already complete.
671676
time = self._system[0].time()
672677
if time > self._config.runtime - self._config.timestep:
673-
_logger.success(f"Simulation already complete. Exiting.")
678+
_logger.success("Simulation already complete. Exiting.")
674679
_sys.exit(0)
680+
else:
681+
_logger.info(
682+
f"Restarting at time {time}, time remaining = {self._config.runtime - time}"
683+
)
675684

676685
try:
677686
with open(self._repex_state, "rb") as f:
@@ -773,28 +782,28 @@ def run(self):
773782
else:
774783
cycles = int(ceil(cycles))
775784

776-
if self._config.checkpoint_frequency.value() > 0.0:
785+
# Store the current checkpoint frequency.
786+
checkpoint_frequency = self._config.checkpoint_frequency
787+
788+
if checkpoint_frequency.value() > 0.0:
777789
# Calculate the number of blocks and the remainder time.
778-
frac = (self._config.runtime / self._config.checkpoint_frequency).value()
790+
frac = (self._config.runtime / checkpoint_frequency).value()
779791

780792
# Handle the case where the runtime is less than the checkpoint frequency.
781793
if frac < 1.0:
782794
frac = 1.0
783-
self._config.checkpoint_frequency = str(self._config.runtime)
795+
checkpoint_frequency = self._config.runtime
784796

785797
num_blocks = int(frac)
786798
rem = round(frac - num_blocks, 12)
787799

788800
# Work out the number of repex cycles per block.
789-
frac = (
790-
self._config.checkpoint_frequency.value()
791-
/ self._config.energy_frequency.value()
792-
)
801+
frac = (checkpoint_frequency / self._config.energy_frequency).value()
793802

794803
# Handle the case where the checkpoint frequency is less than the energy frequency.
795804
if frac < 1.0:
796805
frac = 1.0
797-
self._config.checkpoint_frequency = str(self._config.energy_frequency)
806+
checkpoint_frequency = self._config.energy_frequency
798807

799808
# Store the number of repex cycles per block.
800809
cycles_per_checkpoint = int(frac)
@@ -981,7 +990,7 @@ def run(self):
981990
repeat(num_blocks + int(rem > 0)),
982991
repeat(i == cycles - 1),
983992
):
984-
if not result:
993+
if error:
985994
_logger.error(
986995
f"Checkpoint failed for {_lam_sym} = "
987996
f"{self._lambda_values[index]:.5f}: {error}"

src/somd2/runner/_runner.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ def run_window(self, index):
292292
else:
293293
system = self._system.clone()
294294

295+
# Delete an existing trajectory frames.
296+
system.delete_all_frames()
297+
295298
# GPU platform.
296299
if self._is_gpu:
297300
# Get a GPU from the pool.
@@ -644,22 +647,26 @@ def generate_lam_vals(lambda_base, increment=0.001):
644647
else:
645648
num_energy_neighbours = None
646649

650+
# Store the current checkpoint frequency.
651+
checkpoint_frequency = self._config.checkpoint_frequency
652+
647653
# Store the checkpoint time in nanoseconds.
648-
checkpoint_interval = self._config.checkpoint_frequency.to("ns")
654+
checkpoint_interval = checkpoint_frequency.to("ns")
649655

650656
# Store the start time.
651657
start = _timer()
652658

653659
# Run the simulation, checkpointing in blocks.
654-
if self._config.checkpoint_frequency.value() > 0.0:
660+
if checkpoint_frequency.value() > 0.0:
655661

656662
# Calculate the number of blocks and the remainder time.
657-
frac = (time / self._config.checkpoint_frequency).value()
663+
frac = (time / checkpoint_frequency).value()
658664

659665
# Handle the case where the runtime is less than the checkpoint frequency.
660666
if frac < 1.0:
661667
frac = 1.0
662-
self._config.checkpoint_frequency = f"{time} ps"
668+
checkpoint_frequency = _sr.u(f"{time} ps")
669+
checkpoint_interval = checkpoint_frequency.to("ns")
663670

664671
num_blocks = int(frac)
665672
rem = round(frac - num_blocks, 12)
@@ -684,7 +691,7 @@ def generate_lam_vals(lambda_base, increment=0.001):
684691
next_frame = self._config.frame_frequency
685692

686693
# Loop until we reach the runtime.
687-
while runtime <= self._config.checkpoint_frequency:
694+
while runtime <= checkpoint_frequency:
688695
# Run the dynamics in blocks of the GCMC frequency.
689696
dynamics.run(
690697
self._config.gcmc_frequency,
@@ -725,7 +732,7 @@ def generate_lam_vals(lambda_base, increment=0.001):
725732

726733
else:
727734
dynamics.run(
728-
self._config.checkpoint_frequency,
735+
checkpoint_frequency,
729736
energy_frequency=self._config.energy_frequency,
730737
frame_frequency=self._config.frame_frequency,
731738
lambda_windows=lambda_array,

0 commit comments

Comments
 (0)