From 2b4114c6c3b0b9d1e4a9a329d6612855bd252080 Mon Sep 17 00:00:00 2001 From: "Sergey E. Koposov" Date: Tue, 25 Jun 2024 16:13:15 -0400 Subject: [PATCH] Fix #475, add a corresponding test also deprecate repeated run_nested() runs --- CHANGELOG.md | 6 +++--- docs/source/index.rst | 1 + py/dynesty/sampler.py | 7 ++++++- tests/test_blob.py | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15c57551a..0720dabd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,9 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Changed - Get rid of npdim option that at some point may have allowed the prior transformation to return higher dimensional vector than the inputs. Note that due to this change, restoring the checkpoint from previous version of the dynesty won't be possible) (issues #456, #457) (original issue reported by @MichaelDAlbrow, fixed by @segasai ) ### Fixed -- Fix the way the additional arguments are treated when working with dynesty's pool. Previously those only could have been passed through dynesty.pool.Pool() constructor. Now they can still be provided directly to the sampler (not recommended) (reported by @eteq, fixed by @segasai ) -- change the .ptp() method to np.ptp() function as it is deprecated in numpy 2.0 (reported and patched by @joezuntz) - +- Fix the way the additional arguments are treated when working with dynesty's pool. Previously those only could have been passed through dynesty.pool.Pool() constructor. Now they can still be provided directly to the sampler (not recommended) ( #464 , reported by @eteq, fixed by @segasai ) +- change the .ptp() method to np.ptp() function as it is deprecated in numpy 2.0 ( #478 , reported and patched by @joezuntz) +- Fix an error if you use run_nested() several times (i.e. with maxiter option) while using blob=True. ( #475 , reported by @carlosRmelo,) ## [2.1.3] - 2023-10-04 ### Added diff --git a/docs/source/index.rst b/docs/source/index.rst index 97333ac65..a3a63e3bf 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -103,6 +103,7 @@ Changelog - Get rid of npdim option that at some point may have allowed the prior transformation to return higher dimensional vector than the inputs. Note that due to this change, restoring the checkpoint from previous version of the dynesty won't be possible) (issues #456, #457) (original issue reported by @MichaelDAlbrow, fixed by @segasai ) - Fix the way the additional arguments are treated when working with dynesty's pool. Previously those only could have been passed through dynesty.pool.Pool() constructor. Now they can still be provided directly to the sampler (not recommended) (reported by @eteq, fixed by @segasai ) - change the .ptp() method to np.ptp() function as it is deprecated in numpy 2.0 (reported and patched by @joezuntz) +- Fix an error if you use run_nested() several times (i.e. with maxiter option) while using blob=True. ( #475 , reported by @carlosRmelo,) 2.1.3 (2023-10-04) ------------------ diff --git a/py/dynesty/sampler.py b/py/dynesty/sampler.py index 8c6e09f23..8da70934d 100644 --- a/py/dynesty/sampler.py +++ b/py/dynesty/sampler.py @@ -589,7 +589,7 @@ def _remove_live_points(self): for k in [ 'id', 'u', 'v', 'logl', 'logvol', 'logwt', 'logz', 'logzvar', 'h', 'nc', 'boundidx', 'it', 'bounditer', - 'scale' + 'scale', 'blob' ]: del self.saved_run[k][-self.nlive:] else: @@ -729,6 +729,11 @@ def sample(self, else: # Remove live points (if added) from previous run. if self.added_live and not resume: + warnings.warn( + 'Repeatedly running sample() or run_nested() ' + '(when not just resuming an existing run is considered ' + 'deprecated and will be removed in the future', + DeprecationWarning) self._remove_live_points() # Get final state from previous run. diff --git a/tests/test_blob.py b/tests/test_blob.py index c813392ae..17c603b5e 100644 --- a/tests/test_blob.py +++ b/tests/test_blob.py @@ -85,6 +85,25 @@ def test_gaussian(): assert np.all(res['blob'] == res['samples']) +def test_restart(): + rstate = get_rstate() + g = Gaussian() + sampler = 'rslice' # doing this sampler for static + # unifor for dynamic + sampler = dynesty.NestedSampler(g.loglikelihood_with_blob, + g.prior_transform, + g.ndim, + nlive=nlive, + rstate=rstate, + sample=sampler, + blob=True) + sampler.run_nested(print_progress=printing, maxiter=100) + sampler.run_nested(print_progress=printing, maxiter=100) + res = sampler.results + assert res['blob'].shape == (len(res['samples']), 3) + assert np.all(res['blob'] == res['samples']) + + def test_gaussian_livepts(): # test we can provide starting points while using blobs rstate = get_rstate()