Use auto diff to get at jacobian of deflection angles#206
Merged
CKrawczyk merged 1 commit intofeature/jax_wrapperfrom Oct 25, 2024
Merged
Use auto diff to get at jacobian of deflection angles#206CKrawczyk merged 1 commit intofeature/jax_wrapperfrom
CKrawczyk merged 1 commit intofeature/jax_wrapperfrom
Conversation
These changes add the ability to use JAX to find the jacobian of deflection angles. To do this it first needs a version of the deflection angle function that takes in two scalars and returns a 2 element vector. From this `jax.jacfwd` is used to get the 2x2 jacobian for a single (y,x) value. This function is vectorized to take in a set of (y,x) values (of arbitrary shape) and return a (*shape, 2, 2) array of jacobian values. The final step is to pass the value from a `grid` object into this function.
rhayes777
approved these changes
Oct 25, 2024
Comment on lines
+730
to
+731
| if not use_jax: | ||
| return |
Collaborator
There was a problem hiding this comment.
Should this ever get called if jax is off?
Collaborator
Author
There was a problem hiding this comment.
I don't expect it to, but figured just to be safe.
Collaborator
There was a problem hiding this comment.
Might be worth raising an exception instead?
Collaborator
There was a problem hiding this comment.
Something like:
if not use_jax:
raise AssertionError("Function should not be called unless JAX is in use")
return ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These changes add the ability to use JAX to find the jacobian of deflection angles. To do this it first needs a version of the deflection angle function that takes in two scalars and returns a 2 element vector. From this
jax.jacfwdis used to get the 2x2 jacobian for a single (y,x) value. This function is vectorized to take in a set of (y,x) values (of arbitrary shape) and return a (*shape, 2, 2) array of jacobian values.The final step is to pass the value from a
gridobject into this function.