-
Notifications
You must be signed in to change notification settings - Fork 8
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
Parallel Sampling #70
Comments
We could achieve this without too significant of an API overhaul with the following: Implement the following methods AbstractMCMC.sample(::AbstractRNG, ::NestedModel, ::Nested, ::MCMCThreads; kwargs...)
AbstractMCMC.sample(::AbstractRNG, ::NestedModel, ::Nested, ::MCMCDistributed; kwargs...) these methods should not be functionally different than AbstractMCMC.step(::AbstractRNG, ::NestedModel, ::Nested, ::MCMCThreads, state; kwargs...)
AbstractMCMC.step(::AbstractRNG, ::NestedModel, ::Nested, ::MCMCDistributed, state; kwargs...) The Proposals.(::AbstractProposal)(rng, ::MCMCThreads, point, logl_star, bounds, loglike, prior_transform; kwargs...)
Proposals.(::AbstractProposal)(rng, ::MCMCDistributed, point, logl_star, bounds, loglike, prior_transform; kwargs...) which looks roughly like (pseudocode)
this would require minimal code-rewriting, because we can effectively wrap all the existing proposal code. This also means each task's proposal will evolve independently, and I'm not sure what the repercussions of that are (or how dynesty/polychord manage that). In order to have the proposals evolve homogenously, I'd have to find a way to refactor the proposal code with generic ways to iterate and check for completion. |
@devmotion @cpfiffer this seems like I'm really pushing the boundaries of the |
Okay you mentioned that the parallelization is within the sample, right? Is that the correct reading? If so, I don't think you should need to touch I.e. you could add |
I think your proposed method should be good: Proposals.(::AbstractProposal)(rng, ::MCMCThreads, point, logl_star, bounds, loglike, prior_transform; kwargs...)
Proposals.(::AbstractProposal)(rng, ::MCMCDistributed, point, logl_star, bounds, loglike, prior_transform; kwargs...) |
It's just contextualization so internally we know we need to parallelize the sampling, it could be a keyword argument, too. |
Ah, okay, then yeah I like what you have ( I don't necessarily want to pass the chain threading context (the one we give |
I am sorry that it took almost 6 months (I am the one who asked @mileslucas about parallelizing Nested Sampling), but now I really can help on this particular item.
However, as far as I understand. the likelihood for each accepted point is not saved, only the likelihood of the final state. Tomorrow I'll make a couple of tests, in order to understand correctly the algorithm they propose and if it's worth implementing it. After this, I'll write here my findings and I'll ask to you how to proceed. |
Hi @mileslucas , Here is attached the code I have written. This is NOT a beautiful code, this is just meant to show that it is indeed possible to merge more chains after a single run. Please, let me know if you have any suggestions or considerations. In order to improve what I have done, I'd need to have saved for each point in the chains the value of the logl (I am computing it again, which is kind of inefficient). |
@marcobonici Sorry for such a belated response. This is really nice to see! Your chain-merging code doesn't look too shabby
This is available in the raw samples (see here for example of the sample and state tuples). To get these, you'll want to run
so you can directly access them in this way. That being said, as you'll see here there is some minor processing of the samples that won't be automatically done in this case. So you'll have to manually add this to your analysis. Thanks for taking a look into this! Thanks for your patience while I haven't been super available; I'm eager to see what you can come up with. |
Hi @mileslucas , |
No worries, I'm also very behind on stuff from working on a paper, currently. As you start working on it feel free to ask me anything! |
Hi @mileslucas ,
This is the easy part. |
Sounds good, make sure to follow the API in the AbstractMCMC interface
Do you just need the log-likelihoods of the sampled points? If so, this is already stored for each sample, it just doesn't get exposed for some of the output types. |
Hi @mileslucas , I have modified the |
Here we are! I have obtained a few interesting results:)
From the tests I have performed, it seems that merging chains improve the posterior we obtain (as in the preliminary plots I obtained a few weeks ago). I have checked the algorithm using the example problems I found in this repo. Probably I'll continue investigating using other problems where I have a closed form for the posterior. |
Hi @marcobonici @mileslucas - is there any more progress on using parallelisation here? In Dynesty we can pass a |
Hi @tomkimpson I have not looked at it and I do not have time right now with my commitments to my PhD thesis. Sorry- I believe Marco had a working version he emailed to me a few months ago, I do not know if that still works. |
Although sampling in NS is not as easily parallelizable as MCMC, there are still opportunities for multi-threading/multi-processing during the sample proposal step. Following the formalism of https://www.wesleyhenderson.me/pdfs/Parallelized_Nested_Sampling_Henderson_Goggans.pdf when we propose a new point during the sample steps, the proposals can be done in parallel, accepting the first new point that fulfills the likelihood constraints. This is implemented in dynesty using Python's
multiprocessing.pool
.If we overload
AbstractMCMC.sample
methods using theMCMCDistributed
andMCMCThreads
structs, we should be able to do something similar, although I don't have a clear idea of the implementation figured out.The text was updated successfully, but these errors were encountered: