On Thu, Jan 10, 2013 at 3:01 PM, Vinzenz Bargsten
<
vbar...@googlemail.com> wrote:
> Hi,
>
> I would like to use sympy expressions with multiprocessing. This requires
> the expressions to be pickled. As this is currently not possible with
> functions included in the expressions, I tried using srepr and str to
> convert the expressions to strings and then hand them over to other
> processes. However, I observed that my expressions are not correctly
> restored (first using srepr, eval), especially if the cache is cleared (also
> in other processes). Currently, I use str / S and do not clear the cache.
> Note: I removed all assumptions from my symbols. Find some test output and
> script below.
>
> 1. Are there better options than this to transfer such expressions to other
> processes?
You could try to get around the pickling issues by writing a custom
pickler. See for example
https://code.google.com/p/sympy/issues/detail?id=2587 and associated
pull request
https://github.com/sympy/sympy-live/pull/46. I don't
know what would be required to make this work for Functions. There
might be some hints at
https://code.google.com/p/sympy/issues/detail?id=1198, which explains
why it doesn't work. Actually, there's a trick in that issue that
works some of the time, but not all of the time (setting __module__).
You could see if that works for you.
Or we could try to actually fix the problem and rewrite Function in a
way that is pickable already.
> 2. Is it intended that clearing the cache has this effect?
No, that's a bug.
If you turn the cache off completely, you get False for everything. I
think the core of the issue is
https://code.google.com/p/sympy/issues/detail?id=1612 (and related
issue 440).
Actually, my old fix at seems to work (with it, your script gives all
True). I created a pull request with the fix at
https://github.com/sympy/sympy/pull/1710. We'll see if there are
issues still.
> 3. Did the 0.7.1 version have some problem with srepr ?
It wasn't an issue with srepr(), which returned the same thing. The
issues are are with the subtleties of how __eq__ works in the core.
Anyway, let's not worry about 0.7.1. That was released over a year
ago, and we have a hard enough time managing the bugs that are
current.
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to
sy...@googlegroups.com.
> To unsubscribe from this group, send email to
>
sympy+un...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/sympy?hl=en.
>