You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gh-1077: Spherical hard switch using S2FFT - #1232
This allows users to use glass.harmonics.transform and glass.harmonics.inverse_transform with either healpy or s2fft inputs. S2FFT depends on JAX necessary so I have created an optional dependency group jax that includes both. I've added some tests to check the values are consistent between healpy and s2fft for NumPy inputs. I've also added a test to check what happens if S2FFT isn't installed.
Added: JAX-native scalar and spin spherical harmonic transforms
Added: A glass[jax] install extra
Changed: nside is now mandatory in glass.harmonics.transform
Checks
Is your code passing linting?
Is your code passing tests?
Have you added additional tests (if required)?
Have you modified/extended the documentation (if required)?
Have you added a one-liner changelog entry above (if required)?
The reason will be displayed to describe this comment to others. Learn more.
The rationale for this is method="healpix_jax" with sampling="healpy" wraps healpy and so matches the default used there while the support for iter in the numpy and jax methods was only added latterly and so the original default behaviour of using no iterative refinement was retained when iter support was added for these methods. It could make sense to make a breaking change and default to iter = 3 for sampling = "healpix" with any method though.
JAX forward transform fails when lmax is below 2*nside
glass/harmonics.py:146
S2FFT also enforces L >= 2 * nside for the forward HEALPix transform, but this path passes lmax + 1 unchanged. Therefore valid calls such as from_convergence(..., lmax=8) at nside=32 work with NumPy but fail with an assertion for JAX. Mirror the inverse path by transforming at an effective bandlimit of at least 2 * nside, then crop the 2-D coefficients back to the requested bandlimit before packing them.
Derive NSIDE from shape instead of converting JAX arrays to NumPy
glass/lensing.py:297
Before reaching this JAX transform, hp.get_nside(kappa) uses numpy_fallback, which calls np.asarray(kappa). That copies the entire device map to the host in eager execution and raises a tracer-conversion error under jax.jit, so even the potential-only path is not fully GPU-resident or traceable. NSIDE can be derived from the static map shape without converting the array.
Use a backend-native spin transform for JAX deflection and shear
glass/lensing.py:330
The deflection path still reaches hp.alm2map_spin at line 334 (and the shear path at line 357); its numpy_fallback converts these JAX coefficients to NumPy and performs the transform on the CPU. Thus the full lensing workflow requested by #1077 remains GPU-incompatible whenever deflection or shear is requested. A backend-native spin inverse transform is needed before this issue can be considered closed.
Document transform and inverse_transform in the harmonics API
glass/harmonics.py:56
This new public wrapper (and transform) is absent from docs/modules/harmonics.rst, whose API reference still lists only multalm. Add both transform functions there so the feature introduced by this PR appears in the generated user documentation.
The reason will be displayed to describe this comment to others. Learn more.
I had this wonder too. The question is whether there is much point or benefit? For array_api_strict and jax we're actually doing something. We wouldn't need to configure NumPy at all. Like even pytest.importorskip is unnecessary at the moment as NumPy is always required.
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
array-apiWork is related to the Array APIdependenciesPull requests that update a dependency fileenhancementNew feature or requestinfrastructureProject infrastructure: dev tools, packaging, etc.jax-portingRemoving mutation to make the code JAX compatibleneeds-2-reviewersCould be considered "controversial" so worth a second pair of eyesperformancePerformance improvements or regressionsspherical-transformChanged related to spherical transforms, i.e. HEALPix
5 participants
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.
Description
This allows users to use
glass.harmonics.transformandglass.harmonics.inverse_transformwith eitherhealpyors2fftinputs. S2FFT depends on JAX necessary so I have created an optional dependency groupjaxthat includes both. I've added some tests to check the values are consistent betweenhealpyands2fftfor NumPy inputs. I've also added a test to check what happens if S2FFT isn't installed.Currently blocked because S2FFT isn't working on3.13/3.14, see astro-informatics/s2fft#413.Closes: #1077
Changelog entry
Added: JAX-native scalar and spin spherical harmonic transforms
Added: A
glass[jax]install extraChanged:
nsideis now mandatory inglass.harmonics.transformChecks