You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been using SymPy recently. Anonymous functions can be generated using sympy.lambdify.
I required to store these for later, as they can be computationally expensive to generate the expressions in the first place; i.e., solving an ODE system symbolically.
dill came to mind as I have previously used it to pickle a lambda, however it was giving errors. Here is a minimalistic example of a simple function:
importsympyimportdill# use basic session, puts multiple symbols in scopesympy.init_session()
# create expression, simple for exampleexpr=2*x+y# generate anonymous functionfunc=sympy.lambdify((x, y), expr)
print(func(5, 6)) #=> prints 16# pickle filepickled_func=dill.dumps(func)
Where I get a big error that traces back to:
PicklingError: Can't pickle : it's not found as mpmath.ctx_mp_python.constant
Now I thought this maybe an issue with how SymPy generates the function, however cloudpickle was able to successfully pickle the function:
importpickleimportcloudpickleprint(pickle.loads(cloudpickle.dumps(func))(5, 6)) #=> prints 16
It was brought to my attention that this may be unexpected behaviour with how dill interprets lambdas of objects; and thus you should be made aware.
The text was updated successfully, but these errors were encountered:
If you use the flag recurse=True on dumps, dill can pickle your func (see #86). This behavior will likely become the default setting once #105 is resolved.
I have been using SymPy recently. Anonymous functions can be generated using
sympy.lambdify
.I required to store these for later, as they can be computationally expensive to generate the expressions in the first place; i.e., solving an ODE system symbolically.
dill
came to mind as I have previously used it to pickle a lambda, however it was giving errors. Here is a minimalistic example of a simple function:Where I get a big error that traces back to:
Now I thought this maybe an issue with how SymPy generates the function, however
cloudpickle
was able to successfully pickle the function:It was brought to my attention that this may be unexpected behaviour with how
dill
interprets lambdas of objects; and thus you should be made aware.The text was updated successfully, but these errors were encountered: