Pickling eq objects

For equadratures to slot into a number of workflows (i.e. Dash apps, DevOps etc), it would be very useful for eq objects to be pickle-able.

At the moment pickle (and joblib) cannot pickle certain eq classes due to a number of attributes such as lambda functions (for some reason jsonpickle can though). There’s also some extraneous attributes that we don’t really want to save with the model, such as the training data (Poly.inputs and Poly.outputs).

We either need to implement options to avoid storing problem attributes in the classes, or save methods which strip out problem attributes before pickling themselves. I will hopefully find some time to implement this soon, but posting now in case anyone has anything to add here.

1 Like

Just a thought: can we just save the coefficients, list of parameters, and basis attributes and then alter the Poly constructor to read those in from a saved file(s)?

1 Like

Good idea!

I actually just fixed the issue with Poly not being pickle-able (I think, needs more testing!) by removing a few redundant lambda functions e.g. in subsampling.py:

# this:
self.algorithm = lambda A, k: _get_all_pivots(A, k)
# replaced with:
self.algorithm = _get_all_pivots

Tutorial showing save/load capability here:
https://equadratures.org/_documentation/tutorials/Object_Persistence.html

I still like your idea as it will allow for smaller file sizes (we won’t be storing the training data etc). I reckon we should keep this request open to implement this too at some point.

2 Likes