joshspeagle / dynesty

Dynamic Nested Sampling package for computing Bayesian posteriors and evidences
https://dynesty.readthedocs.io/
MIT License
347 stars 76 forks source link

Saving DynamicNestedSampler class #187

Closed psheehan closed 4 years ago

psheehan commented 4 years ago

Thanks for putting this great code together! I've been testing using it with fairly expensive likelihood functions, and so it's convenient to be able to save progress, in case the run dies for some reason (or hits a time limit a la a supercomputer) it can be started up again from where it left off. I've been doing this by pickling the sampler object from time to time so that it can be reloaded and restarted.

This works really well for NestedSampler, but for the DynamicNestedSampler class there's a problem if it dies during the initial nested sampling run (which is frequently - my likelihood functions can get expensive) as the "sub" NestedSampler class doesn't save samples, and sample_initial always assumes starting from 0 and resets. I was able to get around this by adding keywords to sample_initial to allow the NestedSampler sub-sampler to also save samples as it goes, and by adding a resume option that allows the function to skip the initial setup. The changes can be found in a forked version here. (The git diff didn't come out very well... but it basically puts the setup block of sample_initial into an "if not resume:" block).

This may not be the most elegant way to do this... but I thought I'd mention it here in case these changes are something you'd be interested in, or in case there's a better way to do this? Or perhaps in case somebody else has come across this problem.

Thanks!

joshspeagle commented 4 years ago

This seems like a reasonable workaround that I would be happy to merge into the main branch!

psheehan commented 4 years ago

Awesome, thanks! I'll create a pull request.

jluastro commented 4 years ago

Fantastic addition! Did this get merged in and closed? I'd love to use it.

joshspeagle commented 4 years ago

Ah no -- I just realized I never actually merged this. I'll flag it in my to-do list and try to get to it ASAP (hopefully by early next week). Thanks!

joshspeagle commented 4 years ago

Just merged in two PRs that should hopefully resolve this.

psheehan commented 4 years ago

Awesome, thanks so much!