Skip to content

feat: Add JAX acceleration support to z_n_search#966

Open
temp-noob wants to merge 3 commits intoStingraySoftware:mainfrom
temp-noob:useJaxFor_z_n_search
Open

feat: Add JAX acceleration support to z_n_search#966
temp-noob wants to merge 3 commits intoStingraySoftware:mainfrom
temp-noob:useJaxFor_z_n_search

Conversation

@temp-noob
Copy link
Copy Markdown

@temp-noob temp-noob commented Feb 22, 2026

feat: Add JAX acceleration support to z_n_search

Adds optional JAX-accelerated backend for z_n_search via use_jax parameter.
The JAX implementation computes exact unbinned Z^2_n statistics directly from
event phases, complementing the existing numba-JIT'd binned approach.

Implementation details:

  • JAX kernel using vmap for vectorized frequency/fdot grid search
  • Conditional @jax.jit with static_argnums for nharm parameter
  • Graceful fallback when JAX not installed (HAS_JAX flag)
  • Compatible with existing API (1D and 2D search with fdots)

Added comprehensive test suite (16 tests):

  • Correctness tests validating peak detection
  • Comparison tests (JAX vs standard: >0.95 correlation)
  • Benchmark tests showing ~19x speedup on 1D searches (CPU)

Performance on CPU: 1D (no fdot vector) searches gain ~19x speedup. Larger gains expected
on GPU-enabled JAX backends.


This change is Reviewable

@temp-noob
Copy link
Copy Markdown
Author

@matteobachetti, this is my first time contributing to the repo. Let me know if I can help out with more things or things which would be more crucial.

@matteobachetti
Copy link
Copy Markdown
Member

@temp-noob thanks for the PR.
Could you show this code in action, e.g. through a jupyter notebook modifying one of our tutorials? Also on colab.

@temp-noob
Copy link
Copy Markdown
Author

Sorry for the late reply. And thanks for the review @matteobachetti.
Which tutorial are you referring to? I have this test which contrasts the performance

@temp-noob
Copy link
Copy Markdown
Author

@matteobachetti let me know if I can provide any more clarifications ?

@matteobachetti
Copy link
Copy Markdown
Member

@temp-noob We have the notebooks that we use for documentation here: https://github.com/stingraysoftware/notebooks

If you could modify the notebook with Z searches and make it work with your code, we would have a clearer idea of the actual usability of the code, besides a few tests (which are still necessary and important, of course!)

@temp-noob
Copy link
Copy Markdown
Author

@matteobachetti added this notebook for the jupyter notebook tests: StingraySoftware/notebooks#129
Let me know if I can expand more on the reproducing steps.

@temp-noob
Copy link
Copy Markdown
Author

@matteobachetti let me know if this looks good to you.

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