(python) pickling casadi classes

  • Anonymous - 2012-08-13

    I was wondering if anyone has had success using python's pickle module to serialize and save casadi classes to binary files. The motivation behind this being a lot of parallel routines pickle your objects to send them to nodes (and otherwise its often nice to be able to save results/functions to a re-loadable file).

    Currently, when I try to pickle an object I get the error

    PicklingError: Can't pickle <type 'SwigPyObject'>: it's not found as __builtin__.SwigPyObject

    a quick google search mentions that pickling Swig objects is a common problem, and you need to define __setstate__ and __getstate__ methods. (http://stackoverflow.com/questions/9310053/how-to-make-my-swig-extension-module-work-with-pickle)

    I currently get around this by removing any references to casadi objects before saving my data, but if there was a (relatively) easy way to pickle them it would certainly save me some effort. Has anyone come across this before?


  • Joel Andersson

    Joel Andersson - 2012-08-13

    I have no experience with this. Joris, have you ever "pickled" anything?

  • jgillis

    jgillis - 2012-08-13

    Sure I've had my fair share of pickling, but not with CasADi.
    I wasn't aware of workarounds to make pickling work with SWIG.
    Thanks, Peter!
    I will have a second look at https://sourceforge.net/apps/trac/casadi/ticket/308

  • Anonymous - 2012-08-14

    wow, great! Thanks for looking into this!



Log in to post a comment.