Skip to content
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 numerical constants pi, e, Euler's gamma, and imaginary I #12

Merged
merged 4 commits into from
Oct 21, 2023

Conversation

denehoffman
Copy link
Contributor

Addresses #6 and adds some other nice constants. For example, you should now be able to run the following without error:

import sympy
import sympy2jax
theta, phi = sympy.symbols("theta phi")
y22 = sympy.Ynm(2, 2, theta, phi).expand(func=True)
mod = sympy2jax.SymbolicModule(y22)
mod(theta=0.1, phi=0.2)
# returns Array(0.00354597+0.00149921j, dtype=complex64, weak_type=True), which is the correct result for this spherical harmonic function
mod.sympy()
# returns: -sqrt(30)*exp(2*I*phi)*cos(theta)**2/(8*sqrt(pi)) + sqrt(30) *exp(2*I*phi)/(8*sqrt(pi))

I've also written a unit test for these constants, although I had to use jnp.isclose rather than == I believe because of some type conversions. If someone knows how to make this nicer, please do so!

@google-cla
Copy link

google-cla bot commented Oct 21, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Owner

@patrick-kidger patrick-kidger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits aside, this LGTM.

The CI failure looks a little odd, I think that's unrelated. Let me see if I can fix that.

sympy2jax/sympy_module.py Outdated Show resolved Hide resolved
sympy2jax/sympy_module.py Outdated Show resolved Hide resolved
@denehoffman
Copy link
Contributor Author

denehoffman commented Oct 21, 2023

The CI failure looks a little odd, I think that's unrelated. Let me see if I can fix that.

From a quick search, I believe changing isort 5.10.1 to a newer version might fix this (source)

see also: https://github.com/PyCQA/isort/releases/tag/5.11.5

@patrick-kidger
Copy link
Owner

Alright, try rebasing on top of the new main and I think the CI should be fixed. :)

@denehoffman
Copy link
Contributor Author

denehoffman commented Oct 21, 2023

@patrick-kidger nice (love the switch to ruff and pyproject.toml btw)! Okay, I've updated my PR with the changes you mentioned, let me know how it looks.

update: oops, not sure why the pre-commit didn't do the formatting but I've run black on it now so it should pass this time.

@patrick-kidger patrick-kidger merged commit afca2fe into patrick-kidger:main Oct 21, 2023
2 checks passed
@patrick-kidger
Copy link
Owner

Marvellous! Just merged.
I'll do a new release with this now.

@denehoffman
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants