Neural operators

DeepONet, FNO and GINO aim to learn maps between functions, so the model is less tied to one grid.

Outcome: Say what an operator is and what discretisation-invariant does and does not promise; build a DeepONet from two MLPs in PyTorch; explain an FNO layer (FFT, keep the low modes, multiply, inverse FFT) and train one with the neuraloperator library.

Builds on Convolutions and U-Nets, A first field surrogate

A U-Net maps one grid to another grid of the same size. A neural operator learns a map from one function to another: from the permeability field of a porous plate to its pressure field (Darcy flow, slow flow through a porous medium and a common first benchmark), or from a wing's shape to its surface pressure. The functions are sampled on a grid or mesh for the computer, but the learned map is meant not to depend on how they are sampled.

For a linear PDE (partial differential equation) with homogeneous boundary conditions, the solution is the source integrated against a Green's function:

u(x)=∫ΩG(x,y) f(y) dyu(x) = \int_{\Omega} G(x, y)\, f(y)\, dy
(5-3)
ff is the source, uu the solution, GG the Green’s function and Ω\Omega the domain, over which yy runs.

A neural operator stacks layers of this form, with a learned kernel in place of GG and a nonlinearity between layers (Kovachki et al. 2023). FNO, below, restricts the kernel to depend only on x−yx - y: the integral is then a convolution, which the FFT makes cheap.

DeepONet: a neural field with a branch

DeepONet (Lu et al. 2021) has two MLPs. The branch net reads the input function at mm fixed sensor points and returns pp numbers. The trunk net reads a query point yy and also returns pp numbers. The prediction at yy is their dot product.

The trunk is a neural field with pp outputs, and it returns in 6.5 as the first query decoder; the branch decides how to weight its pp outputs for this particular input.

G(u)(y)≈∑k=1pbk(u) tk(y)+b0\mathcal{G}(u)(y) \approx \sum_{k=1}^{p} b_k(u)\, t_k(y) + b_0
(5-4)
The symbols are the paper’s, so uu and yy change meaning from Equation 5-3: G\mathcal{G} is the operator being learned, uu the input function and yy a query point; b1,…,bpb_1, \dots, b_p come from the branch (the input function at the mm sensors), t1,…,tpt_1, \dots, t_p from the trunk (the query point yy), and b0b_0 is an optional learned constant.
Example 5-5. DeepONet in plain PyTorch
import torch
from torch import nn

def mlp(i, o, h=128):
    return nn.Sequential(
        nn.Linear(i, h), nn.SiLU(),
        nn.Linear(h, h), nn.SiLU(), nn.Linear(h, o))

class DeepONet(nn.Module):
    def __init__(self, m_sensors, dim_y, p=64):
        super().__init__()
        # Branch: the input function at m fixed sensors.
        self.branch = mlp(m_sensors, p)
        # Trunk: the query point y.
        self.trunk = mlp(dim_y, p)
        # The optional constant b0 of the DeepONet paper.
        self.bias = nn.Parameter(torch.zeros(1))

    def forward(self, u, y):         # u: (B, m)
        b = self.branch(u)[:, None]  # (B, 1, p)1
        t = self.trunk(y)            # y: (B, Q, dim_y)
        # One value per query point: (B, Q)
        return (b * t).sum(-1) + self.bias2

# 16 input functions, each sampled at 100 sensors,
# and 500 query points (x, y) per case.
u = torch.randn(16, 100)
y = torch.rand(16, 500, 2)
print(DeepONet(100, 2)(u, y).shape)  # (16, 500)
  1. [:, None] adds an axis for the query points, so the branch’s pp numbers for each case broadcast over all QQ of its points.
  2. The sum over the last axis is the dot product of Equation 5-4, one per query point, plus b0b_0.

Example 5-5 prints torch.Size([16, 500]): a value at each of the 500 query points of each of the 16 input functions.

FNO: mixing in Fourier space

A periodic signal can be written as a sum of sines and cosines, its Fourier modes: mode 1 is one wave across the domain, mode 10 is ten waves. The fast Fourier transform (FFT) computes the modes from the samples, and the inverse FFT goes back. A Fourier Neural Operator (FNO; Li et al. 2021) layer takes the FFT of its input channels, keeps only the lowest kk modes, multiplies them by learned complex weights (which mixes channels), and transforms back. A pointwise linear path is added alongside, then a nonlinearity. Because every kept mode spans the whole domain, one layer is global, unlike a 3×3 convolution.

vℓ+1(x)=σ(Wvℓ(x)+F−1(R⋅Fvℓ)(x))v_{\ell+1}(x) = \sigma\Big(W v_\ell(x) + \mathcal{F}^{-1}\big(R \cdot \mathcal{F} v_\ell\big)(x)\Big)
(5-5)
vℓ(x)v_\ell(x) holds the channels of layer ℓ\ell at point xx; F\mathcal{F} is the Fourier transform (the FFT on a grid); RR holds the learned complex weights, one channel-mixing matrix per kept mode, with every mode above the lowest kk set to zero; WW is the pointwise linear path and σ\sigma the nonlinearity. By the convolution theorem, multiplying the modes by RR is a convolution with a kernel that depends only on x−yx - y.

With fewer modes kept, which part of the signal goes first, the broad waves or the narrow peak?

mode 0mode 398 kept; modes 0 to 39 of 65 shown
Figure 5-5. A synthetic signal with a narrow peak (thin line) rebuilt from its lowest Fourier modes (thick line); the bars are the size of each mode, kept modes in colour. The error is the relative L2 error of the rebuilt signal.

Smooth parts of the signal need few modes; the narrow peak of Figure 5-5 needs many. An FNO with 16 modes per direction tends to capture large-scale structure well and to struggle with shocks and thin boundary layers, which the pointwise path and the nonlinearities have to rebuild (Lanthaler et al. 2022). Example 5-6 is the core of one layer.

Example 5-6. The core of an FNO layer, in one dimension
import torch
from torch import nn

class SpectralConv1d(nn.Module):
    def __init__(self, c, k):
        super().__init__()
        self.k = k                     # Fourier modes kept
        w = torch.randn(c, c, k, dtype=torch.cfloat)
        self.w = nn.Parameter(w / c)1

    def forward(self, x):              # x: (B, c, n)
        X = torch.fft.rfft(x)          # (B, c, n/2 + 1)2
        Y = torch.zeros_like(X)
        # Mix channels mode by mode; drop the high modes.
        Y[..., :self.k] = torch.einsum(
            "bik,iok->bok", X[..., :self.k], self.w)3
        return torch.fft.irfft(Y, n=x.shape[-1])4

# In 2D and 3D (rfftn), the low modes sit at both ends of
# every axis except the last, so implementations keep two
# or four corner blocks of modes.
layer = SpectralConv1d(c=8, k=12)
print(layer(torch.randn(2, 8, 256)).shape)
print(layer(torch.randn(2, 8, 1024)).shape)
  1. One complex c×cc \times c matrix per kept mode: the RR of Equation 5-5. Dividing by cc keeps the first outputs small.
  2. rfft of a real signal returns only the non-negative frequencies, n // 2 + 1 modes along the last axis.
  3. For each mode k, the vector of input channels i is multiplied by a matrix to give output channels o: channels mix, modes do not.
  4. n=x.shape[-1] returns a signal as long as the input, so the same weights run on 256 and on 1,024 points, as the last two lines show.

Example 5-6 prints torch.Size([2, 8, 256]) and torch.Size([2, 8, 1024]): the same 12 kept modes, on two grids.

The neuraloperator library adds a lifting layer (a pointwise MLP that widens the input channels to the hidden width) and a projection layer (the reverse, down to the output fields). Optional domain padding (domain_padding=..., off by default) handles non-periodic domains, so the FFT does not wrap one edge onto the other. Its Darcy example trains a smaller model of this kind (n_modes=(8, 8)) on a CPU.

Example 5-7. An FNO for 2D fields with neuraloperator
# pip install neuraloperator (tested with 2.0)
import torch
from neuralop.models import FNO

model = FNO(n_modes=(16, 16), hidden_channels=32,1
            in_channels=1, out_channels=1)
# e.g. permeability on a 64 x 64 grid (Darcy flow)
a = torch.randn(4, 1, 64, 64)
print(model(a).shape)                  # (4, 1, 64, 64)
# The same weights run on a finer grid.
print(model(torch.randn(4, 1, 128, 128)).shape)2
  1. 16 modes kept in each direction; hidden_channels is the width after the lifting layer.
  2. The same weights on a 128×128 grid. It runs; whether it is more accurate there is the subject of the next section.

Example 5-7 prints torch.Size([4, 1, 64, 64]), then torch.Size([4, 1, 128, 128]).

Discretisation invariance

DefinitionDiscretisation-invariant

An operator is discretisation-invariant when the same weights can be applied to inputs sampled at different resolutions, and its answers converge to those of one continuous operator as the sampling is refined.

DeepONet's trunk accepts any query point, though its branch needs the input at the same mm sensors every time. The FNO's weights live on Fourier modes, not on grid cells, so the last line of Example 5-7 runs on a 128×128 grid.

Evaluating above the training resolution, which the FNO paper calls zero-shot super-resolution, adds no information: a model trained on a coarse grid and run on a finer one is not reliably more accurate than the same model run on its training grid and upsampled, and can be worse (Sakarvadia et al. 2026; Colagrande et al. 2026).

Operators on irregular 3D geometry

An FFT needs a regular grid, and a car is not one. The usual remedy keeps the FNO on a regular grid of its own, a latent grid, and puts a learned interpolation on either side of it; the price is that detail finer than the latent grid’s cells has to be carried by those two interpolations. GINO (Li et al. 2023) does this with two graph operators. The first aggregates the surface points onto a regular latent grid around the car: each grid point takes a learned, kernel-weighted sum over the surface points within a radius. The result is concatenated with a signed distance on that grid. The FNO works there, and the second graph operator brings the result back to any query point on the surface. Its paper tests it on 3D vehicle shapes (ShapeNet-Car and Ahmed bodies), for surface pressure.