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:
A neural operator stacks layers of this form, with a learned kernel in place of and a nonlinearity between layers (Kovachki et al. 2023). FNO, below, restricts the kernel to depend only on : 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 fixed sensor points and returns numbers. The trunk net reads a query point and also returns numbers. The prediction at is their dot product.
The trunk is a neural field with outputs, and it returns in 6.5 as the first query decoder; the branch decides how to weight its outputs for this particular input.
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)
[:, None]adds an axis for the query points, so the branch’s numbers for each case broadcast over all of its points.- The sum over the last axis is the dot product of Equation 5-4, one per query point, plus .
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 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.
With fewer modes kept, which part of the signal goes first, the broad waves or the narrow peak?
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.
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)
rfftof a real signal returns only the non-negative frequencies,n // 2 + 1modes along the last axis.- For each mode
k, the vector of input channelsiis multiplied by a matrix to give output channelso: channels mix, modes do not. 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.
# 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
- 16 modes kept in each direction;
hidden_channelsis the width after the lifting layer. - 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
DeepONet's trunk accepts any query point, though its branch needs the input at the same 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.