-
Notifications
You must be signed in to change notification settings - Fork 20
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
Problems with sympy.pi in the equations of motion #257
Comments
Here is a minimal reproducer of the issue: import sympy as sm
import numpy as np
from opty.utils import ufuncify_matrix
x, y = sm.symbols("x y")
result, x_vals, y_vals = np.empty((1, 2)), np.array([1.0]), np.array([2.0])
expected = np.array([[1.0, 6.283185307179586]])
f_np = ufuncify_matrix((x, y), sm.Matrix([x, np.pi * y])) # works fine
f_np(result, x_vals, y_vals)
np.testing.assert_allclose(result, expected)
f_sm = ufuncify_matrix((x, y), sm.Matrix([x, sm.pi * y])) # crashes due to a compilation error
f_sm(x_vals, y_vals, result)
np.testing.assert_allclose(result, expected) |
When I run Timo's example on Linux I get this error:
|
I vaguely recall, that my example above (or rather something similar) did not give an error witth Linux, only with windows - but maybe my memory is wrong. |
When I run Timo's example, I get this error:
|
That error just tells you that it didn't compile. You have to compile it manually to show what the actual compilation error is. |
|
I think this issue has already been raised before. |
You opened the same issue on PyDy: pydy/pydy#499 Timo gives the fix there. I suspect it is the same here. It seems that on Windows math constants are not available by default, as they are on linux. |
From https://stackoverflow.com/a/26065595:
|
Also see this note in SymPy's C printer: https://github.com/sympy/sympy/blob/d293133e81194adc11177729af91c970f092a6e7/sympy/printing/c.py#L94 |
I vaguely remembered that I had raised it before. |
This morning I ran into a problem using opty for a simulation (Example 10.59 from Betts' book)
With the help from @tjstienstra I found the problem was that I used sympy.pi in the equations of motion. Replacing it with numpy.pi solved the problem.
Here I think, one can see that opty objects to sympy.pi:
in the simulation below, I added a factor sympy.cos(symypy.pi) / sympy.cos(numpy.pi) and sympy.pi / numpy.py, in lines 37, 38.
For some reason, it accepts sympy.cos(sympy.pi), but not sympy.pi alone.
NB:
The text was updated successfully, but these errors were encountered: