PSLmodels / ParamTools

Library for parameter processing and validation with a focus on computational modeling projects
https://paramtools.dev
MIT License
19 stars 14 forks source link

Pickling a paramtools object #101

Closed jdebacker closed 4 years ago

jdebacker commented 4 years ago

@hdoupe I often like to save my parameters object with a model run to be able to return to that exact specification. With the newest paramtools 0.13.1, I'm finding that I can no longer pickle the paramtools object as I could before:

In [1]: import ogusa
from ogusa.paramet
In [2]: from ogusa.parameters import Specifications

In [3]: import pickle

In [4]: p = Specifications()

In [5]: pickle.dump(p, open('test_param_pickle.pkl', 'wb'))
---------------------------------------------------------------------------
PicklingError                             Traceback (most recent call last)
<ipython-input-5-02455fbfcece> in <module>
----> 1 pickle.dump(p, open('test_param_pickle.pkl', 'wb'))

PicklingError: Can't pickle <class 'marshmallow.schema.DefaultsSchema'>: attribute lookup DefaultsSchema on marshmallow.schema failed

Is this expected? Suggestions on workarounds?

hdoupe commented 4 years ago

Thanks for opening this issue @jdebacker. You can use cloudpickle to pickle Parameters objects. Here are some related issues/comments:

https://github.com/PSLmodels/ParamTools/issues/78 https://github.com/marshmallow-code/marshmallow/pull/1469#issuecomment-564584443

cloudpickle should be installed with dask. Once you dump the objects with cloudpickle, you can load them like usual with regular pickle. Is that an OK solution with you?

jdebacker commented 4 years ago

@hdoupe Thanks for quick reply. I now recall you helping me with this before - sorry to forget.

hdoupe commented 4 years ago

No worries!