TuringLang / AbstractMCMC.jl

Abstract types and interfaces for Markov chain Monte Carlo methods
https://turinglang.org/AbstractMCMC.jl
MIT License
87 stars 18 forks source link

Interrupting and resuming sampling #73

Closed kaandocal closed 3 years ago

kaandocal commented 3 years ago

I was wondering if there is any possibility to concatenate chains horizontally. I often need to run long MCMC simulations and sometimes decide afterwards that I need more samples, but I haven't found a simple way to extend chains (I mostly use MCMCChains so this might be more relevant to that package). An overload of sample that takes a chain as an input and continues sampling from there might be a nice idea; any thoughts?

devmotion commented 3 years ago

You can concatenate MCMCChains.Chains objects with vcat (more iterations), hcat (more parameters), or cat(...; dims=3) (more chains).

Resuming is possible with Turing and we want to move it upstream to AbstractMCMC (see https://github.com/TuringLang/AbstractMCMC.jl/discussions/72#discussioncomment-753238).

kaandocal commented 3 years ago

Thanks a lot for the fast reply! I tried experimenting with vcat unsuccessfully but this might have been due to errors on my side. Would there be any interest in a tentative implementation or would you rather work on that yourself as a more experienced Turing contributor?

devmotion commented 3 years ago

An implementation of the resume functionality? Contributions are always welcome :slightly_smiling_face: My suggestion would be to check if one can use the approach outlined in the comment linked above.

kaandocal commented 3 years ago

Apologies for not checking in on this issue for a while, I think the vcat issue has been resolved thanks to your comments. I am still pondering whether it would be useful to include some more high-level options for saving chains/creating backups as I've accidentally Ctrl-C'd my samplers a bit too often for my liking, but that would be another issue I guess. For now I'm just using a callback to save the chain every once in a while...