To begin with, here is the outline of the workflow I want to do: 1. Use sympy to "do the math" and develop some expressions 2. Lambdify the corresponding expressions 3. Store the corresponding lambda functions in a file 4. Load them in an independent part of my code
Everything goes fine until step 3. I tried different things, and in particular after having read this this is a minimalistic example I would like to make work:
import sympy as sp
import dill as pickle
x, y = sp.symbols("x, y")
f_example = 2*x**2 + 2*x*y
f_lbda= sp.lambdify((x, y),f_example )
pickle.settings['recurse'] = True
fileW = open('file_where_I_dump.dill', 'wb')
# the following line crashes
pickle.dump([f_lbda, f_lbda], fileW)
fileR = open('file_where_I_dump.dill', 'rb')
f_lbda_loaded = pickle.load(fileR)
I get this error (after an important number of During handling of the above exception, another exception occurred
:
ValueError: 'axis' entry is out of bounds
Am I missing something important here ?
Note: when I dump the sympy expressions instead and lambdify the function after a pickle.load, everything goes fine. But this is not exactly the workflow I need !
Thanks for your help !
Here's a slightly modified version of your code (below): It looks like a bug. Note that pickling the lambda expression destroys the original symbolic expression object!
I'm the
dill
author. I'd suggest posting it as asympy
github issue -- f you post it as adill
issue, I'll dig into it then punt it over tosympy
.