Coder Social home page Coder Social logo

Cloudpickle compatibility about param HOT 3 CLOSED

samimia-swks avatar samimia-swks commented on June 12, 2024
Cloudpickle compatibility

from param.

Comments (3)

maximlt avatar maximlt commented on June 12, 2024

Hi @samimia-swks,

cloudpickle is indeed mentioned in the docs, albeit in a pretty light way 🙃

lambdas cannot easily be pickled for saving and restoring state (though see cloudpickle for an alternative to pickle that does support lambdas)

Unfortunately it seems that Param doesn't support it out of the box, even for very simple cases like the one you tried above. It'd be nice to add support for cloudpickle (and fix the original support for pickle if it's been broken in some ways), contributions in the area of serializing/deserializing Param objects are welcomed :) !

from param.

samimia-swks avatar samimia-swks commented on June 12, 2024

Hi @maximlt,

I was able to figure out that cloudpickle (or dill) support was broken by #386 which is between version 1.9.3 and 1.10.0.

If I remove the offending lines of code, which are the definition setstate() method for the Parameters class, I can get cloudpickle to pickle a Parametrized class with both lambdas and @param.depends() decorators even on the latest 1.13.0 version :

    def __setstate__(self, state):
        # Set old parameters state on Parameterized._parameters_state
        self_or_cls = state.get('self', state.get('cls'))
        for k in self_or_cls._parameters_state:
            key = '_'+k
            if key in state:
                self_or_cls._parameters_state[k] = state.pop(key)
        for k, v in state.items():
            setattr(self, k, v)

From what I understand, this is a method that's called by pickle after unpickeling. However, I can't tell what it is doing because things still seem to work without it. My knowledge of python and this project is not nearly good enough to figure this out in the short terrm :)

Perhaps @philippjfr, who authored this code can clarify.

from param.

maximlt avatar maximlt commented on June 12, 2024

Thanks @samimia-swks I'm sure that's going to be very helpful!

from param.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.