Closed MarcoMagl closed 7 years ago
The above is confusing as to what you are asking, and there's no traceback, and your link just points to this question… however, since I know of your original posting here, I'm going to assume I know what you are asking. Please correct me if I'm mistaken.
Here's the minimalist example of what happens:
>>> import sympy as sp
>>> x,y = sp.symbols('x,y')
>>> f_ex = 2*x**2 + 2*x*y
>>> f_la = sp.lambdify((x,y),f_ex)
>>> f_ex
2*x**2 + 2*x*y
>>> import dill
>>> dill.settings['recurse'] = True
>>> la = dill.loads(dill.dumps(f_la))
>>> la
<function <lambda> at 0x10b4ed668>
>>> f_ex
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/basic.py", line 392, in __repr__
return sstr(self, order=None)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/str.py", line 748, in sstr
s = p.doprint(expr)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/printer.py", line 233, in doprint
return self._str(self._print(expr))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/printer.py", line 257, in _print
return getattr(self, printmethod)(expr, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/str.py", line 51, in _print_Add
terms = self._as_ordered_terms(expr, order=order)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/printer.py", line 271, in _as_ordered_terms
return expr.as_ordered_terms(order=order)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/expr.py", line 888, in as_ordered_terms
terms, gens = self.as_terms()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/expr.py", line 920, in as_terms
coeff = complex(coeff)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/expr.py", line 229, in __complex__
result = self.evalf()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/evalf.py", line 1377, in evalf
prec = dps_to_prec(n)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mpmath/libmp/libmpf.py", line 67, in dps_to_prec
return max(1, int(round((int(n)+1)*3.3219280948873626)))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2293, in amax
out=out, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_methods.py", line 26, in _amax
return umr_maximum(a, axis, None, out, keepdims)
ValueError: 'axis' entry is out of bounds
As I said on SO, I think this means that the serialization of one object is destroying a pointer or a weakref on another object. It's pretty weird, and I think most definitely a sympy
issue. I'm willing to lend a hand, but it should be a PR to sympy
and not dill
.
You're right, sorry. I will close this thread and open a new one in sympy. I am going to take your title which is probably more accurate than the one I gave :)
I've just done it.
I have described the issue here Here is a minimalist example: from pdb import set_trace import sympy as sp import dill as pickle
And a more complicated one where dill is working nicely to import sympy expressions, but not the corresponding lambda functions:
please do not hesitate to contact me if you require more info. I use Python 3.5.2