question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to resume run following pickle / dill

See original GitHub issue

I’m on dynesty Version: 1.0.1

Following advise in other issues, I am attempting to create resume functionality by pickling the nested_sampler:

dynesty_sampler = NestedSampler(loglikelihood=fitness, prior_transform=prior,ndim=model.prior_count)

dynesty_sampler.run_nested(maxcall=200)

with open("{}/{}.dill".format(path, "nls"), "wb") as f:
     dill.dump(dynesty_sampler, f)

This works fine, in the sense that the instance is output to hard disk (using either pickle or dill).

The problem is when I load the pickle and attempt to continue sampling:

with open("{}/{}.dill".format(path, "nls"), "rb") as f:
    dynesty_sampler = dill.load(f)`

dynesty_sampler.run_nested(maxcall=200)

This gives the following error:

File “/home/jammy/PycharmProjects/VirtualEnvs/PyAuto/lib/python3.6/site-packages/dynesty/sampler.py”, line 928, in run_nested add_live=add_live)): File “/home/jammy/PycharmProjects/VirtualEnvs/PyAuto/lib/python3.6/site-packages/dynesty/sampler.py”, line 782, in sample u, v, logl, nc = self._new_point(loglstar_new, logvol) File “/home/jammy/PycharmProjects/VirtualEnvs/PyAuto/lib/python3.6/site-packages/dynesty/sampler.py”, line 380, in _new_point u, v, logl, nc, blob = self._get_point_value(loglstar) File “/home/jammy/PycharmProjects/VirtualEnvs/PyAuto/lib/python3.6/site-packages/dynesty/sampler.py”, line 364, in _get_point_value self._fill_queue(loglstar) File “/home/jammy/PycharmProjects/VirtualEnvs/PyAuto/lib/python3.6/site-packages/dynesty/sampler.py”, line 337, in _fill_queue point = self.rstate.rand(self.npdim) AttributeError: ‘MultiEllipsoidSampler’ object has no attribute ‘rstate’

Any help appreciated!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
segasaicommented, May 12, 2022

The sampler can be pickled/dilled, if the likelihood function can. If the likelihood function is not pickleable it needs to be set to None likely before pickling. Regarding the restarting from results, I don’t believe it is possible. I don’t know if it is worth implementing. IMO it is worth implementing a more user-friendly way of setting a pool after the restore (and maybe setting the likelihood function, if it’s also nonpickleable)

1reaction
Jammy2211commented, Jun 23, 2020

Found the following workaround, by removing the loglike before pickling:

            sampler_pickle = sampler
            sampler_pickle.loglikelihood = None

            with open(f"{self.paths.samples_path}/dynesty.pickle", "wb") as f:
                pickle.dump(sampler_pickle, f)

            sampler_pickle.loglikelihood = fitness_function
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to dill (pickle) to file? - python - Stack Overflow
Just give it the file without the read : resultstatsDF_out = dill.load(dill_file). you can also dill to file like this:
Read more >
Pickle in Python Tutorial: Object Serialization - DataCamp
Discover the Python pickle module: learn about serialization, when (not) to use it, how to compress pickled objects, multiprocessing, and much more!
Read more >
The ultimate guide to Python pickle - Snyk
This article will teach you how to safely use Python's built-in pickle library to maintain persistence within complex data structures.
Read more >
How To Restore Your Jupyter Notebook Session
Well, the only advice I can give you is to “Restart the Kernel and rerun all the cells”. But it doesn't have to...
Read more >
Troubleshooting common problems with home canned pickles
If you experience problems with hollow pickles, the most common cause is too much time between gathering and pickling. Start processing as soon...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found