Closed tjstienstra closed 3 months ago
A quick "fix" is to add in the documentation that symbols should be representable in C via SymPy's printers. This is really a SymPy issue, not opty, right? The CCodePrinter should be made to handle these symbols.
I would indeed expect that it should be solved within sympy, but I still have to check where this should exactly be handled. Lambdify does work, at least for the numpy module.
This is a related sympy issue: https://github.com/sympy/sympy/issues/7767
Also related (suggested fix for all printers to handle the curly braces in symbol names). https://github.com/sympy/sympy/issues/23374
A quick "fix" is to add in the documentation that symbols should be representable in C via SymPy's printers. This is really a SymPy issue, not opty, right? The CCodePrinter should be made to handle these symbols. At least for someone like me, totally ignorant of C (or of anything other than Python), this would not have helped me much. Maybe better to list what is not allowed, e.g. curly brackets {} ?
Maybe better to list what is not allowed, e.g. curly brackets {} ?
It isn't as simple as listing that curly braces are not allowed because there are many characters and even symbol names that are not allowed. The documentation for opty shouldn't have to explain anything about SymPy's C code printers. It is best to fix this in SymPy. We could catch the error and report to the opty user "Something has gone wrong in SymPy C code generation", but that also isn't so simple.
You can see that we do catch the reserved words in C:
https://github.com/sympy/sympy/blob/d2be7bacd2604e98a642f74028e8f0d7d6084f78/sympy/printing/c.py#L81
These seem to be the rules in C:
Also: The length of the variable name can be up to 31 characters.
Clearer now, thanks! Does the sympy C printer 'translate' sympy code into code that C understands, similar to sm.lambdify(..) for python / numpy?
I opened this: https://github.com/sympy/sympy/pull/26360 as a possible fix.
Does the sympy C printer 'translate' sympy code into code that C understands, similar to sm.lambdify(..) for python / numpy?
Yes.
Thanks!
The PR in SymPy was merged, so opty user will get a value error if bad symbols are provided when using SymPy >= 1.13.
So my playing around with opty improved it! :-)
Yes, I think we've fixed at least three things you've brought up. We just have to figure out how to teach you to fix these things yourself :)
Knowing my (lack of) computer skills, this may well be mission impossible! :-)
As
ufuncify_matrix
uses the string representation of each symbol when creating the c code, it actually fails when one uses curly brackets in the string representation. Below is a minimal reproducer.This results in the following ufuncify compile files that fail to compile as they use variables like
f_{ext}
.