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

TST fix tests for JAX-Galsim #1252

Open
wants to merge 358 commits into
base: main
Choose a base branch
from
Open

TST fix tests for JAX-Galsim #1252

wants to merge 358 commits into from

Conversation

beckermr
Copy link
Contributor

@beckermr beckermr commented Oct 15, 2023

This PR has two main features:

  1. It has a generalization of the concept of a "galsim backend" with associated functions for the test suite only. In the test suite only, the backend is used to adjust the tests as needed for the jax-based galsim implementation.

  2. It has adjustments of the tests for jax-galsim. Most of them are related to cases where jax cannot raise the same errors (e.g., for checking argument types) or when the fact that jax arrays cannot be changed in place causes the APIs to differ.

@beckermr
Copy link
Contributor Author

The commits here need to be rebased onto main I think.

setup.py Outdated Show resolved Hide resolved
@beckermr beckermr marked this pull request as ready for review August 26, 2024 20:54
@beckermr beckermr requested a review from rmjarvis August 26, 2024 20:59
@beckermr
Copy link
Contributor Author

ok @rmjarvis This giant PR is ready for review. I can break it up into smaller PRs if that would help. My hope is that with this PR, we can run jax-galsim tests against the main branch going forward.

np.testing.assert_almost_equal(neg_image.array/prof.flux, -image.array/prof.flux, 7,
'%s negative flux drawReal is not negative of +flux image'%name)
np.testing.assert_array_almost_equal(neg_image.array/prof.flux, -image.array/prof.flux, 7,
'%s negative flux drawReal is not negative of +flux image'%name)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? I thought they were equivalent. I'd rather not use the more verbose one if we can avoid it.

@@ -298,6 +371,9 @@ def do_shoot(prof, img, name):
print('nphot = ',nphot)
img2 = img.copy()

if is_jax_galsim():
rtol *= 3
Copy link
Member

Choose a reason for hiding this comment

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

Is this a sign of a problem with the jax-galsim implementation?

assert_raises(TypeError,galsim.AngleUnit, 1, 3)
assert_raises(TypeError,galsim.Angle, 3.4)
assert_raises(TypeError,galsim.Angle, theta1, galsim.degrees)
assert_raises(ValueError,galsim.Angle, 'spam', galsim.degrees)
assert_raises((ValueError, TypeError), galsim.Angle, 'spam')
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should remove the last arg, galsim.degrees.

(0.0, 0.0),
rtol=0,
atol=1e-16,
)
Copy link
Member

Choose a reason for hiding this comment

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

What computation are you doing in Jax-Galsim that makes this not be exactly zero. This should have been trivially true I would think

Copy link
Member

Choose a reason for hiding this comment

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

Also, the line bloat here seems rather gratuitous. Can we put each of these in a single line?

else:
check_dep(galsim.GSParams, allowed_flux_variation=0.90)
check_dep(galsim.GSParams, range_division_for_extrema=50)
check_dep(galsim.GSParams, small_fraction_of_flux=1.e-6)
Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I think there is no reason that JAX-GalSim needs to comport with our now-deprecated behavior. I'd be happy to just have:

if is_jax_galsim(): return

at the start of every test in this file.

assert_raises(ValueError, galsim.BoundsD, 11, 23, 17, "blue")
if is_jax_galsim():
# jax doesn't raise for this
pass
Copy link
Member

Choose a reason for hiding this comment

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

I think I can guess what it does with floats. But I'm quite curious what it does with "blue".


if is_jax_galsim():
# jax doesn't raise for these things
pass
Copy link
Member

Choose a reason for hiding this comment

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

What does it do for an undefined Bounds if you ask for the center?

im_list, offsets = deInterleaveImage(img,8)
img1 = interleaveImages(im_list,8,offsets)
im_list, offsets = galsim.utilities.deInterleaveImage(img,8)
img1 = galsim.utilities.interleaveImages(im_list,8,offsets)
Copy link
Member

Choose a reason for hiding this comment

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

This is fine I guess, but I'm curious why this was required?

@@ -499,7 +500,7 @@ def do_local_wcs(wcs, ufunc, vfunc, name):
wcs2 = wcs.local()
assert wcs == wcs2, name+' local() is not == the original'
new_origin = galsim.PositionI(123,321)
wcs3 = wcs.withOrigin(new_origin)
wcs3 = wcs.shiftOrigin(new_origin)
Copy link
Member

Choose a reason for hiding this comment

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

For a LocalWCS, these are equivalent. And IMO withOrigin is preferred, since the WCS doesn't have an origin yet.

@@ -41,10 +40,10 @@ def test_Zernike_orthonormality():
y = y[w].ravel()
area = np.pi*R_outer**2
for j1 in range(1, jmax+1):
Z1 = Zernike([0]*(j1+1)+[1], R_outer=R_outer)
Z1 = galsim.zernike.Zernike([0]*(j1+1)+[1], R_outer=R_outer)
Copy link
Member

Choose a reason for hiding this comment

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

Again, why add the extra boilerplate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Non-functional changes to make the code better tests Related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants