dynesty: Unable to resume run following pickle / dill

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!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

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)

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

Okay, I’ll move this up on my to-do list and also plan to add in additional information into the documentation.