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
Add better interaction with and export to sympy, and uses sympy to implement more Hessian functions #191
Conversation
cc @smoh - this finally fixes some of the Hessian issues you were having (...last year 😶) |
Before merging, make an issue to remind me to figure out how to implement |
Cool! Yea, I never got around to that.. That's a lot of tmps! 😅 Wouldn't it be neat if we could generate gradient funcs from sympy expression! |
Heh, yea...at least they were auto-generated! 😄
Do you mean in the same way that I generated the hessians, or you want to be able to create a potential class from an arbitrary sympy expression? |
Oh, cool -- I missed this comment
If you are autogenerating the C code from sympy, I guess you are already kind of doing it! Looking at it again, probably no sane person can stay on top of doing that by hand..! And I see that you are comparing to the function generated using sympy's lambdify. I meant something like an integration with sympy's lambdify so that people can define e.g., potential by a symbolic expression, and any gradients would follow from sympy, too. I'm actually curious how it was done in the notebook, which seems to be not available anywhere, specifically how you figured out the common factors to store in tmp variables. Is it a functionality sympy offers?
|
Oh yea, that's a good idea! It would be a lot slower (unless I can figure out a way to combine with numba) but that would be cool. There's some limited support for this already, actually, but it could use some cleaning! https://gala-astro.readthedocs.io/en/latest/api/gala.potential.potential.from_equation.html#gala.potential.potential.from_equation
It's a bit of a mess, but here it is: https://gist.github.com/e1aa71fbb11167d6109fb7077020d630 |
Thanks! That's pretty cool. |
Describe your changes
This adds a
.to_sympy()
classmethod to the potential classes. I've also then used this method with sympy to compute all of the Hessians, and implemented these using C code generated by sympy.Checklist
CHANGES.rst
)Amazingly, this closes #159, closes #56, closes #5, and closes #85 !!