Neural Functional: Learning Function to Scalar Maps for Neural PDE Surrogates

Anthony Y. Zhou, Amir Barati Farimani

Abstract

Designing neural networks within a Hamiltonian framework offers a principled way to ensure that conservation laws are respected in physical systems. While promising, these capabilities have been largely limited to discrete, analytically solvable systems. In contrast, many physical phenomena are governed by PDEs, which govern infinite-dimensional fields through Hamiltonian functionals and their functional derivatives. Building on prior work, we represent the Hamiltonian functional as a kernel integral parameterized by a neural field, enabling learnable function-to-scalar mappings and the use of automatic differentiation to calculate functional derivatives. This allows for an extension of Hamiltonian mechanics to neural PDE solvers by predicting a functional and learning in the gradient domain. We show that the resulting Hamiltonian Neural Solver (HNS) can be an effective surrogate model through improved stability and conserving energy-like quantities across 1D and 2D PDEs. This ability to respect conservation laws also allows HNS models to better generalize to longer time horizons or unseen initial conditions.

Introduction

Most modern neural PDE solvers, such as Fourier Neural Operators (FNO) or U-Nets, operate within a "Newtonian" framework. They are typically trained to predict the next state of a system or its time derivative directly from data. While these models are powerful, they often lack a fundamental understanding of the underlying physics. Consequently, they frequently "drift" over time, violating basic conservation laws like the conservation of energy, mass, or momentum.

In classical mechanics, Hamiltonian mechanics provides a principled way to ensure these laws are respected by describing a system's evolution based on its total energy (the Hamiltonian). However, applying this to PDEs is challenging. Unlike discrete systems, PDEs describe continuous fields which are infinite-dimensional. Mapping a continuous field to a single scalar energy value—and then calculating the functional derivative of that mapping—presents a significant mathematical and architectural challenge for deep learning.

Methodology

The Hamiltonian Neural Solver (HNS) bridges the gap between Hamiltonian mechanics and deep learning through functional approximation. The core of the approach relies on three main components:

1. Integral Kernel Functionals (IKF)

Instead of a standard feed-forward map, the Hamiltonian $H[u]$ is represented as an integral: $$H_\theta[u] = \int_\Omega \kappa_\theta(x, u(x)) u(x) dx$$ This structure allows the model to map an entire input field $u$ to a single scalar energy value. This approximation is visualized in the architecture overview below.

Overview of the HNS architecture, illustrating the Integral Kernel Functional (IKF) approximation and the SIREN-based kernel parameterization.

2. Neural Field Kernels and Conditioning

The kernel $\kappa_\theta$ is parameterized using a Sinusoidal Representation Network (SIREN). SIRENs use periodic activation functions, which are exceptionally good at representing complex functions and providing well-behaved, high-quality derivatives. To allow the kernel to adapt based on local or global information about the field, the authors use Feature-wise Linear Modulation (FiLM), enabling the model to handle non-local interactions.

3. Hamilton’s Equations and Training

The system's evolution is defined by Hamilton's equations for PDEs: $$\frac{\partial u}{\partial t} = \mathcal{J} \frac{\delta H}{\delta u}$$ Here, $\frac{\delta H}{\delta u}$ is the functional derivative calculated via automatic differentiation, and $\mathcal{J}$ is a symplectic operator. The training process involves optimizing the parameters $\theta$ in the gradient domain, as detailed in Algorithm 1.

The training algorithm for HNS, highlighting the use of autograd for functional derivatives and the loss function in the gradient domain.

Experimental Evaluation

The researchers evaluated HNS across several physical systems, focusing on stability and out-of-distribution (OOD) generalization:

  • 1D Advection: A simple linear wave equation used as a baseline.
  • 1D KdV (Korteweg–De Vries): A complex, nonlinear, dispersive PDE describing shallow water waves, highly sensitive to numerical errors.
  • 2D Shallow Water Equations (SWE): A system used in atmospheric and oceanic modeling.

Models were specifically tested on unseen initial conditions (e.g., training on sine waves but testing on Gaussian pulses) and longer time horizons than those seen during training.

Key Results and Insights

  • Superior Stability: In 1D KdV experiments, HNS achieved a correlation time of 151.1, more than double that of a standard FNO (68.0). While other models' energy drifted or exploded, the HNS Hamiltonian remained nearly constant.
  • OOD Generalization: On the 2D SWE, HNS outperformed baselines significantly on unseen "Pulse" initial conditions, achieving an error of 0.021 compared to 0.117 for FNO.
  • Implicit Conservation: Remarkably, HNS models conserve energy-like quantities even without explicit constraints in the loss function. The architectural choice itself enforces this behavior.
  • Discretization Invariance: Because the Hamiltonian is defined as a continuous integral kernel, the model can be queried at different spatial resolutions (zero-shot super-resolution) without retraining.

Conclusion and Future Work

HNS demonstrates that forcing a model to operate within a Hamiltonian framework provides a powerful inductive bias. The model learns an energy surface, and the physics emerges from the gradient of that surface.

Current limitations include the focus on conservative systems (excluding dissipative systems with friction) and the computational overhead of calculating functional derivatives during every integration step. Future work may involve learning the symplectic operator $\mathcal{J}$ alongside the Hamiltonian to create a fully data-driven solver.

Summary updated

BibTeX
@inproceedings{zhou2025neural,
  author = {Anthony Y. Zhou and Amir Barati Farimani},
  title = {{Neural Functional: Learning Function to Scalar Maps for Neural PDE Surrogates}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=XFzDI9CPUm},
}
Figure