diff --git a/openmmtools/cache.py b/openmmtools/cache.py index 06119a42e..536a61369 100644 --- a/openmmtools/cache.py +++ b/openmmtools/cache.py @@ -318,6 +318,10 @@ def time_to_live(self): def time_to_live(self, new_time_to_live): self._lru.time_to_live = new_time_to_live + def empty(self): + """Clear up cache and remove all Contexts.""" + self._lru.empty() + def get_context(self, thermodynamic_state, integrator): """Return a context in the given thermodynamic state. diff --git a/openmmtools/tests/test_mcmc.py b/openmmtools/tests/test_mcmc.py index bcd12c8dd..c79a322d2 100644 --- a/openmmtools/tests/test_mcmc.py +++ b/openmmtools/tests/test_mcmc.py @@ -211,6 +211,7 @@ def test_context_cache(): thermodynamic_state = ThermodynamicState(testsystem.system, 300*unit.kelvin) # By default the global context cache is used. + cache.global_context_cache.empty() # Clear cache from previous tests. move = SequenceMove([LangevinDynamicsMove(n_steps=5), GHMCMove(n_steps=5)]) move.apply(thermodynamic_state, sampler_state) assert len(cache.global_context_cache) == 2