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?
2. Is it intended that clearing the cache has this effect?
3. Did the 0.7.1 version have some problem with srepr ?

Thanks and kind regards,
Vinzenz
------------------------------------------------------------------------
:~> python3.2 sympy_strrepr_test.py
Version:  0.7.1-git
srepr(x):  Function('x')(Symbol('t'))
str(x):  x(t)
x==S(srepr(x)):  False
x==eval(srepr(x))):  False
x==S(str(x)):  True
x(t)
Clearing cache...
x(t)
x==S(srepr(x)):  False
x==eval(srepr(x))):  False
x==S(str(x)):  False
-------------------------------------------------------------------------
:~> python2.7 sympy_strrepr_test.py
Version:  0.7.2
srepr(x):  Function('x')(Symbol('t'))
str(x):  x(t)
x==S(srepr(x)):  True
x==eval(srepr(x))):  True
x==S(str(x)):  True
x(t)
Clearing cache...
x(t)
x==S(srepr(x)):  False
x==eval(srepr(x))):  False
x==S(str(x)):  False
-------------------------------------------------------------------------
:~> python2.7 sympy_strrepr_test.py
Version:  0.7.1-git
srepr(x):  Function('x')(Symbol('t'))
str(x):  x(t)
x==S(srepr(x)):  False
x==eval(srepr(x))):  False
x==S(str(x)):  True
x(t)
Clearing cache...
x(t)
x==S(srepr(x)):  False
x==eval(srepr(x))):  False
x==S(str(x)):  False
-------------------------------------------------------------------------


This is the script I use:
from __future__ import print_function
from sympy import *
from sympy import __version__ as sympyver
print("Version: ", sympyver)
x=S('x(t)')
print("srepr(x): ", srepr(x))
print("str(x): ", str(x))

print("x==S(srepr(x)): ",x==S(srepr(x)))
print("x==eval(srepr(x))): ",x==eval(srepr(x)))
print("x==S(str(x)): ",x==S(str(x)))
print(x)
print("Clearing cache...")
cache.clear_cache()
print(x)
print("x==S(srepr(x)): ",x==S(srepr(x)))
print("x==eval(srepr(x))): ",x==eval(srepr(x)))
print("x==S(str(x)): ",x==S(str(x)))


--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to