-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigate human-readable serialization for SymPy expressions #20
Comments
That would be super cool if it is also possible to serialized the undone-exressions. the full expression is
where
where
The fully substituted expression is this
|
Let's chat about it at the next opportunity, I am curious to learn some SymPy tree manipulations, serialization/deserialization from you. It would be cool to have the cached expressions in json (expect relatively nice diffs) |
String serialization with The time of the serialization is also ok. With an example I just tried, it started exciting 0.5s at the length of the string ![]() |
Thanks for reporting! Nice that it also contains the symbol definitions, and indeed assumptions are stored as well: >>> import sympy as sp
>>> x, y = sp.symbols('x y', real=True)
>>> n = sp.symbols('n', integer=True)
>>> expr = x**2 + y*n
>>> sp.srepr(expr)
"Add(Mul(Symbol('n', integer=True), Symbol('y', real=True)), Pow(Symbol('x', real=True), Integer(2)))" As a side note to #20 (comment), >>> type(sp.srepr).__mro__
(<class 'sympy.printing.printer.srepr_PrintFunction'>, <class 'sympy.printing.printer._PrintFunction'>, <class 'object'>) So it may be possible to inject that class to other printer mechanisms that support |
great note. |
That would be more complicated with the existing mechanisms that SymPy offers, it seems. Dumping is easy, but for parsing, you need to know where to load the class definition from. For #20 (comment) this works fine, because it is just built up of fundamental mathematical operations that are defined within the >>> src = sp.srepr(expr)
>>> from sympy import *
>>> eval(src)
n*y + x**2 Theoretically, you could dump the entire class definition of these 'folded' expressions, but at that stage you may better just run the entire program 😅 |
Nonetheless, the Of course, it is not ideal, JSON would be better, but surprisingly I could not find the tree-like serialization format. Could you please check if the entire Lc2pKpi model can be saved as a string? |
See #319. I also tried from sympy.parsing.sympy_parser import T, stringify_expr
local_dict = {}
global_dict = {}
src = stringify_expr(
unfolded_intensity_expr,
local_dict,
global_dict,
transformations=T,
) but got
so I'm misunderstanding something here. Feeding the result of |
Goals:
pickle
)pickle
)The text was updated successfully, but these errors were encountered: