-
Notifications
You must be signed in to change notification settings - Fork 8
fix: ensure moffat derivs are not nan and increase performance for trunc=0
#188
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bb69aa4
fix: ensure moffat derivs are not nan
beckermr fbe4dac
Update bessel.py
beckermr 7ef38d4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ea7bde8
fix: do not use lazy property
beckermr 0a02281
fix: ensure tests pass by having enough k range and tons of points
beckermr 2d7b9bf
fix: match the maxk for truncation in other parts of the code
beckermr e1be276
fix: do not cap this
beckermr aa433e4
Merge branch 'debug-moffat-perf' of https://github.com/GalSim-develop…
beckermr a5e799e
fix: get right fudge factor
beckermr 33f12a6
fix: adjust tests again
beckermr 68d4334
feat: use aymptotic expansion with untruncated profiles
beckermr 8db2728
fix: use slope properly
beckermr be849d3
fix: nan derivs needs mask at k=0
beckermr 51421d7
fix: wrong way to truncate
beckermr 3b4cf52
fix: wrong value at k = 0
beckermr 55b08b1
fix: only use interp for untraced profiles
beckermr 0fc251d
perf: use fewer points
beckermr 99df4fc
fix: enable derivs for moffats with truncation
beckermr ecba9da
fix: performance regression for moffat init and test derivs with trunc
beckermr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import jax | ||
| import jax.numpy as jnp | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| import jax_galsim as jgs | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "params,gsobj,args", | ||
| [ | ||
| (["scale_radius", "half_light_radius"], jgs.Spergel, [1.0]), | ||
| (["scale_radius", "half_light_radius"], jgs.Exponential, []), | ||
| (["sigma", "fwhm", "half_light_radius"], jgs.Gaussian, []), | ||
| (["scale_radius", "half_light_radius", "fwhm"], jgs.Moffat, [2.0]), | ||
| ], | ||
| ) | ||
| def test_deriv_params_gsobject(params, gsobj, args): | ||
| val = 2.0 | ||
| eps = 1e-5 | ||
|
|
||
| for param in params: | ||
| print("\nparam:", param, flush=True) | ||
|
|
||
| def _run(val_): | ||
| kwargs = {param: val_} | ||
| return jnp.max( | ||
| gsobj( | ||
| *args, | ||
| **kwargs, | ||
| gsparams=jgs.GSParams(minimum_fft_size=64, maximum_fft_size=64), | ||
| ) | ||
| .drawImage(nx=48, ny=48, scale=0.2) | ||
| .array[24, 24] | ||
| ** 2 | ||
| ) | ||
|
|
||
| gfunc = jax.jit(jax.grad(_run)) | ||
| gval = gfunc(val) | ||
|
|
||
| gfdiff = (_run(val + eps) - _run(val - eps)) / 2.0 / eps | ||
|
|
||
| np.testing.assert_allclose(gval, gfdiff, rtol=0, atol=1e-6) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.