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 verified that dill is able to dump sympy symbolic expressions. Unfortunately, there are expressions that contain symbols that may be a function of time (e.g. dynamicsymbols).
import sympy as sp
import dill
from sympy.physics.mechanics import dynamicsymbols
q = dynamicsymbols('q')
t = sp.symbols('t')
dump = dill.dumps(q, -1)
Is there a way to export these kind of expressions.
Best
The text was updated successfully, but these errors were encountered:
It seems that there's a simple workaround that will allow these objects to be pickled:
import sympy as sp
import dill
from sympy.physics.mechanics import dynamicsymbols
q = dynamicsymbols('q')
t = sp.symbols('t')
q.__class__.__module__ = '__main__'
_q = dill.dumps(q)
q_ = dill.loads(_q)
assert q_ == q
The question is now: is this a general fix (i.e. it should be applied to all kinds of objects missing the module information) and thus should go into dill -- or is it a sympy-specific workaround, and thus should be applied in sympy? (FYI @asmeurer)
Also fixes it for sympy.Function('f')(sympy.Symbol('x')). It is a dynamically created class from a metaclass. It looks like __module__ is set to None before you set it to __main__.
This succeeds for python 3.x, and fails for python 2.7. dill will drop support for `2.7 after the upcoming release, and then will close this issue at this time. See #413
Hi,
I verified that dill is able to dump sympy symbolic expressions. Unfortunately, there are expressions that contain symbols that may be a function of time (e.g.
dynamicsymbols
).Is there a way to export these kind of expressions.
Best
The text was updated successfully, but these errors were encountered: