A PyTorch implementation for learning Physical Operators using Neural Operators within a Neural-ODE framework for solving Partial Differential Equations through operator splitting of linear and nonlinear terms.
This repository implements the novel approach described in "Learning Physical Operators using Neural Operators" where we decompose PDE solving by splitting linear and nonlinear operators, learning each component separately using Neural Operators, then integrating them through time using ODE solvers.
Traditional Neural-PDE solvers approximate the entire right-hand side of a PDE with a single neural network. Our approach instead:
- Splits PDEs into linear and nonlinear operator components
- Learns each operator type separately using specialized Neural Operators
- Provides classical finite difference approximations for linear operators via convolution
- Integrates through time using operator splitting schemes and ODE solvers
For example, the Navier-Stokes equation:
βu/βt = -(uΒ·β)u + Ξ½βΒ²u - βp
becomes:
du/dt = NO_nonlinear(u) + NO_linear(u) + NO_pressure(u)
= -NO_convection(u) + Ξ½Β·laplace(u) - gradient(p)
Where:
- Linear operators: Diffusion (βΒ²u), Pressure gradient (βp) - can use finite difference stencils
- Nonlinear operators: Convection ((uΒ·β)u), Advection terms - require neural learning
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Input u_n β -> β Operator β -> β Time β
β β β Splitting β β Integration β
β β β (Linear/Nonlin) β β (ODE Solver) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββΌββββββββββ
β β β
βββββββββββΌβββ ββββββΌβββββ ββββΌββββββββββ
β Nonlinear β β Linear β β Coupling β
β Operators β βOperatorsβ β Terms β
β (Neural) β β(FD/ β β β
β β β Neural)β β β
ββββββββββββββ βββββββββββ ββββββββββββββ
β β β
ββββββββββββΌββ βββββββββΌβββ ββββββΌβββββ
βNO_convect β βFD_diffuseβ βNO_press β
βNO_advect β βFD_laplaceβ βFD_grad β
βNO_reactive β βNO_linear β βNO_force β
ββββββββββββββ ββββββββββββ βββββββββββ
- Linear/Nonlinear Operator Splitting: Separates physics-based operator types
- Hybrid Learning Approach: Neural operators for complex terms, finite differences for linear terms
- Physical Residual Estimation (PRE): Classical stencil-based operator approximations
- Multiple Neural Operators: Support for FNO, CNO, U-Net, ConvNets optimized for operator type
- Time Integration: Euler, Midpoint, RK4 along with their adjoint versions
- Physics-Informed: Maintains mathematical structure and stability properties
- Multiple PDEs: Navier-Stokes, Euler, reaction-diffusion, MHD, and more
βββ Expts/ # Experiment scripts
β βββ Train.py # Main training pipeline
β βββ Evaluate.py # Model evaluation
β βββ Solve.py # Handcrafted solver comparison
β βββ data_loaders.py # Data loading utilities
β βββ model_setup.py # Model initialization
β βββ operator_splitting.py # Linear/nonlinear operator splitting
βββ PRE/ # Physical Residual Estimation
β βββ ConvOps_Spatial.py # Finite difference as convolution
β βββ VectorConvOps_Spatial.py # Vector field FD operations
β βββ Stencils.py # FD stencils (2nd to 10th order)
β βββ boundary_conditions.py # Boundary condition handling
β βββ fft_conv_pytorch/ # Efficient convolution implementations
βββ Utils/ # Utilities
β βββ explicit_time.py # Explicit time stepping
β βββ torch_odesolve.py # Neural-ODE integration
β βββ plots.py # Visualization tools
β βββ metrics.py # Performance metrics
βββ configs/ # Configuration files
git clone https://github.com/yourusername/NOs_for_POs.git
cd NOs_for_POs
git submodule init
git submodule update
# Install dependencies
pip install torch torchvision
pip install simvue # For experiment tracking (optional)
pip install torchdiffeq # For Neural-ODE integration
pip install scikit-learn
pip install einops neuraloperator
pip install tqdm matplotlib h5py pyyaml h5pycd Expts
python Train.py --config configs/NS_linear_nonlinear_split.yaml# Set the run name from your training
run_name = 'your-trained-model-name'
python Evaluate.pyCreate a YAML config file:
Physics:
pde: 'Navier-Stokes'
variables: 2
field: 'u, v'
Model:
arch: 'FNO'
operator splitting: true
split_type: 'linear_nonlinear' # New: specify splitting strategy
# Linear operator configuration
linear_operators:
method: 'finite_difference' # or 'neural'
taylor_order: 4 # FD accuracy order
boundary_cond: 'periodic' # or 'dirichlet', 'neumann'
# Nonlinear operator configuration
nonlinear_operators:
arch: 'CNO' # Better for local, complex interactions
modes: 8
width: 64
Train:
odesolve:
method: 'imex_euler' # Implicit-Explicit for stiff problems
source: 'custom'
rollout_length: 20
hybrid_training: true # FD for linear, Neural for nonlinearPRE (Physical Residual Estimation) Approach: Linear differential operators can be exactly represented using finite difference stencils implemented as convolutions.
from PRE.ConvOps_Spatial import ConvOperator
from PRE.VectorConvOps_Spatial import Laplace, Gradient, Divergence
# Finite difference Laplacian as convolution
laplacian = ConvOperator(domain=('x','y'), order=2, scale=1/dx**2,
taylor_order=4, boundary_cond='periodic')
# Vector operations for fluid dynamics
gradient = Gradient(scale=1/dx, taylor_order=4, boundary_cond='periodic')
divergence = Divergence(scale=1/dx, taylor_order=4, boundary_cond='periodic')
laplace_vector = Laplace(scale=1/dx**2, taylor_order=4, scalar=False)
# Usage in physics
def linear_operators_fd(u, p):
diffusion = laplace_vector(u) # Ξ½βΒ²u
pressure_grad = gradient(p) # βp
return diffusion, pressure_gradAvailable Finite Difference Stencils:
- 2nd to 10th order accuracy: Higher order for better spectral properties
- Multiple boundary conditions: Periodic, Dirichlet, Neumann, symmetric
- Optimized implementations: FFT-based convolution for large kernels
class HybridLinearOperators(nn.Module):
def __init__(self, config):
# Base finite difference operators
self.fd_laplacian = ConvOperator(domain=('x','y'), order=2, ...)
self.fd_gradient = Gradient(...)
# Neural correction for complex geometries/coefficients
self.neural_correction = FNO_multi2d(...)
def forward(self, u):
fd_result = self.nu * self.fd_laplacian(u)
correction = self.neural_correction(u)
return fd_result + correction # FD + learned residualCharacteristics: Local interactions, sharp gradients, potentially unstable Examples: Convection, Reaction terms, Shock formation Optimal Networks:
- CNO: Better for local, sharp features
- U-Net: Good for multi-scale nonlinear interactions
- ConvNets: Efficient for local nonlinear operations
# Nonlinear operator example
class NonlinearOperators(nn.Module):
def __init__(self, config):
self.convection = CNO2d(...) # (uΒ·β)u
self.reaction = UNet2d(...) # f(u,v) reaction terms
def forward(self, u):
return -self.convection(u) + self.reaction(u)Located in PRE/Stencils.py:
# 2nd order Laplacian stencil
stencil_2nd = tensor([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])
# 4th order Laplacian stencil
stencil_4th = tensor([[0, 0, -1/12, 0, 0],
[0, 0, 4/3, 0, 0],
[-1/12, 4/3, -5, 4/3, -1/12],
[0, 0, 4/3, 0, 0],
[0, 0, -1/12, 0, 0]])Located in PRE/boundary_conditions.py:
# Flexible boundary condition manager
bc_manager = BoundaryManager(kernel_size=(5, 5))
bc_manager.set_boundary_type('left', 'periodic')
bc_manager.set_boundary_type('right', 'dirichlet', value=0.0)
bc_manager.set_boundary_type('top', 'neumann') # Zero gradient
bc_manager.set_boundary_type('bottom', 'symmetric') # ReflectionLocated in PRE/VectorConvOps_Spatial.py:
# Complete set of vector calculus operations
from PRE.VectorConvOps_Spatial import Gradient, Divergence, Curl, Laplace
# Navier-Stokes using finite difference
def navier_stokes_fd(u, v, p, nu=0.01):
# Nonlinear convection (would be learned)
convection = dot(vectorize(u, v), gradient(u)), dot(vectorize(u, v), gradient(v))
# Linear diffusion (finite difference)
diffusion = nu * laplace_vector(u, v)
# Pressure gradient (finite difference)
pressure_grad = gradient(p)
return -convection + diffusion - pressure_grad- Exact linear operators: No approximation error for linear terms
- Efficient computation: Convolution operations are highly optimized
- Reduced learning complexity: Only nonlinear terms need neural approximation
- Memory efficient: Fixed stencils vs learned parameters
- Conservation properties: FD stencils preserve discrete conservation laws
- Spectral accuracy: High-order stencils maintain correct dispersion relations
- Stability guarantees: Well-understood stability conditions for linear terms
- Boundary condition accuracy: Proper treatment of complex boundaries
- Faster convergence: Reduced parameter space for learning
- Better generalization: Physics-based inductive bias for linear operators
- Interpretability: Clear separation of known vs learned physics
- Transfer learning: FD operators transfer across problems
# Pure finite difference linear operators
python Train.py --config configs/NS_hybrid_FD_neural.yaml
# Comparison: FD vs Neural vs Hybrid
python compare_operators.py --linear_method fd --nonlinear_method neural
# Accuracy vs efficiency trade-offs
python efficiency_study.py --fd_order 2,4,6,8 --neural_width 16,32,64# Test FD operator accuracy
cd PRE
python test_fd_operators.py --taylor_order 2,4,6,8 --boundary periodic
# Convergence analysis
python convergence_test.py --operator laplacian --orders 2,4,6,8,10Our hybrid FD + Neural approach demonstrates:
- Computational Efficiency: 5-10x faster than pure neural for linear operators
- Enhanced Accuracy: Exact representation of linear physics
- Better Stability: Provable stability for finite difference components
- Reduced Training Time: 3-5x faster convergence with hybrid approach
- Improved Generalization: Better extrapolation due to exact linear operators
- Conservation Properties: Discrete conservation laws automatically satisfied
If you use this code in your research, please cite:
@article{gopakumar2024learning,
title={Learning Physical Operators using Neural Operators: Hybrid Finite Difference and Neural Approach},
author={Gopakumar, Vignesh},
journal={arXiv preprint},
year={2024}
}We welcome contributions! Please:
- Fork the repository
- Create a feature branch focusing on operator splitting improvements
- Add tests for stability and accuracy
- Submit a pull request
Areas of particular interest:
- New finite difference stencils for complex operators
- Advanced boundary condition implementations
- Novel hybrid FD + Neural architectures
- High-order accurate schemes
- Adaptive mesh refinement integration
This project is licensed under the MIT License - see the LICENSE file for details.
- Fourier Neural Operator
- Finite Difference Methods
- Physics-Informed Neural Networks
- Operator Splitting
- Neural ODEs
- Author: Vignesh Gopakumar
- Email: v.gopakumar@ucl.ac.uk, vignesh.gopakumar@ukaea.uk
- Affiliation: UKAEA / UCL / Simvue
This work was supported by UKAEA and UCL. Special thanks to the Simvue team for experiment tracking infrastructure, the numerical analysis community for finite difference theory, and the scientific computing community for convolution optimization techniques.
Note: This is research code under active development with focus on hybrid finite difference and neural operator methods. For production use, please contact the authors.