Skip to content

Commit

Permalink
Merge pull request #400 from mj-will/improve-resume
Browse files Browse the repository at this point in the history
Improve resuming when run is finished
  • Loading branch information
mj-will authored Jul 23, 2024
2 parents 807d279 + edb1b8e commit 2b627e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nessai/proposal/flowproposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def names(self):
def rescaled_names(self):
warn(
(
"`rescaled_names` is deprecated, use `rescaled_parameters` "
"`rescaled_names` is deprecated, use `prime_parameters` "
"instead"
),
FutureWarning,
Expand Down
3 changes: 3 additions & 0 deletions nessai/samplers/nestedsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,9 @@ def nested_sampling_loop(self):
nested_samples : numpy.ndarray
Array of nested samples.
"""
if self.finalised:
logger.info("Run has already finished!")
return self.log_evidence, np.array(self.nested_samples)
self.sampling_start_time = datetime.datetime.now()
if not self.initialised:
self.initialise(live_points=True)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_samplers/test_nested_sampler/test_core_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def test_nested_sampling_loop(sampler, config):
def test_nested_sampling_loop_prior_sampling(sampler, close_pool):
"""Test the nested sampling loop for prior sampling"""
sampler.initialised = False
sampler.finalised = False
sampler.nested_samples = sampler.model.new_point(10)
sampler.prior_sampling = True
sampler._close_pool = close_pool
Expand All @@ -288,3 +289,15 @@ def test_nested_sampling_loop_prior_sampling(sampler, close_pool):
sampler.finalise.assert_called_once()
assert_structured_arrays_equal(samples, sampler.nested_samples)
assert evidence == -5.99


def test_nested_sampling_loop_already_finished(sampler, caplog):
caplog.set_level("INFO")
sampler.finalised = True
sampler.log_evidence = 0.1
sampler.nested_samples = [1, 2, 3]
logz, ns = NestedSampler.nested_sampling_loop(sampler)
assert "Run has already finished!" in str(caplog.text)
sampler.check_resume.assert_not_called()
assert logz is sampler.log_evidence
np.testing.assert_array_equal(ns, np.array(sampler.nested_samples))

0 comments on commit 2b627e5

Please sign in to comment.