Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fftlog_lss-0.1.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fftlog_lss-0.1.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file fftlog_lss-0.1.1.tar.gz.

File metadata

  • Download URL: fftlog_lss-0.1.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.1

File hashes

Hashes for fftlog_lss-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6f14abf2185765b2b358b0ad75d4aa1a74547fbc3354eaf52957f4536775c875
MD5 53820bb543e3fac6cfb636b6dbc2a30e
BLAKE2b-256 8e7a53d73bc1bb66929a1fa3f6935c2258187fb62865bc639b9aa93f8569c1c4

See more details on using hashes here.

File details

Details for the file fftlog_lss-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fftlog_lss-0.1.1-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

Hashes for fftlog_lss-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c00642535cefdbe9c7614b8ab9a9800a370e66b3ce1b36af1ada66052926f0e7
MD5 97d2350fa946ed876ffd50abab23d213
BLAKE2b-256 910d5155e31017a88d6cc3524d971f23c7e4c0a90d6a80bc3d7a94df3ecacc26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page