https://github.com/askabalan/s2fft
Differentiable and accelerated spherical transforms with JAX
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: arxiv.org, sciencedirect.com, springer.com -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.7%) to scientific vocabulary
Last synced: 10 months ago
·
JSON representation
Repository
Differentiable and accelerated spherical transforms with JAX
Basic Info
- Host: GitHub
- Owner: ASKabalan
- License: mit
- Default Branch: main
- Homepage: https://astro-informatics.github.io/s2fft
- Size: 44.5 MB
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 0
Fork of astro-informatics/s2fft
Created over 2 years ago
· Last pushed about 2 years ago
https://github.com/ASKabalan/s2fft/blob/main/
[](https://github.com/astro-informatics/s2fft/actions/workflows/tests.yml) [](https://codecov.io/gh/astro-informatics/s2fft) [](https://opensource.org/licenses/MIT) [](https://badge.fury.io/py/s2fft) [](https://arxiv.org/abs/2311.14670) [](#contributors-) [](https://colab.research.google.com/drive/1YmJ2ljsF8HBvhPmD4hrYPlyAKc4WPUgq?usp=sharing)# Differentiable and accelerated spherical transforms `S2FFT` is a Python package for computing Fourier transforms on the sphere and rotation group [(Price & McEwen 2023)](https://arxiv.org/abs/2311.14670) using JAX or PyTorch. It leverages autodiff to provide differentiable transforms, which are also deployable on hardware accelerators (e.g. GPUs and TPUs). More specifically, `S2FFT` provides support for spin spherical harmonic and Wigner transforms (for both real and complex signals), with support for adjoint transformations where needed, and comes with different optimisations (precompute or not) that one may select depending on available resources and desired angular resolution $L$. As of version 1.0.2 `S2FFT` also provides PyTorch implementations of underlying precompute transforms. In future releases this support will be extended to our on-the-fly algorithms. ## Algorithms :zap: `S2FFT` leverages new algorithmic structures that can he highly parallelised and distributed, and so map very well onto the architecture of hardware accelerators (i.e. GPUs and TPUs). In particular, these algorithms are based on new Wigner-d recursions that are stable to high angular resolution $L$. The diagram below illustrates the recursions (for further details see Price & McEwen, in prep.).  With this recursion to hand, the spherical harmonic coefficients of an isolatitudinally sampled map may be computed as a two step process. First, a 1D Fourier transform over longitude, for each latitudinal ring. Second, a projection onto the real polar-d functions. One may precompute and store all real polar-d functions for extreme acceleration, however this comes with an equally extreme memory overhead, which is infeasible at L ~ 1024. Alternatively, the real polar-d functions may calculated recursively, computing only a portion of the projection at a time, hence incurring negligible memory overhead at the cost of slightly slower execution. The diagram below illustrates the separable spherical harmonic transform (for further details see Price & McEwen, in prep.).  ## Sampling :earth_africa: The structure of the algorithms implemented in `S2FFT` can support any isolattitude sampling scheme. A number of sampling schemes are currently supported. The equiangular sampling schemes of [McEwen & Wiaux (2012)](https://arxiv.org/abs/1110.6298), [Driscoll & Healy (1995)](https://www.sciencedirect.com/science/article/pii/S0196885884710086) and [Gauss-Legendre (1986)](https://link.springer.com/article/10.1007/BF02519350) are supported, which exhibit associated sampling theorems and so harmonic transforms can be computed to machine precision. Note that the McEwen & Wiaux sampling theorem reduces the Nyquist rate on the sphere by a factor of two compared to the Driscoll & Healy approach, halving the number of spherical samples required. The popular [HEALPix](https://healpix.jpl.nasa.gov) sampling scheme ([Gorski et al. 2005](https://arxiv.org/abs/astro-ph/0409513)) is also supported. The HEALPix sampling does not exhibit a sampling theorem and so the corresponding harmonic transforms do not achieve machine precision but exhibit some error. However, the HEALPix sampling provides pixels of equal areas, which has many practical advantages.
> [!NOTE] > For algorithmic reasons JIT compilation of HEALPix transforms can become slow at high bandlimits, due to XLA unfolding of loops which currently cannot be avoided. After compiling HEALPix transforms should execute with the efficiency outlined in the associated paper, therefore this additional time overhead need only be incurred once. We are aware of this issue and will work to improve this in subsequent versions. ## Installation :computer: The Python dependencies for the `S2FFT` package are listed in the file `requirements/requirements-core.txt` and will be automatically installed into the active python environment by [pip](https://pypi.org) when running ``` bash pip install s2fft ``` This will install all core functionality which includes JAX support. To install `S2FFT` with PyTorch support run ``` bash pip install s2fft[torch] ``` Alternatively, the `S2FFT` package may be installed directly from GitHub by cloning this repository and then running ``` bash pip install . ``` from the root directory of the repository. To enable PyTorch support you will need to run ``` bash pip install .[torch] ``` Unit tests can then be executed to ensure the installation was successful by running ``` bash pytest tests/ ``` > [!NOTE] > For plotting functionality which can be found throughout our various notebooks, one must install the requirements which can be found in `requirements/requirements-plotting.txt`. ## Usage :rocket: To import and use `S2FFT` is as simple follows: For a signal on the sphere ``` python # Compute harmonic coefficients flm = s2fft.forward_jax(f, L) # Map back to pixel-space signal f = s2fft.inverse_jax(flm, L) ``` For a signal on the rotation group ``` python # Compute Wigner coefficients flmn = s2fft.wigner.forward_jax(f, L, N) # Map back to pixel-space signal f = fft.wigner.inverse_jax(flmn, L, N) ``` For further details on usage see the [documentation](https://astro-informatics.github.io/s2fft/) and associated [notebooks](https://astro-informatics.github.io/s2fft/tutorials/spherical_harmonic/spherical_harmonic_transform.html). > [!NOTE] > We also provide PyTorch support for the precompute version of our transforms. These are called through forward/inverse_torch(). Full PyTorch support will be provided in future releases. ## Benchmarking :hourglass_flowing_sand: We benchmarked the spherical harmonic and Wigner transforms implemented in `S2FFT` against the C implementations in the [SSHT](https://github.com/astro-informatics/ssht) package. A brief summary is shown in the table below for the recursion (left) and precompute (right) algorithms, with `S2FFT` running on GPUs (for further details see Price & McEwen, in prep.). Note that our compute time is agnostic to spin number (which is not the case for many other methods that scale linearly with spin). | L | Wall-Time | Speed-up | Error | Wall-Time | Speed-up | Error | Memory | |------|-----------|----------|----------|-----------|----------|----------|---------| | 64 | 3.6 ms | 0.88 | 1.81E-15 | 52.4 s | 60.5 | 1.67E-15 | 4.2 MB | | 128 | 7.26 ms | 1.80 | 3.32E-15 | 162 s | 80.5 | 3.64E-15 | 33 MB | | 256 | 17.3 ms | 6.32 | 6.66E-15 | 669 s | 163 | 6.74E-15 | 268 MB | | 512 | 58.3 ms | 11.4 | 1.43E-14 | 3.6 ms | 184 | 1.37E-14 | 2.14 GB | | 1024 | 194 ms | 32.9 | 2.69E-14 | 32.6 ms | 195 | 2.47E-14 | 17.1 GB | | 2048 | 1.44 s | 49.7 | 5.17E-14 | N/A | N/A | N/A | N/A | | 4096 | 8.48 s | 133.9 | 1.06E-13 | N/A | N/A | N/A | N/A | | 8192 | 82 s | 110.8 | 2.14E-13 | N/A | N/A | N/A | N/A | where the left hand results are for the recursive based algorithm and the right hand side are our precompute implementation. ## Contributors Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Matt Price |
Jason McEwen |
Matt Graham |
sfmig |
Devaraj Gopinathan |
Francois Lanusse |
Ikko Eltociear Ashimine |
Kevin Mulder |
Philipp Misof |
Owner
- Name: Wassim KABALAN
- Login: ASKabalan
- Kind: user
- Location: Paris
- Company: Dassault Systèmes
- Repositories: 2
- Profile: https://github.com/ASKabalan
# Differentiable and accelerated spherical transforms
`S2FFT` is a Python package for computing Fourier transforms on the sphere
and rotation group [(Price & McEwen 2023)](https://arxiv.org/abs/2311.14670) using
JAX or PyTorch. It leverages autodiff to provide differentiable transforms, which are
also deployable on hardware accelerators (e.g. GPUs and TPUs).
More specifically, `S2FFT` provides support for spin spherical harmonic
and Wigner transforms (for both real and complex signals), with support
for adjoint transformations where needed, and comes with different
optimisations (precompute or not) that one may select depending on
available resources and desired angular resolution $L$.
As of version 1.0.2 `S2FFT` also provides PyTorch implementations of underlying
precompute transforms. In future releases this support will be extended to our
on-the-fly algorithms.
## Algorithms :zap:
`S2FFT` leverages new algorithmic structures that can he highly
parallelised and distributed, and so map very well onto the architecture
of hardware accelerators (i.e. GPUs and TPUs). In particular, these
algorithms are based on new Wigner-d recursions that are stable to high
angular resolution $L$. The diagram below illustrates the recursions
(for further details see Price & McEwen, in prep.).

With this recursion to hand, the spherical harmonic coefficients of an
isolatitudinally sampled map may be computed as a two step process. First,
a 1D Fourier transform over longitude, for each latitudinal ring. Second,
a projection onto the real polar-d functions. One may precompute and store
all real polar-d functions for extreme acceleration, however this comes
with an equally extreme memory overhead, which is infeasible at L ~ 1024.
Alternatively, the real polar-d functions may calculated recursively,
computing only a portion of the projection at a time, hence incurring
negligible memory overhead at the cost of slightly slower execution. The
diagram below illustrates the separable spherical harmonic transform
(for further details see Price & McEwen, in prep.).

## Sampling :earth_africa:
The structure of the algorithms implemented in `S2FFT` can support any
isolattitude sampling scheme. A number of sampling schemes are currently
supported.
The equiangular sampling schemes of [McEwen & Wiaux
(2012)](https://arxiv.org/abs/1110.6298), [Driscoll & Healy
(1995)](https://www.sciencedirect.com/science/article/pii/S0196885884710086)
and [Gauss-Legendre (1986)](https://link.springer.com/article/10.1007/BF02519350)
are supported, which exhibit associated sampling theorems and so
harmonic transforms can be computed to machine precision. Note that the
McEwen & Wiaux sampling theorem reduces the Nyquist rate on the sphere
by a factor of two compared to the Driscoll & Healy approach, halving
the number of spherical samples required.
The popular [HEALPix](https://healpix.jpl.nasa.gov) sampling scheme
([Gorski et al. 2005](https://arxiv.org/abs/astro-ph/0409513)) is also
supported. The HEALPix sampling does not exhibit a sampling theorem and
so the corresponding harmonic transforms do not achieve machine
precision but exhibit some error. However, the HEALPix sampling provides
pixels of equal areas, which has many practical advantages.
