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

Đang mở
#151 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@jejjohnson đang làm issue này rồi.

Từ ngày 17/10/2026.

  • #159 của @jejjohnson — đang mở

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
2
Fork
0
Merge trung bình
8 giờ 13 phút
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của jejjohnson/spectraldiffx

Tất cả issue của jejjohnson/spectraldiffx

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.