JAX-accelerated FFTLog implementation for Large Scale Structure cosmology
Project description
FFTLog
A Python implementation of FFTLog for fast logarithmic FFT transforms, developed for PyBird.
Installation
Basic installation (recommended)
pip install fftlog-lss
With JAX acceleration
pip install "fftlog-lss[jax]"
From source
git clone https://github.com/pierrexyz/fftlog.git
cd fftlog
pip install --editable .
From source with JAX
git clone https://github.com/pierrexyz/fftlog.git
cd fftlog
pip install --editable ".[jax]"
Dependencies
Required
- Python >= 3.8
- numpy >= 1.20.0
- scipy >= 1.7.0
Optional (for JAX acceleration)
- jax >= 0.4.0
- jaxlib >= 0.4.0
- interpax >= 0.3.0
Quickstart
Basic Usage (without JAX)
import numpy as np
from scipy.stats import lognorm
from fftlog import FFTLog
# Create test function (power spectrum)
k = np.logspace(-4, 0, 200)
pk = lognorm.pdf(k, 2.1)
# Initialize FFTLog
fft = FFTLog(
Nmax=512, # Number of points
xmin=1e-5, # Minimum k value
xmax=1e3, # Maximum k value
bias=-0.1, # Bias parameter
complex=False, # Use real FFT
window=0.1 # Anti-aliasing window
)
# FFTLog decomposition and reconstruction
pk_reconstructed = fft.rec(k, pk, k)
# Spherical Bessel Transform
s = np.arange(1., 1e3, 5.)
xi = fft.sbt(k, pk, s) # Fast O(N log N) transform
With JAX Acceleration
import numpy as np
from scipy.stats import lognorm
from fftlog import FFTLog
from fftlog.config import set_jax_enabled
from jax import jit
import jax.numpy as jnp
# Enable JAX mode
set_jax_enabled(True)
# Create test function
k = np.logspace(-4, 0, 200)
pk = lognorm.pdf(k, 2.1)
# Initialize FFTLog (same as above)
fft = FFTLog(
Nmax=512, xmin=1e-5, xmax=1e3,
bias=-0.1, complex=False, window=0.1
)
# Convert to JAX arrays and JIT compile
k_jax, pk_jax = jnp.array(k), jnp.array(pk)
get_coef_jit = jit(fft.Coef)
# Now much faster for repeated calls
coefficients = get_coef_jit(k_jax, pk_jax)
Features
- Fast logarithmic FFT transforms
- Support for both real and complex transforms
- Spherical Bessel transforms
- Anti-aliasing windows
- Optional JAX acceleration for GPU/TPU support
Documentation
For more detailed examples and documentation, see the notebooks in the notebooks/ directory.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fftlog_lss-0.1.2.tar.gz.
File metadata
- Download URL: fftlog_lss-0.1.2.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dbfcc12c8733f3dd7c53752487e7342ec2d60bff8f9dfd0128c11dfa5456284
|
|
| MD5 |
d846c67e2cd98bb1bee26b1ef6a10e17
|
|
| BLAKE2b-256 |
082a398eaa7e8469dcc0c8f8f56715d66a092670ae66a911a7920605775cb1d3
|
File details
Details for the file fftlog_lss-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fftlog_lss-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e8e67ba421133e4eb252e903034a129cc5ff56279f5a10dcf956eae9a6c4b4f
|
|
| MD5 |
2c04a59bb0e71ac5db40b69445de523f
|
|
| BLAKE2b-256 |
190f6335fea715b5f18d01f22e440814ecfc16dcd07a965f52bb87208c8893dc
|