Epic: JAX-native modules (static fields, no Python control flow on traced values, cached wavenumbers)

Open
#82 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
jupyter-notebook, python

Research direction

The issue points to MixedBCHelmholtzSolver2D in fourier/solvers.py:2386 as a pattern to copy, and mentions gaussx using eqx.field(static=True). Start by examining those modules to understand the static field pattern. Then, identify the 35 equinox.Module subclasses that need refactoring, likely in the spectraldiffx codebase. Look for integer sizes, strings, and enums as pytree leaves. The goal is to make all modules JAX-native, allowing jax.jit and jax.vmap without errors. Check for Python if statements on traced values and replace with eqx.error_if. Finally, implement caching for wavenumber grids and dealias masks at construction.

Written by the indexing model from the issue text.

Description

enhancement epic

Scope

Make every grid, operator, filter and solver in the package a well-behaved JAX pytree so that it can be passed as an argument to jax.jit / jax.vmap and used with traced parameters (alpha, nu, dx, boundary values) without TracerBoolConversionError or ConcretizationTypeError.

Today: 35 of the 43 equinox.Module subclasses hold integer sizes and strings (N, Nx, dealias, node_type) as pytree leaves, so jax.jit(f)(module, u) fails on the string leaf or traces N; only eqx.filter_jit works. About ten if statements on possibly-traced scalars break jit with traced parameters. Wavenumber grids and dealias masks are rebuilt on every property access, which is constant-folded under jit but costs 2.6–4.7x in eager mode.

MixedBCHelmholtzSolver2D (fourier/solvers.py:2386) already does this correctly and is the pattern to copy. gaussx uses eqx.field(static=True) throughout and is the house style to match.

Child issues (in suggested order)

  • #102 refactor: eqx.field(static=True) on sizes, strings and enums in every module — high; prerequisite for #112/#114
  • #103 fix: Python if on possibly-traced values in ~10 places → eqx.error_if — medium; Chebyshev sites after #79
  • #104 perf(grid): cache wavenumber grids and dealias masks at construction — medium
  • #105 docs: static-argument requirements, eqx.filter_jit today, λ=0 gradient discontinuity — low

Related

  • #80 (correctness), #81 (spherical), #83 (Fourier consolidation), #84 (gaussx integration), #85 (hygiene).
Dominant language
Python
Stars
2
Forks
0
Avg merge
8h 13m
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/spectraldiffx

All issues in jejjohnson/spectraldiffx

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.