s2fft

S2FFT: Differentiable and accelerated spherical transforms

https://github.com/astro-informatics/s2fft

Science Score: 59.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org, sciencedirect.com, springer.com
  • Committers with academic emails
    2 of 12 committers (16.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.9%) to scientific vocabulary

Keywords

differentiable-programming fourier-transform jax pytorch recursion-algorithm spherical spherical-harmonics wigner-d-matrix wigner-transform

Keywords from Contributors

optimism agents automatic-differentiation battery optimizing-compiler transformers projects hacking cryptocurrencies sequencers
Last synced: 6 months ago · JSON representation

Repository

S2FFT: Differentiable and accelerated spherical transforms

Basic Info
Statistics
  • Stars: 202
  • Watchers: 10
  • Forks: 13
  • Open Issues: 48
  • Releases: 9
Topics
differentiable-programming fourier-transform jax pytorch recursion-algorithm spherical spherical-harmonics wigner-d-matrix wigner-transform
Created almost 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Citation

README.md

s2fft logo - schematic representation of a tiled sphere # S2FFT: differentiable and accelerated spherical transforms [![Tests status](https://github.com/astro-informatics/s2fft/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/astro-informatics/s2fft/actions/workflows/tests.yml) [![Linting status](https://github.com/astro-informatics/s2fft/actions/workflows/linting.yml/badge.svg?branch=main)](https://github.com/astro-informatics/s2fft/actions/workflows/linting.yml) [![Documentation status](https://github.com/astro-informatics/s2fft/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/astro-informatics/s2fft/actions/workflows/docs.yml) [![Codecov](https://codecov.io/gh/astro-informatics/s2fft/branch/main/graph/badge.svg?token=7QYAFAAWLE)](https://codecov.io/gh/astro-informatics/s2fft) [![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PyPI package](https://badge.fury.io/py/s2fft.svg)](https://badge.fury.io/py/s2fft) [![arXiv](http://img.shields.io/badge/arXiv-2311.14670-orange.svg?style=flat)](https://arxiv.org/abs/2311.14670) ![All Contributors](https://img.shields.io/github/all-contributors/astro-informatics/s2fft?color=ee8449&style=flat-square) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/astro-informatics/s2fft/blob/main/notebooks/spherical_harmonic_transform.ipynb) [![Linter](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

S2FFT is a Python package for computing Fourier transforms on the sphere and rotation group (Price & McEwen 2024) 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$.

Algorithms

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 2024).

Schematic of Wigner recursions

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 \sim 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 2024).

Schematic of forward and inverse spherical harmonic transforms

Sampling

The structure of the algorithms implemented in S2FFT can support any isolatitude sampling scheme. A number of sampling schemes are currently supported.

The equiangular sampling schemes of McEwen & Wiaux (2012), Driscoll & Healy (1995) and Gauss-Legendre (1986) 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 sampling scheme (Gorski et al. 2005) 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.

Visualization of spherical sampling schemes

[!NOTE] For algorithmic reasons JIT compilation of HEALPix transforms can become slow at high bandlimits, due to XLA unfolding of loops. After compilation, HEALPix transforms should execute with the efficiency outlined in the associated paper, therefore this additional time overhead need only be incurred once.

If running on a CPU, we provide (differentiable) JAX wrappers of the healpy transforms which can be used to sidestep the issue. This implementation can be selected by passing a method="jax_healpy" keyword argument to the s2fft.forward or s2fft.inverse functions - see example notebook.

If running on a GPU, a CUDA extension module is available which avoids the long compilation time. This implementation can be selected by passing a method="jax_cuda" keyword argument to the sfft.forward and s2fft.inverse functions. Currently we do not publish binary wheels with the CUDA extension support so you will need to build the package from source to use this functionality.

Installation

The latest release of S2FFT published on PyPI can be installed by running

bash pip install s2fft

This will install S2FFT's dependencies including JAX if not already installed. As by default installing JAX from PyPI will use a CPU-only build, if you wish to install JAX with GPU or TPU support, you should first follow the relevant installation instructions in JAX's documentation and then install S2FFT as above.

Alternatively, the latest development version of S2FFT may be installed directly from GitHub by running

bash pip install git+https://github.com/astro-informatics/s2fft

CUDA extension support

To install the package with support for the CUDA extension module giving reduced compile times for running HEALPix transforms on the GPU, you will need to build from source on a system with CUDA (tested with version 12.3) and CMake (versions 3.19+) installed.

To install the latest development version from source in verbose mode run

bash pip install -v git+https://github.com/astro-informatics/s2fft

or to install a specific release tag in verbose mode run

bash pip install -v git+https://github.com/astro-informatics/s2fft@TAG

where TAG is the relevant version tag. The output should indicate if the CUDA install on your system is successfully detected.

Tests

A pytest test suite for the package is included in the tests directory. To install the test dependencies, clone the repository and install the package (in editable mode) with the extra test dependencies by running from the root of the repository

bash pip install -e ".[tests]"

To run the tests, run from the root of the repository

bash pytest

Documentation

Documentation for the released version is available here. To install the documentation dependencies, clone the repository and install the package (in editable mode) with the extra documentation dependencies by running from the root of the repository

bash pip install -e ".[docs]"

To build the documentation, run from the root of the repository

bash cd docs make html open _build/html/index.html

Notebooks

A series of tutorial notebooks are included in the notebooks directory and rendered in the documentation.

To install the dependencies required to run the notebooks locally, clone the repository and install the package (in editable mode) with the extra documentation and plotting dependencies by running from the root of the repository

bash pip install -e ".[docs,plotting]"

To run the notebooks in Jupyter Lab, run from the root of the repository

bash jupyter lab

Usage

To import and use S2FFT is as simple follows:

For a signal on the sphere

```python import s2fft

Define sampled signal to transform and harmonic bandlimit

f = ... L = ...

Compute harmonic coefficients

flm = s2fft.forward(f, L, method="jax")

Map back to pixel-space signal

f = s2fft.inverse(flm, L, method="jax") ```

For a signal on the rotation group

```python import s2fft

Define sampled signal to transform and harmonic and azimuthal bandlimits

f = ... L = ... N = ...

Compute Wigner coefficients

flmn = s2fft.wigner.forward(f, L, N, method="jax")

Map back to pixel-space signal

f = fft.wigner.inverse_jax(flmn, L, N, method="jax") ```

For further details on usage see the documentation and associated notebooks.

We also provide PyTorch support for our transforms, as demonstrated in the Torch frontend tutorial notebook. This wraps the JAX implementations so JAX will need to be installed in addition to PyTorch.

SSHT & HEALPix wrappers

S2FFT also provides JAX support for existing C/C++ packages, specifically HEALPix and SSHT. This works by wrapping Python bindings with custom JAX frontends. Note that this C/C++ to JAX interoperability is currently limited to CPU.

For example, one may call these alternate backends for the spherical harmonic transform by:

``` python

Forward SSHT spherical harmonic transform

flm = s2fft.forward(f, L, sampling="mw", method="jax_ssht")

Forward HEALPix spherical harmonic transform

flm = s2fft.forward(f, L, nside=nside, sampling="healpix", method="jax_healpy") ```

All of these JAX frontends supports out of the box reverse mode automatic differentiation, and under the hood is simply linking to the C/C++ packages you are familiar with. In this way S2fft enhances existing packages with gradient functionality for modern scientific computing or machine learning applications!

For further details on usage see the associated notebooks.

Benchmarks

A suite of benchmark functions for both the on-the-fly and precompute versions of the spherical harmonic and Wigner transforms are available in the benchmarks directory, along with utilities for running the benchmarks and plotting the results.

Contributors

Thanks goes to these wonderful people (emoji key): <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable -->

Matt Price
Matt Price

Jason McEwen
Jason McEwen

Matt Graham
Matt Graham

sfmig
sfmig

Devaraj Gopinathan
Devaraj Gopinathan

Francois Lanusse
Francois Lanusse

Ikko Eltociear Ashimine
Ikko Eltociear Ashimine

Kevin Mulder
Kevin Mulder

Philipp Misof
Philipp Misof

Elis Roberts
Elis Roberts

Wassim KABALAN
Wassim KABALAN

Mayeul d'Avezac
Mayeul d'Avezac

We encourage contributions from any interested developers. A simple first addition could be adding support for more spherical sampling patterns!

Attribution

Should this code be used in any way, we kindly request that the following article is referenced. A BibTeX entry for this reference may look like:

@article{price:s2fft, author = "Matthew A. Price and Jason D. McEwen", title = "Differentiable and accelerated spherical harmonic and Wigner transforms", journal = "Journal of Computational Physics", year = "2024", volume = "510", pages = "113109", eprint = "arXiv:2311.14670", doi = "10.1016/j.jcp.2024.113109" }

You might also like to consider citing our related papers on which this code builds:

@article{mcewen:fssht, author = "Jason D. McEwen and Yves Wiaux", title = "A novel sampling theorem on the sphere", journal = "IEEE Trans. Sig. Proc.", year = "2011", volume = "59", number = "12", pages = "5876--5887", eprint = "arXiv:1110.6298", doi = "10.1109/TSP.2011.2166394" }

@article{mcewen:so3, author = "Jason D. McEwen and Martin B{\"u}ttner and Boris ~Leistedt and Hiranya V. Peiris and Yves Wiaux", title = "A novel sampling theorem on the rotation group", journal = "IEEE Sig. Proc. Let.", year = "2015", volume = "22", number = "12", pages = "2425--2429", eprint = "arXiv:1508.03101", doi = "10.1109/LSP.2015.2490676" }

License

We provide this code under an MIT open-source licence with the hope that it will be of use to a wider community.

Copyright 2023 Matthew Price, Jason McEwen and contributors.

S2FFT is free software made available under the MIT License. For details see the LICENCE.txt file.

The file lib/include/kernel_helpers.h is adapted from code in a tutorial on extending JAX by Dan Foreman-Mackey and licensed under a MIT license.

The file lib/include/kernel_nanobind_helpers.h is adapted from code by the JAX authors and licensed under a Apache-2.0 license.

Owner

  • Name: AstroInfo Team @ UCL
  • Login: astro-informatics
  • Kind: organization
  • Location: United Kingdom

GitHub Events

Total
  • Create event: 47
  • Release event: 4
  • Issues event: 51
  • Watch event: 62
  • Delete event: 39
  • Member event: 1
  • Issue comment event: 102
  • Push event: 310
  • Pull request review event: 54
  • Pull request review comment event: 38
  • Pull request event: 85
  • Fork event: 4
Last Year
  • Create event: 47
  • Release event: 4
  • Issues event: 51
  • Watch event: 62
  • Delete event: 39
  • Member event: 1
  • Issue comment event: 102
  • Push event: 310
  • Pull request review event: 54
  • Pull request review comment event: 38
  • Pull request event: 85
  • Fork event: 4

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 863
  • Total Committers: 12
  • Avg Commits per committer: 71.917
  • Development Distribution Score (DDS): 0.521
Past Year
  • Commits: 213
  • Committers: 8
  • Avg Commits per committer: 26.625
  • Development Distribution Score (DDS): 0.338
Top Committers
Name Email Commits
CosmoMatt m****e@h****k 413
Jason McEwen j****n@g****m 182
Matt Graham m****m@g****m 154
Wassim KABALAN w****v@g****m 38
Devaraj Gopinathan d****n@u****k 36
allcontributors[bot] 4****] 25
dependabot[bot] 4****] 6
EiffL f****l@g****m 4
Philipp Misof m****f@c****e 2
Ikko Eltociear Ashimine e****r@g****m 1
Elis Roberts e****s@i****m 1
CosmoMatt m****e@k****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 138
  • Total pull requests: 146
  • Average time to close issues: 3 months
  • Average time to close pull requests: 12 days
  • Total issue authors: 13
  • Total pull request authors: 11
  • Average comments per issue: 1.08
  • Average comments per pull request: 1.37
  • Merged pull requests: 125
  • Bot issues: 0
  • Bot pull requests: 26
Past Year
  • Issues: 50
  • Pull requests: 87
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 12 days
  • Issue authors: 9
  • Pull request authors: 10
  • Average comments per issue: 1.16
  • Average comments per pull request: 1.17
  • Merged pull requests: 69
  • Bot issues: 0
  • Bot pull requests: 23
Top Authors
Issue Authors
  • jasonmcewen (66)
  • matt-graham (42)
  • CosmoMatt (11)
  • PhilippMisofCH (5)
  • Magwos (4)
  • ASKabalan (3)
  • lgrcia (2)
  • sijil-jose (2)
  • mariogeiger (1)
  • mreineck (1)
  • ntessore (1)
  • MEH04 (1)
  • ElisR (1)
  • yangjinhui11 (1)
Pull Request Authors
  • matt-graham (71)
  • CosmoMatt (41)
  • jasonmcewen (25)
  • dependabot[bot] (18)
  • allcontributors[bot] (13)
  • ASKabalan (4)
  • ElisR (2)
  • PhilippMisofCH (2)
  • ntessore (1)
  • eltociear (1)
  • kmulderdas (1)
Top Labels
Issue Labels
infrastructure (14) documentation (12) enhancement (12) clean up (9) bug (7) question (4) blocker (3) tests (3) good first issue (2) github_actions (2) dependencies (1) security (1) critical (1) wontfix (1)
Pull Request Labels
enhancement (32) documentation (22) infrastructure (22) github_actions (20) dependencies (19) bug (6) clean up (5) blocker (3) critical (2) benchmarks (2) help wanted (1)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 455 last-month
  • Total dependent packages: 2
  • Total dependent repositories: 0
  • Total versions: 8
  • Total maintainers: 3
pypi.org: s2fft

Differentiable and accelerated spherical transforms with JAX

  • Documentation: https://s2fft.readthedocs.io/
  • License: MIT License Copyright (c) 2022 Authors & Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 1.3.0
    published 10 months ago
  • Versions: 8
  • Dependent Packages: 2
  • Dependent Repositories: 0
  • Downloads: 455 Last month
Rankings
Stargazers count: 9.1%
Dependent packages count: 10.0%
Forks count: 19.1%
Average: 26.4%
Dependent repos count: 67.4%
Maintainers (3)
Last synced: 6 months ago

Dependencies

.github/workflows/docs.yml actions
  • JamesIves/github-pages-deploy-action 4.1.5 composite
  • actions/checkout v2.3.1 composite
  • actions/setup-python v2 composite
.github/workflows/tests.yml actions
  • actions/checkout v2.3.1 composite
  • actions/setup-python v2 composite
requirements/requirements-core.txt pypi
  • colorlog *
  • ipykernel *
  • ipywidgets *
  • jax >=0.3.13
  • numpy >=1.20
  • pyssht *
  • pyvista *
  • pyyaml *
  • trame *
requirements/requirements-docs.txt pypi
  • ipython ==7.16.1
  • jupyter ==1.0.0
  • nbsphinx-link ==1.3.0
  • pydata-sphinx-theme ==0.12.0
  • sphinx ==4.2.0
  • sphinx-copybutton *
  • sphinx-git ==11.0.0
  • sphinx-tabs ==3.2.0
  • sphinx_rtd_theme *
  • sphinx_toolbox ==2.15.0
  • sphinxcontrib-bibtex ==2.4.1
  • sphinxcontrib-texfigure ==0.1.3
  • sphinxemoji *
requirements/requirements-tests.txt pypi
  • codecov * test
  • healpy * test
  • jaxlib * test
  • pytest * test
  • pytest-cov * test
  • so3 * test
requirements/requirements-plotting.txt pypi
  • ipykernel *
  • ipywidgets *
  • pyvista *
  • trame *
setup.py pypi