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
Copy file name to clipboardExpand all lines: README.md
+72-43Lines changed: 72 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,8 +18,8 @@
18
18
</div>
19
19
20
20
`S2FFT` is a Python package for computing Fourier transforms on the sphere
21
-
and rotation group [(Price & McEwen 2024)](https://arxiv.org/abs/2311.14670) using
22
-
JAX or PyTorch. It leverages autodiff to provide differentiable transforms, which are
21
+
and rotation group [(Price & McEwen 2024)](https://arxiv.org/abs/2311.14670) using
22
+
JAX or PyTorch. It leverages autodiff to provide differentiable transforms, which are
23
23
also deployable on hardware accelerators (e.g. GPUs and TPUs).
24
24
25
25
More specifically, `S2FFT` provides support for spin spherical harmonic
@@ -41,16 +41,16 @@ angular resolution $L$. The diagram below illustrates the recursions
41
41
<imgclass="dark-light"alt="Schematic of Wigner recursions"src="https://raw.githubusercontent.com/astro-informatics/s2fft/main/docs/assets/figures/Wigner_recursion_legend_darkmode.png" />
42
42
</div>
43
43
44
-
With this recursion to hand, the spherical harmonic coefficients of an
45
-
isolatitudinally sampled map may be computed as a two step process. First,
46
-
a 1D Fourier transform over longitude, for each latitudinal ring. Second,
47
-
a projection onto the real polar-d functions. One may precompute and store
48
-
all real polar-d functions for extreme acceleration, however this comes
49
-
with an equally extreme memory overhead, which is infeasible at $L \sim 1024$.
50
-
Alternatively, the real polar-d functions may calculated recursively,
51
-
computing only a portion of the projection at a time, hence incurring
52
-
negligible memory overhead at the cost of slightly slower execution. The
53
-
diagram below illustrates the separable spherical harmonic transform
44
+
With this recursion to hand, the spherical harmonic coefficients of an
45
+
isolatitudinally sampled map may be computed as a two step process. First,
46
+
a 1D Fourier transform over longitude, for each latitudinal ring. Second,
47
+
a projection onto the real polar-d functions. One may precompute and store
48
+
all real polar-d functions for extreme acceleration, however this comes
49
+
with an equally extreme memory overhead, which is infeasible at $L \sim 1024$.
50
+
Alternatively, the real polar-d functions may calculated recursively,
51
+
computing only a portion of the projection at a time, hence incurring
52
+
negligible memory overhead at the cost of slightly slower execution. The
53
+
diagram below illustrates the separable spherical harmonic transform
54
54
(for further details see [Price & McEwen 2024]((https://arxiv.org/abs/2311.14670))).
55
55
56
56
<divstyle="text-align: center;"align="center">
@@ -65,7 +65,7 @@ supported.
65
65
66
66
The equiangular sampling schemes of [McEwen & Wiaux
and [Gauss-Legendre (1986)](https://link.springer.com/article/10.1007/BF02519350)
70
70
are supported, which exhibit associated sampling theorems and so
71
71
harmonic transforms can be computed to machine precision. Note that the
@@ -84,8 +84,17 @@ pixels of equal areas, which has many practical advantages.
84
84
<imgclass="dark-light"alt="Visualization of spherical sampling schemes"src="https://raw.githubusercontent.com/astro-informatics/s2fft/main/docs/assets/figures/spherical_sampling.png"width="700">
85
85
</div>
86
86
87
-
> [!NOTE]
88
-
> 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 are working to fix it. A fix for CPU execution has now been implemented (see example [notebook](https://astro-informatics.github.io/s2fft/tutorials/spherical_harmonic/JAX_HEALPix_backend.html)).
87
+
> [!NOTE]
88
+
> For algorithmic reasons JIT compilation of HEALPix transforms can become slow at high bandlimits, due to XLA unfolding of loops.
89
+
> After compilation, HEALPix transforms should execute with the efficiency outlined in the associated paper, therefore this additional time overhead need only be incurred once.
90
+
>
91
+
> __If running on a CPU__, we provide (differentiable) JAX wrappers of the [`healpy`](https://healpy.readthedocs.io/en/latest/) transforms which can be used to sidestep the issue.
92
+
> This implementation can be selected by passing a `method="jax_healpy"` keyword argument to the `s2fft.forward` or `s2fft.inverse` functions -
93
+
> see example [notebook](https://astro-informatics.github.io/s2fft/tutorials/spherical_harmonic/JAX_HEALPix_backend.html).
94
+
>
95
+
> __If running on a GPU__, a CUDA extension module is available which avoids the long compilation time.
96
+
> This implementation can be selected by passing a `method="jax_cuda"` keyword argument to the `sfft.forward` and `s2fft.inverse` functions.
97
+
> Currently we do not publish binary wheels with the CUDA extension support so you will need to [build the package from source](#cuda-extension-support) to use this functionality.
89
98
90
99
## Installation 💻
91
100
@@ -101,16 +110,36 @@ if you wish to install JAX with GPU or TPU support,
101
110
you should first follow the [relevant installation instructions in JAX's documentation](https://docs.jax.dev/en/latest/installation.html#installation)
102
111
and then install `S2FFT` as above.
103
112
104
-
Alternatively, the latest development version of `S2FFT` may be installed directly from GitHub by running
113
+
Alternatively, the latest development version of `S2FFT` may be installed directly from GitHub by running
The output should indicate if the CUDA install on your system is successfully detected.
138
+
110
139
## Tests 🚦
111
140
112
141
A `pytest` test suite for the package is included in the `tests` directory.
113
-
To install the test dependencies, clone the repository and install the package (in [editable mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html))
142
+
To install the test dependencies, clone the repository and install the package (in [editable mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html))
114
143
with the extra test dependencies by running from the root of the repository
115
144
116
145
```bash
@@ -120,13 +149,13 @@ pip install -e ".[tests]"
120
149
To run the tests, run from the root of the repository
121
150
122
151
```bash
123
-
pytest
152
+
pytest
124
153
```
125
154
126
155
## Documentation 📖
127
156
128
-
Documentation for the released version is available [here](https://astro-informatics.github.io/s2fft/).
129
-
To install the documentation dependencies, clone the repository and install the package (in [editable mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html))
157
+
Documentation for the released version is available [here](https://astro-informatics.github.io/s2fft/).
158
+
To install the documentation dependencies, clone the repository and install the package (in [editable mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html))
130
159
with the extra documentation dependencies by running from the root of the repository
131
160
132
161
```bash
@@ -136,7 +165,7 @@ pip install -e ".[docs]"
136
165
To build the documentation, run from the root of the repository
137
166
138
167
```bash
139
-
cd docs
168
+
cd docs
140
169
make html
141
170
open _build/html/index.html
142
171
```
@@ -146,7 +175,7 @@ open _build/html/index.html
146
175
A series of tutorial notebooks are included in the `notebooks` directory
147
176
and rendered [in the documentation](https://astro-informatics.github.io/s2fft/tutorials/index.html).
148
177
149
-
To install the dependencies required to run the notebooks locally, clone the repository and install the package (in [editable mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html))
178
+
To install the dependencies required to run the notebooks locally, clone the repository and install the package (in [editable mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html))
150
179
with the extra documentation and plotting dependencies by running from the root of the repository
151
180
152
181
```bash
@@ -172,12 +201,12 @@ import s2fft
172
201
f =...
173
202
L =...
174
203
# Compute harmonic coefficients
175
-
flm = s2fft.forward(f, L, method="jax")
204
+
flm = s2fft.forward(f, L, method="jax")
176
205
# Map back to pixel-space signal
177
206
f = s2fft.inverse(flm, L, method="jax")
178
207
```
179
208
180
-
For a signal on the rotation group
209
+
For a signal on the rotation group
181
210
182
211
```python
183
212
import s2fft
@@ -194,27 +223,27 @@ f = fft.wigner.inverse_jax(flmn, L, N, method="jax")
194
223
195
224
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).
196
225
197
-
> [!NOTE]
198
-
> We also provide PyTorch support for our transforms, as demonstrated in the [_Torch frontend_ tutorial notebook](https://astro-informatics.github.io/s2fft/tutorials/torch_frontend/torch_frontend.html). This wraps the JAX implementations so JAX will need to be installed in addition to PyTorch.
226
+
We also provide PyTorch support for our transforms, as demonstrated in the [_Torch frontend_ tutorial notebook](https://astro-informatics.github.io/s2fft/tutorials/torch_frontend/torch_frontend.html).
227
+
This wraps the JAX implementations so JAX will need to be installed in addition to PyTorch.
199
228
200
229
## SSHT & HEALPix wrappers 💡
201
230
202
-
`S2FFT` also provides JAX support for existing C/C++ packages, specifically [`HEALPix`](https://healpix.jpl.nasa.gov) and [`SSHT`](https://github.com/astro-informatics/ssht). This works
231
+
`S2FFT` also provides JAX support for existing C/C++ packages, specifically [`HEALPix`](https://healpix.jpl.nasa.gov) and [`SSHT`](https://github.com/astro-informatics/ssht). This works
203
232
by wrapping Python bindings with custom JAX frontends. Note that this C/C++ to JAX interoperability is currently limited to CPU.
204
233
205
234
For example, one may call these alternate backends for the spherical harmonic transform by:
All of these JAX frontends supports out of the box reverse mode automatic differentiation,
216
-
and under the hood is simply linking to the C/C++ packages you are familiar with. In this
217
-
way `S2fft` enhances existing packages with gradient functionality for modern scientific computing or machine learning
244
+
All of these JAX frontends supports out of the box reverse mode automatic differentiation,
245
+
and under the hood is simply linking to the C/C++ packages you are familiar with. In this
246
+
way `S2fft` enhances existing packages with gradient functionality for modern scientific computing or machine learning
218
247
applications!
219
248
220
249
For further details on usage see the associated [notebooks](https://astro-informatics.github.io/s2fft/tutorials/spherical_harmonic/JAX_SSHT_backend.html).
@@ -264,8 +293,8 @@ patterns!
264
293
Should this code be used in any way, we kindly request that the following article is
265
294
referenced. A BibTeX entry for this reference may look like:
266
295
267
-
```
268
-
@article{price:s2fft,
296
+
```
297
+
@article{price:s2fft,
269
298
author = "Matthew A. Price and Jason D. McEwen",
270
299
title = "Differentiable and accelerated spherical harmonic and Wigner transforms",
271
300
journal = "Journal of Computational Physics",
@@ -280,21 +309,21 @@ referenced. A BibTeX entry for this reference may look like:
280
309
You might also like to consider citing our related papers on which this
281
310
code builds:
282
311
283
-
```
312
+
```
284
313
@article{mcewen:fssht,
285
314
author = "Jason D. McEwen and Yves Wiaux",
286
315
title = "A novel sampling theorem on the sphere",
287
316
journal = "IEEE Trans. Sig. Proc.",
288
317
year = "2011",
289
318
volume = "59",
290
319
number = "12",
291
-
pages = "5876--5887",
320
+
pages = "5876--5887",
292
321
eprint = "arXiv:1110.6298",
293
322
doi = "10.1109/TSP.2011.2166394"
294
323
}
295
324
```
296
325
297
-
```
326
+
```
298
327
@article{mcewen:so3,
299
328
author = "Jason D. McEwen and Martin B{\"u}ttner and Boris ~Leistedt and Hiranya V. Peiris and Yves Wiaux",
300
329
title = "A novel sampling theorem on the rotation group",
@@ -304,7 +333,7 @@ code builds:
304
333
number = "12",
305
334
pages = "2425--2429",
306
335
eprint = "arXiv:1508.03101",
307
-
doi = "10.1109/LSP.2015.2490676"
336
+
doi = "10.1109/LSP.2015.2490676"
308
337
}
309
338
```
310
339
@@ -319,10 +348,10 @@ Copyright 2023 Matthew Price, Jason McEwen and contributors.
319
348
details see the [`LICENCE.txt`](https://github.com/astro-informatics/s2fft/blob/main/LICENCE.txt) file.
320
349
321
350
The file [`lib/include/kernel_helpers.h`](https://github.com/astro-informatics/s2fft/blob/main/lib/include/kernel_helpers.h) is adapted from
322
-
[code](https://github.com/dfm/extending-jax/blob/c33869665236877a2ae281f3f5dbff579e8f5b00/lib/kernel_helpers.h) in [a tutorial on extending JAX](https://github.com/dfm/extending-jax) by
351
+
[code](https://github.com/dfm/extending-jax/blob/c33869665236877a2ae281f3f5dbff579e8f5b00/lib/kernel_helpers.h) in [a tutorial on extending JAX](https://github.com/dfm/extending-jax) by
323
352
[Dan Foreman-Mackey](https://github.com/dfm) and licensed under a [MIT license](https://github.com/dfm/extending-jax/blob/371dca93c6405368fa8e71690afd3968d75f4bac/LICENSE).
324
353
325
354
The file [`lib/include/kernel_nanobind_helpers.h`](https://github.com/astro-informatics/s2fft/blob/main/lib/include/kernel_nanobind_helpers.h)
326
-
is adapted from [code](https://github.com/jax-ml/jax/blob/3d389a7fb440c412d95a1f70ffb91d58408247d0/jaxlib/kernel_nanobind_helpers.h)
327
-
by the [JAX](https://github.com/jax-ml/jax) authors
328
-
and licensed under a [Apache-2.0 license](https://github.com/jax-ml/jax/blob/3d389a7fb440c412d95a1f70ffb91d58408247d0/LICENSE).
355
+
is adapted from [code](https://github.com/jax-ml/jax/blob/3d389a7fb440c412d95a1f70ffb91d58408247d0/jaxlib/kernel_nanobind_helpers.h)
356
+
by the [JAX](https://github.com/jax-ml/jax) authors
357
+
and licensed under a [Apache-2.0 license](https://github.com/jax-ml/jax/blob/3d389a7fb440c412d95a1f70ffb91d58408247d0/LICENSE).
0 commit comments