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

Save pipeline "can't pickle abc_data objects" error #69

Closed
luizfelippesr opened this issue Oct 21, 2020 · 0 comments · Fixed by #70
Closed

Save pipeline "can't pickle abc_data objects" error #69

luizfelippesr opened this issue Oct 21, 2020 · 0 comments · Fixed by #70
Labels
bug Something isn't working infrastructure Installation, optimization, internal (re)organization

Comments

@luizfelippesr
Copy link
Member

luizfelippesr commented Oct 21, 2020

As first reported by @ashley-stock, trying to save a Pipeline object which includes FieldFactory classes defined within the running notebook leads to error. A minimal version of such error can be seen below:

import imagine as img
import imagine_datasets as img_data

original_bregLSA = img.fields.hamx.BregLSAFactory()

class LocalBregLSAFactory(img.fields.FieldFactory):
    """This is fully equivalent to BregLSAFactory!"""
    FIELD_CLASS = original_bregLSA.field_class
    DEFAULT_PARAMETERS = original_bregLSA.default_parameters
    PRIORS = original_bregLSA.priors

factory_list = [LocalBregLSAFactory()]
measurement = img.observables.Measurements(img_data.HEALPix.fd.Oppermann2012(Nside=2))
simulator = img.simulators.Hammurabi(measurement)
likelihood = img.likelihoods.EnsembleLikelihood(measurement)
pipeline = img.pipelines.MultinestPipeline(simulator=simulator,
                                           likelihood=likelihood, 
                                           factory_list=factory_list)
pipeline.save()

this leads to

TypeError: can't pickle _abc_data objects

Interestingly, if one replaces LocalBregLSAFactory() by original_bregLSA, everything works normally.

The error is actually a problem with dill and the way it serializes objects defined in __main__. We can get the same error by simply doing (using the same definitions as above):

with open('/tmp/test.pkl', 'wb') as f:
    dill.dump(LocalBregLSAFactory(), f)

Issue uqfoundation/dill#332 is related to this.

@luizfelippesr luizfelippesr added bug Something isn't working infrastructure Installation, optimization, internal (re)organization labels Oct 21, 2020
luizfelippesr added a commit that referenced this issue Oct 21, 2020
This should fix issue #69.
@luizfelippesr luizfelippesr linked a pull request Oct 21, 2020 that will close this issue
luizfelippesr added a commit that referenced this issue Oct 23, 2020
This should fix issue #69.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working infrastructure Installation, optimization, internal (re)organization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant