Skip to content

Conversation

andrinr
Copy link
Collaborator

@andrinr andrinr commented Apr 27, 2025

This pull request enables importing the library using

import powerbox.jax ...

Summary by Sourcery

Introduce JAX support for core functionalities.

New Features:

  • Add a new powerbox.jax sub-package containing JAX implementations of PowerBox, LogNormalPowerBox, get_power, angular_average, and related tools.
  • Enable importing the library using import powerbox.jax ...

Enhancements:

  • Add a JAXFFT backend for FFT operations using jax.fft.

Copy link

sourcery-ai bot commented Apr 27, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new sub-package powerbox.jax which provides a JAX-based implementation of the library's core functionalities, including FFT calculations, power spectrum analysis, and the generation of Gaussian and LogNormal fields. This allows users to leverage JAX for potentially faster or GPU-accelerated computations.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Implement a JAX backend for FFT operations.
  • Add a new class JAXFFT inheriting from FFTBackend.
  • Implement fftn, ifftn, fftshift, ifftshift, fftfreq, and empty methods using jax.numpy.fft.
  • Include a JAX import check within the JAXFFT constructor.
src/powerbox/dft_backend.py
Add JAX-compatible Discrete Fourier Transform (DFT) functions.
  • Create fft, ifft, fftfreq, fftshift, and ifftshift functions specifically for JAX.
  • Implement arbitrary convention and normalization logic using JAX NumPy.
  • Integrate with the new JAX FFT backend.
src/powerbox/jax/dft.py
Add JAX utility functions for power spectrum analysis and manipulation.
  • Implement angular averaging functions (angular_average, angular_average_nd) compatible with JAX.
  • Include helper functions for binning, weighted averaging, and interpolation.
  • Add functions for converting power units (power2delta) and weighting k-modes (ignore_zero_absk, ignore_zero_ki).
  • Implement a function for discretizing particle data onto a grid (discretize_N).
  • Provide the main get_power function for calculating the isotropic power spectrum using the JAX-based utilities.
src/powerbox/jax/tools.py
Implement JAX-based classes for generating fields with specified power spectra.
  • Create a PowerBox class for generating Gaussian random fields using JAX.
  • Implement methods for generating k-space coefficients and real-space fields.
  • Add a LogNormalPowerBox class inheriting from PowerBox to generate LogNormal fields.
  • Override methods to apply the log-normal transformation while maintaining the desired power spectrum.
src/powerbox/jax/powerbox.py
Establish the powerbox.jax sub-package structure.
  • Add an __init__.py file to mark the directory as a Python package.
src/powerbox/jax/__init__.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codecov bot commented Apr 27, 2025

Codecov Report

Attention: Patch coverage is 0.38023% with 524 lines in your changes missing coverage. Please review.

Project coverage is 49.00%. Comparing base (69c5cc1) to head (3f69aa0).

Files with missing lines Patch % Lines
src/powerbox/jax/tools.py 0.00% 308 Missing ⚠️
src/powerbox/jax/powerbox.py 0.00% 120 Missing ⚠️
src/powerbox/jax/dft.py 0.00% 82 Missing ⚠️
src/powerbox/dft_backend.py 14.28% 12 Missing ⚠️
src/powerbox/jax/__init__.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #79       +/-   ##
===========================================
- Coverage   92.95%   49.00%   -43.95%     
===========================================
  Files           5        9        +4     
  Lines         582     1108      +526     
===========================================
+ Hits          541      543        +2     
- Misses         41      565      +524     
Flag Coverage Δ
unittests 49.00% <0.38%> (-41.51%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@steven-murray
Copy link
Owner

@andrinr have you had any time to work on this branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants