feat(operators): `spectral_out` on `SpectralDerivative2D`

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

@jejjohnson is already working on this.

Since Oct 17, 2026.

  • #158 by @jejjohnson — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
54/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
data

Research direction

Start with SpectralDerivative2D and the existing methods named in the issue, then inspect tests/test_tracing.py and its CASES. Check how each method handles spectral input and transforms before adding the output option. Done means the equivalence checks pass for every method and both input modes, and compiled HLO has the specified transform counts.

Written by the indexing model from the issue text.

Description

enhancement

Part of epic #148. The 2-D slice of #108 that the pipekit layer needs. No dependencies.

Problem

SpectralDerivative2D already takes Fourier coefficients (spectral=True), but it always returns a physical field. A pipeline that keeps fields in spectral space therefore pays an inverse → forward round trip at every node. The barotropic-vorticity prototype measured 40 transforms per RK4 step, against 20 when the output stays spectral. XLA merges identical transforms, but it does not cancel an inverse → forward pair.

Proposal

Add a keyword spectral_out: bool = False to the 2-D methods:

  • gradient, divergence, curl, laplacian, biharmonic, hyperviscosity, inverse_laplacian, velocity_from_streamfunction: return the coefficients and skip the inverse transform;
  • jacobian, advection_scalar: return the dealiased coefficients of the product, which is 1 forward transform instead of 1 forward + 1 inverse.

The defaults are unchanged. apply_dealias keeps its current rule (output space = input space).

The N-D grid, the rfft layout and the exposed multipliers stay in #108.

Acceptance criteria

  • transform(op(u, spectral_out=False)) == op(u, spectral_out=True) (allclose), for every method and both spectral= modes.
  • Transform counts in compiled HLO, spectral in and spectral out:
    • 0 for the linear methods;
    • 4 inverse + 1 forward for jacobian.
  • Added to the tests/test_tracing.py CASES.

Generated by Claude Code

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.