Skip to content

Commit

Permalink
Fix/issue 708 (#710)
Browse files Browse the repository at this point in the history
* add test that will fail until we have a fix

* check to see if real time analysis is none before check if it has been set

* see if this fixes issues on osx

* lets see if upstream has fixed the issue

* I will just fix this in another PR
  • Loading branch information
mikemhenry authored Jun 30, 2023
1 parent fcf9a20 commit 90d655b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
8 changes: 5 additions & 3 deletions openmmtools/multistate/multistatesampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,11 @@ def create(self, thermodynamic_states: list, sampler_states, storage,

# Make sure online analysis interval is a multiples of the reporter's checkpoint interval
# this avoids having redundant iteration information in the real time yaml files
if self.online_analysis_interval % self._reporter.checkpoint_interval != 0:
raise ValueError(f"Online analysis interval: {self.online_analysis_interval}, must be a "
f"multiple of the checkpoint interval: {self._reporter.checkpoint_interval}")
# only check if self.online_analysis_interval is set
if self.online_analysis_interval:
if self.online_analysis_interval % self._reporter.checkpoint_interval != 0:
raise ValueError(f"Online analysis interval: {self.online_analysis_interval}, must be a "
f"multiple of the checkpoint interval: {self._reporter.checkpoint_interval}")

# Make sure sampler_states is an iterable of SamplerStates.
if isinstance(sampler_states, states.SamplerState):
Expand Down
24 changes: 21 additions & 3 deletions openmmtools/tests/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import contextlib
import copy
import inspect
import math
import os
import pickle
import shutil
import sys
import tempfile
from io import StringIO

import numpy as np
Expand All @@ -35,8 +37,7 @@
import mpiplus

import openmmtools as mmtools
from openmmtools import cache
from openmmtools import testsystems
from openmmtools import cache, testsystems, states, mcmc
from openmmtools.multistate import MultiStateReporter
from openmmtools.multistate import MultiStateSampler, MultiStateSamplerAnalyzer
from openmmtools.multistate import ReplicaExchangeSampler, ReplicaExchangeAnalyzer
Expand Down Expand Up @@ -1595,7 +1596,24 @@ def test_real_time_analysis_yaml(self):
assert len(yaml_contents) == expected_yaml_entries, \
"Expected yaml entries do not match the actual number entries in the file."


def test_real_time_analysis_can_be_none():
"""Test if real time analysis can be done"""
testsystem = testsystems.AlanineDipeptideImplicit()
n_replicas = 3
T_min = 298.0 * unit.kelvin # Minimum temperature.
T_max = 600.0 * unit.kelvin # Maximum temperature.
temperatures = [T_min + (T_max - T_min) * (math.exp(float(i) / float(n_replicas-1)) - 1.0) / (math.e - 1.0)
for i in range(n_replicas)]
temperatures = [T_min + (T_max - T_min) * (math.exp(float(i) / float(n_replicas-1)) - 1.0) / (math.e - 1.0)
for i in range(n_replicas)]
thermodynamic_states = [states.ThermodynamicState(system=testsystem.system, temperature=T)
for T in temperatures]
move = mcmc.GHMCMove(timestep=2.0*unit.femtoseconds, n_steps=50)
simulation = MultiStateSampler(mcmc_moves=move, number_of_iterations=2, online_analysis_interval=None)
storage_path = tempfile.NamedTemporaryFile(delete=False).name + '.nc'
reporter = MultiStateReporter(storage_path, checkpoint_interval=1)
simulation.create(thermodynamic_states=thermodynamic_states,
sampler_states=states.SamplerState(testsystem.positions), storage=reporter)
#############

class TestExtraSamplersMultiStateSampler(TestMultiStateSampler):
Expand Down

0 comments on commit 90d655b

Please sign in to comment.