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

Aperta
#151 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@jejjohnson ci sta già lavorando.

Dal 17/10/2026.

  • #159 di @jejjohnson — aperta

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
2
Fork
0
Merge medio
8h 13m
PR unite (30g)
8

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jejjohnson/spectraldiffx

Tutte le issue di jejjohnson/spectraldiffx

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.