-
Notifications
You must be signed in to change notification settings - Fork 85
Parallel uniform sampling + New sampler interface #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
nestedsamplers classes can probably be removed at some point
Pull Request Test Coverage Report for Build 7952108689Details
💛 - Coveralls |
!!!! This is an excellent proposed change! Very interested to see how the other internal refactoring might also work. |
and unify it all in one class The only thing I had to disable is the 'custom sampler' test in test_misc
Thanks @joshspeagle |
The demonstration of this patch. The following uniform sampling of Eggbox with single bound 9490it [03:16, 48.25it/s, +1000 | bound: 999 | nc: 1 | ncall: 12943702 | eff(%): 0.081 | loglstar: -inf < 243.000 < inf | logz: 235.863 +/- 0.078 | dlogz: 0.000 > 0.100] And if I bump the number of threads to 36 , it takes 50 seconds. I.e. basically it scales properly, while previously uniform sampler basically didn't really scale with multiple threads. import numpy as np
import dynesty
import multiprocessing as mp
nlive = 1000
def loglike_egg(x):
logl = ((2 + np.cos(x[0] / 2) * np.cos(x[1] / 2))**5)
return logl
def prior_transform_egg(x):
return x * 10 * np.pi
LOGZ_TRUTH = 235.856
def test_bounds():
bound, sample = 'single', 'unif'
# stress test various boundaries
ndim = 2
rstate = np.random.default_rng(444)
with mp.Pool(4) as poo:
sampler = dynesty.NestedSampler(loglike_egg,
prior_transform_egg,
ndim,
nlive=nlive,
bound=bound,
sample=sample,
rstate=rstate,
pool=poo,
queue_size=4)
sampler.run_nested(dlogz=0.1, print_progress=True)
assert (abs(LOGZ_TRUTH - sampler.results.logz[-1])
< 5. * sampler.results.logzerr[-1])
if __name__ == '__main__':
test_bounds() |
rearrange sampler arguments to make them more logical
It would be great to have some review of this patch @joshspeagle if you have time, before the patch gets bigger. My current thinking is the patch is mostly positive with a few negatives listed below:
Among things I'd like to do, but I don't want to do in this patch: I think with this patch it's becoming easier to do #391. We already now can pack update_slice or update_rwalk in SliceSampler RWalkSampler objects and make sure that things like history dynesty/py/dynesty/nestedsamplers.py Line 145 in 3f10025
|
move the initialize function around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new sampler interface for parallel uniform sampling while deprecating several legacy components. Key changes include replacing function‐based samplers with object‐instantiated versions, renaming several internal attributes (e.g. “bound” → “bound_list” and “M” → “mapper”), and removing or refactoring tests for deprecated custom update functionality.
Reviewed Changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/test_sampling.py | Updated sampler references to use new object‐based sampler API. |
tests/test_misc.py | Removed tests for custom sampler registration and update logic. |
tests/test_gau.py | Adjusted formatting and removed gradient–related tests. |
tests/test_ellipsoid.py | Updated ellipsoid Monte Carlo calls to use new “ctrs” attribute. |
py/dynesty/utils.py | Renamed “M” attribute to “mapper” in restore_sampler method. |
py/dynesty/plotting.py | Updated bound sampling calls to use “ctrs” instead of extra args. |
py/dynesty/dynesty.py | Refactored sampler initialization and internal API (e.g. removed gradient argument in auto–selection, updated citations, renamed ncall). |
py/dynesty/dynamicsampler.py | Refactored dynamic sampler internals including renaming bound→bound_list and updating pool mapping usage. |
docs/source/conf.py | Minor comment update. |
.readthedocs.yaml & .github/workflows/test.yml | Updated build environment and python versions. |
Files not reviewed (2)
- docs/source/api.rst: Language not supported
- docs/source/references.rst: Language not supported
This reverts commit a57e419. to avoid numpy 1.25 requirement
Hi @segasai, this looks like a great update to
I just wanted to chime in on this as a downstream user; I'd strongly favour a 3.0 version if possible since it will make the maintenance on our side a lot easier and cleaner. Thanks for continued work on |
…t propagated properly, fix now
get rid of unused options
This is a preliminary version of patch that enables parallel uniform sampling.
The idea is to get away from this propose/evolve for uniform distributions where evolve doesn't really do anything other than evaluate logl on a single pt, but instead make propose a no-op for uniform, and evolve() actually do the sampling inside the boundary till a satisfactory pt is found.
While implementing this I realized that after some changes all the different samplers in nestedsamplers.py may not need to be there as they do something very similar (but that's tbd).
ATM some tests fail, but I think that's fixable.
Also some class members had to be renamed. I.e. .bound attribute is really misleading in the classes as it was storing the list of all the historic bounds, so I renamed that to bound_list.