Skip to content
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

example for continuing sampling from a periodically saved trace #109

Open
unaschneck opened this issue Mar 13, 2024 · 1 comment
Open

example for continuing sampling from a periodically saved trace #109

unaschneck opened this issue Mar 13, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@unaschneck
Copy link

Hi,

Thank you for making this! I am a little unclear from the readme documentation how I would go about reloading the saved trace to continue an interrupted sampling. Ideally, I'd like to determine the total number of sampling and burn steps ahead of time and then have an ongoing save after each sample in case of a power outage or the job being interrupted in the server and reload from previously saved trace.

I am trying to implement something like

ch_client = clickhouse_driver.Client("localhost")
backend = mcbackend.ClickHouseBackend(ch_client)
trace = mcbackend.pymc.TraceBackend(backend)

continue_run = 0 # here is where I would activate a flag if the last run was not completed because the job was interrupted

with my_model:
if continue_run:
trace_id = pm.sample(***restart sampling from saved trace***)
else:
trace_id = pm.sample(draws=number_samples, tune=number_burn_samples, chains=number_walkers, cores=number_processors, return_inferencedata=True, target_accept=0.95,trace=trace) # save ongoing trace to backend

@michaelosthege michaelosthege added the help wanted Extra attention is needed label Mar 17, 2024
@michaelosthege
Copy link
Member

Hi @unaschneck this is a frequently asked-for thing, but unfortunately it's not easy to restore the state of an MCMC sampler.
I built McBackend to be useful for this, but it requires digging into the way how sampler state & random number generators work in PyMC. Even if you don't care about reproducibility, you'll still need to restore the tuned parameters, such as mass matrix settings of NUTS.

Also see my previous comment here: https://discourse.pymc.io/t/resuming-sampling-from-a-previous-trace/11245/5

Also, this is 100 % something that needs to be done on the PyMC side. I'll still leave this issue open so other people find it more easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants