feat(pipekit): `spectraldiffx.pipekit` scaffolding — `Spectral` carrier, transforms, `GridSpec`, contract test

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

@jejjohnson is already working on this.

Since Oct 17, 2026.

  • #159 by @jejjohnson — open

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
backend, testing

Research direction

Start by reading the pipekit E1.2 JaxOperator contract and the implementation around Graph.describe() and JSON state round trips. Then implement the proposed spectraldiffx/pipekit/ modules and use testing.py to check transforms, pytree behavior, and operator contracts. The issue is done when the listed acceptance criteria pass, including the optional dependency error.

Written by the indexing model from the issue text.

Description

enhancement

Part of epic #148. Depends on: pipekit E1.2 (pipekit_jax.JaxOperator). Not blocked by #108.

Proposal

spectraldiffx/
  pipekit/
    __init__.py
    _src/
      carrier.py      # Spectral, as_hat, emit
      base.py         # SpectralOperator, GridSpec, build_grid
      transforms.py   # ToSpectral, ToPhysical
      derivatives.py  # #152 (E4.2)
      solvers.py      # #153 (E4.3)
      diagnostics.py  # #154 (E4.4)
    testing.py        # check_operator, count_transforms
class Spectral(eqx.Module):
    """Fourier coefficients of a real field.   hat: complex[..., Ny, Nx(/2+1)]"""
    hat: Array
    real: bool = eqx.field(static=True, default=False)   # True → rfft layout (#108)

    # linear algebra on the carrier, so LinComb / RK stages work unchanged
    def __add__(self, o): return Spectral(self.hat + o.hat, self.real)
    def __sub__(self, o): return Spectral(self.hat - o.hat, self.real)
    def __mul__(self, c): return Spectral(c * self.hat, self.real)   # scalar only
    __rmul__ = __mul__
    def __neg__(self):    return Spectral(-self.hat, self.real)


GridSpec = tuple   # (Nx, Ny, Lx, Ly, dealias)  — JSON primitives

class SpectralOperator(JaxOperator):
    grid: GridSpec = eqx.field(static=True)
    out: Literal["physical", "spectral"] = eqx.field(static=True, default="physical")

Carrier helpers, the single place representation is decided:

def as_hat(x, grid):                        # Array → transform; Spectral → as is
def emit(hat, grid, out, real):             # out="spectral" → Spectral; else inverse (.real)

ToSpectral(grid): real [..., Ny, Nx] → Spectral. ToPhysical(grid): Spectral → real. Both are explicit graph nodes, so where the transforms happen is visible in Graph.describe().

testing.count_transforms(fn, *args) -> dict[str, int] counts fft_type=FFT|IFFT|RFFT|IRFFT in jax.jit(fn).lower(*args).compile().as_text(). check_operator(op, *inputs, budget=None) asserts:

  • JSON state round-trip;
  • eager ≡ jit;
  • leading-axis broadcast on [2, …] stacks;
  • grad finite;
  • if budget is given, count_transforms equals it.

Acceptance criteria

  • Spectral is a pytree. jax.tree.map, vmap and lax.scan carries all work, and real survives round trips as static metadata.
  • ToPhysical(ToSpectral(x)) == x (allclose) for random real fields, for both layouts once #108 adds rfft.
  • Budgets: ToSpectral 1 forward, ToPhysical 1 inverse, ToPhysical ∘ ToSpectral exactly 2 (no silent extra transforms).
  • import spectraldiffx.pipekit without pipekit raises an ImportError naming the extra.

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.