pipekit Operators
finitevolx.pipekit wraps the 2-D Cartesian operators as
pipekit operators: JSON
configuration, Sequential / Graph composition, and Equinox pytree leaves
so jit, grad and vmap see through them. Each operator is one Tier-A
call on [*batch, Ny, Nx] fields. Requires the pipekit extra:
pip install "finitevolx[pipekit]". Walkthrough:
Composing finitevolX with pipekit.
| Tier-B operator | Tier-A counterpart | in → out |
|---|---|---|
Difference(axis, src, dst) |
Difference2D.diff_{axis}_{src}_to_{dst} |
1 → 1 |
Divergence |
Difference2D.divergence |
(U, V) → T |
Curl |
Difference2D.curl |
(U, V) → X |
Laplacian |
Difference2D.laplacian |
T → T |
GradPerp |
Difference2D.grad_perp |
X → (U, V) |
Interp(src, dst) |
Interpolation2D.{src}_to_{dst} |
1 → 1 |
Coriolis(f0, beta, y0) |
coriolis_fn + Coriolis2D |
(U, V) → (U, V) |
FillGhosts(kind) |
enforce_periodic, zero_boundaries, …, wall_boundaries |
1 → 1 |
ApplyMask(mask, stagger) |
jnp.where(mask.{h,u,v,xy_corner_strict}, x, 0) |
1 → 1 |
RelativeVorticity |
Vorticity2D.relative_vorticity |
(U, V) → X |
PotentialVorticity |
Vorticity2D.potential_vorticity |
(U, V, T, T) → X |
Enstrophy |
Vorticity2D.enstrophy |
(U, V) → X |
QGPotentialVorticity(f0, beta, y0) |
QGPotentialVorticity2D |
T → T |
KineticEnergy |
Energetics2D.kinetic_energy |
(U, V) → T |
AvailablePE(g_prime, H) |
Energetics2D.available_potential_energy |
T → T |
Strain(component) |
Strain2D.shear / .tensor / .magnitude_squared |
(U, V) → X / T |
OkuboWeiss |
Strain2D.okubo_weiss |
(U, V) → T |
TotalEnergy |
total_energy |
(T, T) → [*batch] |
DomainIntegral / DomainMean |
area_sum / area_mean |
T → [*batch] |
ExplicitStep(rhs, dt, scheme) |
euler_step / heun_step / rk3_ssp_step / rk4_step |
state → state |
Pick(index), LinComb(coeffs) |
— (graph plumbing) |
Base classes and helpers
finitevolx.pipekit.FVXOperator
Bases: JaxOperator
Base for finitevolX pipekit operators.
A pipekit_jax.JaxOperator (pipekit Operator + eqx.Module):
config fields are eqx.field(static=True), learnable coefficients
are leaves with converter=jnp.asarray, and _apply maps fields
[*batch, Ny, Nx] to fields.
Source code in finitevolx/_src/pipekit/base.py
finitevolx.pipekit.GridOperator
Bases: FVXOperator
An FVXOperator on a 2-D Cartesian C-grid.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
GridSpec
|
|
Source code in finitevolx/_src/pipekit/base.py
cartesian_grid
property
The Tier-A grid, rebuilt from grid (cached per spec).
finitevolx.pipekit.as_grid_spec(spec)
Normalise a grid description to a GridSpec tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
sequence of 4 numbers or CartesianGrid2D
|
|
required |
Returns:
| Type | Description |
|---|---|
GridSpec
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in finitevolx/_src/pipekit/base.py
finitevolx.pipekit.build_grid(spec)
cached
The CartesianGrid2D a GridSpec describes (cached per spec).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
GridSpec
|
|
required |
Returns:
| Type | Description |
|---|---|
CartesianGrid2D
|
|
Source code in finitevolx/_src/pipekit/base.py
finitevolx.pipekit.over_leading(fn, core_ndim=2)
Lift fn on [*core] arrays to [*batch, *core] arrays.
Every input shares the same leading shape; it is flattened to one axis,
jax.vmap(fn) maps over it, and every output array gets the leading
shape back::
x : [T, E, Ny, Nx] ─reshape─► [T·E, Ny, Nx] ─vmap fn─► [T·E, …] ─reshape─► [T, E, …]
Only needed for Tier-A functions that are still 2-D only; the 2-D
Cartesian operators take [*batch, Ny, Nx] natively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
callable
|
Function of positional arrays with |
required |
core_ndim
|
int
|
Number of trailing axes |
2
|
Returns:
| Type | Description |
|---|---|
callable
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the inputs disagree on their leading shape. |
Source code in finitevolx/_src/pipekit/base.py
finitevolx.pipekit.testing.check_operator(op, *fields, hlo=True)
Assert that op is a well-behaved finitevolX pipekit operator.
Runs pipekit_jax.testing.check_jax_operator (operator + module, eager
≡ filter_jit, vmap, visible leaves, JSON config round trip),
then checks:
- Leading axes: on inputs
[*lead, Ny, Nx]withlead=(2,)and(2, 3),opequals a loop over the members. - Gradient:
∂/∂x₀ ∑ op(x)is finite. - Lowering (when
hlo): the compiled HLO has nogather,scatterorconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
FVXOperator
|
Operator under test. |
required |
*fields
|
Array
|
Example inputs |
()
|
hlo
|
bool
|
Also check the lowering. |
True
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
On the first violated property. |
Source code in finitevolx/_src/pipekit/testing.py
Stencils, interpolation, boundaries and masks
finitevolx.pipekit.Difference
Bases: GridOperator
One-sided difference between staggered points, δ / Δ.
axis="x", src="T", dst="U": δₓh[j, i+½] = (h[j, i+1] − h[j, i]) / Δx.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
GridSpec
|
|
axis |
{'x', 'y'}
|
Difference direction. |
src, dst |
{'T', 'U', 'V', 'X'}
|
Source and destination stagger; see |
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.Divergence
Bases: GridOperator
∇·(u, v) at T-points: δₓu / Δx + δᵧv / Δy. (U, V) → T.
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.Curl
Bases: GridOperator
Relative vorticity ζ = δₓv / Δx − δᵧu / Δy at X-points. (U, V) → X.
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.Laplacian
Bases: GridOperator
Five-point Laplacian ∇²h at T-points. T → T.
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.GradPerp
Bases: GridOperator
Rotated gradient (u, v) = (−∂ᵧψ, ∂ₓψ) of a streamfunction. X → (U, V).
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.Interp
Bases: GridOperator
Average between staggered points (two- or four-point mean).
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
GridSpec
|
|
src, dst |
{'T', 'U', 'V', 'X'}
|
Source and destination stagger; see |
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.Coriolis
Bases: GridOperator
Coriolis tendencies on a β-plane, (U, V) → (U, V).
f = f₀ + β (y − y₀) at T-points, ghost ring included (y = j Δy), then
Coriolis2D(u, v, f): (+f v̄ at U, −f ū at V), energy conserving.
f0 and beta are learnable leaves.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
GridSpec
|
|
f0 |
Array
|
Reference Coriolis parameter. |
beta |
Array
|
Meridional gradient ∂f/∂y. |
y0 |
float or None
|
Reference latitude coordinate; |
Source code in finitevolx/_src/pipekit/stencils.py
coriolis_parameter(dtype=None)
f at the T-points of the grid, ghost ring included.
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.FillGhosts
Bases: FVXOperator
Fill the ghost ring with a boundary condition. x → x.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
One of |
staggering |
{'h', 'u', 'v', 'q'}
|
Only for |
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.ApplyMask
Bases: FVXOperator
Zero a field on the dry points of its stagger (jnp.where, NaN-safe).
The mask is an array-holding module, so the config has no JSON form:
the operator is forbid_in_yaml and persists through
serialize_weights / with_weights.
Attributes:
| Name | Type | Description |
|---|---|---|
mask |
Mask2D
|
Land / ocean mask. |
stagger |
{'T', 'U', 'V', 'X'}
|
Which wet mask to apply: T → |
Source code in finitevolx/_src/pipekit/stencils.py
Diagnostics and reductions
finitevolx.pipekit.RelativeVorticity
Bases: GridOperator
ζ = δₓv / Δx − δᵧu / Δy at X-points. (U, V) → X.
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.PotentialVorticity
Bases: GridOperator
Shallow-water PV q = (ζ + f) / h at X-points. (U, V, T, T) → X.
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.Enstrophy
finitevolx.pipekit.QGPotentialVorticity
Bases: GridOperator
Single-layer QG PV q = (∇²ψ + β (y − y₀)) / f₀ at T-points. T → T.
y = j Δy at the T-points (ghost ring included).
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
GridSpec
|
|
f0 |
Array
|
Reference Coriolis parameter (learnable). |
beta |
Array
|
Meridional gradient ∂f/∂y (learnable). |
y0 |
float or None
|
Reference y; |
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.KineticEnergy
Bases: GridOperator
½ (ū² + v̄²) at T-points (velocities averaged to T). (U, V) → T.
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.AvailablePE
Bases: GridOperator
½ g′ (h − H)² at T-points. T → T.
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
GridSpec
|
|
g_prime |
Array
|
Reduced gravity (learnable). |
H |
Array
|
Reference thickness (learnable), broadcast over the grid. |
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.Strain
Bases: GridOperator
A strain component: shear σₛ (X), tensor σₙ (T) or σₛ² + σₙ² (T).
Attributes:
| Name | Type | Description |
|---|---|---|
grid |
GridSpec
|
|
component |
{'shear', 'tensor', 'magnitude_squared'}
|
Which component. |
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.OkuboWeiss
Bases: GridOperator
W = σₙ² + σₛ² − ζ² at T-points (W < 0: vortex cores). (U, V) → T.
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.TotalEnergy
Bases: GridOperator
E = ∑_interior (KE + APE) Δx Δy, one value per leading index.
(T, T) → [*batch].
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.DomainIntegral
Bases: GridOperator
∑_interior x ΔA over the T-cells (area_sum). T → [*batch].
Source code in finitevolx/_src/pipekit/diagnostics.py
finitevolx.pipekit.DomainMean
Bases: GridOperator
Area-weighted interior mean ⟨x⟩ (area_mean). T → [*batch].
Source code in finitevolx/_src/pipekit/diagnostics.py
Time stepping and graph plumbing
finitevolx.pipekit.ExplicitStep
Bases: FVXOperator
One explicit step s ↦ s + Δt Φ(s) of ∂ₜs = F(s), for a dict state.
Attributes:
| Name | Type | Description |
|---|---|---|
rhs |
Operator
|
Tendency operator: |
dt |
Array
|
Time step (a leaf). |
scheme |
{'euler', 'heun', 'rk3_ssp', 'rk4'}
|
Which |
Source code in finitevolx/_src/pipekit/timestep.py
get_config()
Config with rhs as a nested-operator payload.
finitevolx.pipekit.Pick
Bases: FVXOperator
Select one output of a tuple-valued node: (a, b, …) → [index].
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Position to select. |
Source code in finitevolx/_src/pipekit/stencils.py
finitevolx.pipekit.LinComb
Bases: FVXOperator
Linear combination y = ∑ᵢ cᵢ xᵢ (coefficients are learnable leaves).
Attributes:
| Name | Type | Description |
|---|---|---|
coeffs |
Array
|
|