Skip to content

Commit

Permalink
Fix #475, add a corresponding test
Browse files Browse the repository at this point in the history
also deprecate repeated run_nested() runs
  • Loading branch information
segasai committed Jun 25, 2024
1 parent 46acf54 commit 2b4114c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
7 changes: 6 additions & 1 deletion py/dynesty/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions tests/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2b4114c

Please sign in to comment.