nops: Neural Operators made simple — with physics-informed losses for FNO, DeepONet, and GNO
Project description
Neural Operators made simple.
graph LR
subgraph nops_FNO [nops: FNO Architecture]
direction LR
Input["Input<br/>(Batch, C_in, X, Y...)"] --> Grid{Append<br/>Grid?}
Grid -- Yes --> InputGrid[Input + Grid]
Grid -- No --> InputGrid
InputGrid --> Lifting["Lifting Layer<br/>(Projection P)"]
subgraph FourierLayers [Fourier Layers x N]
direction TB
FFT[FFT] --> SpecConv["Spectral Conv<br/>(R * Weights)"]
SpecConv --> iFFT["Inverse FFT"]
iFFT --> Skip{"Skip<br/>Connection"}
Skip --> Attention{"Attention<br/>Gating?"}
Attention -- Yes --> AttnBlock["Attention Weights"]
Attention -- No --> SumBlock["Sum"]
AttnBlock --> OutputLayer
SumBlock --> OutputLayer
end
Lifting --> FourierLayers
FourierLayers --> Projection["Projection Layer<br/>(Q)"]
Projection --> Output["Output<br/>(Batch, C_out, X, Y...)"]
end
A human-centric interface for operating with Neural Operators (FNO, GNO, DeepONet, etc.).
nops is designed to be an elegant, high-level layer over complex neural operator architectures. Whether you are a researcher prototyping a new PDE solver or an engineer deploying a model to production, nops abstracts the complexity while retaining the flexibility you need.
✨ Features
- Human-Friendly API: Intuitive classes and methods that make sense.
- Multi-Dimensional: Seamless support for 1D, 2D, and 3D FNO models.
- Production Ready: Built with modularity, type hinting, and efficiency in mind.
- Batteries Included:
- Attention Gating: Advanced mechanisms to weight parallel Fourier branches.
- Flexible Gridding: Automatic handling of grid coordinates.
- Padding Management: Easy handling of boundary conditions.
📦 Installation
Install nops easily via pip:
pip install nops
Note: Requires Python 3.12+
🚀 Quick Start
Solving a PDE with a Fourier Neural Operator (FNO) has never been this simple.
import torch
import torch.nn as nn
from nops.fno.models.original import FNO
# 1. Define your configuration
model = FNO(
modes=[16, 16], # 16 Fourier modes for height and width
num_fourier_layers=4, # Depth of the network
in_channels=3, # (e.g., u, v, p)
out_channels=1, # (e.g., pressure field)
lifting_channels=64,
projection_channels=64,
mid_channels=64,
activation=nn.GELU(),
add_grid=True, # Auto-append x,y coordinates
attn_gating=True # Enable attention mechanism
)
# 2. Forward pass
# Batch size: 8, Channels: 3, Resolution: 128x128
input_data = torch.randn(8, 3, 128, 128)
output = model(input_data)
print(f"Output Field Shape: {output.shape}")
# > Output Field Shape: torch.Size([8, 1, 128, 128])
🗺️ Roadmap
- FNO (Fourier Neural Operator): Original implementation with attention extensions.
- DeepONet: Implementation of Deep Operator Networks.
- GNO (Graph Neural Operator): Support for irregular meshes.
- Physics-Informed Losses: Built-in loss functions for PDE constraints.
- Data Loaders: Standard datasets (Burgers, Navier-Stokes, Darcy Flow).
🤝 Contributing
We welcome contributions! nops is a community-driven project to make neural operators accessible to everyone.
- Fork the repository.
- Create a Feature Branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
Please ensure your code follows the existing style and includes tests.
📄 License
Distributed under the MIT License. See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nops-0.3.0.tar.gz.
File metadata
- Download URL: nops-0.3.0.tar.gz
- Upload date:
- Size: 505.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cf6858fe205758fec7306ca1e346ad4633fc3d5fc11a02c895aac461534f6e9
|
|
| MD5 |
bb5aea0bf693d802ddf98094b675a0e1
|
|
| BLAKE2b-256 |
ce887b6751970cd3e4a19f01a1e5b07782fbdcce8b84949654156648702cf376
|
Provenance
The following attestation bundles were made for nops-0.3.0.tar.gz:
Publisher:
pypi.yml on abelsr/nops
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nops-0.3.0.tar.gz -
Subject digest:
1cf6858fe205758fec7306ca1e346ad4633fc3d5fc11a02c895aac461534f6e9 - Sigstore transparency entry: 1340216465
- Sigstore integration time:
-
Permalink:
abelsr/nops@b56fbfbaa7cf8d1b6e5634abf004e17e0e6f862a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/abelsr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@b56fbfbaa7cf8d1b6e5634abf004e17e0e6f862a -
Trigger Event:
release
-
Statement type:
File details
Details for the file nops-0.3.0-py3-none-any.whl.
File metadata
- Download URL: nops-0.3.0-py3-none-any.whl
- Upload date:
- Size: 96.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eacf85b7de13177900734c982fbb3b2fde744a1fac42772d79fe95d27b151ce9
|
|
| MD5 |
9fb79ead67ad86aec545ae166f8571a2
|
|
| BLAKE2b-256 |
32f194a8a1a688cc8dbee99986b25c1b2b735c3a15824bb9e6ffcc058c121833
|
Provenance
The following attestation bundles were made for nops-0.3.0-py3-none-any.whl:
Publisher:
pypi.yml on abelsr/nops
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nops-0.3.0-py3-none-any.whl -
Subject digest:
eacf85b7de13177900734c982fbb3b2fde744a1fac42772d79fe95d27b151ce9 - Sigstore transparency entry: 1340216473
- Sigstore integration time:
-
Permalink:
abelsr/nops@b56fbfbaa7cf8d1b6e5634abf004e17e0e6f862a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/abelsr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@b56fbfbaa7cf8d1b6e5634abf004e17e0e6f862a -
Trigger Event:
release
-
Statement type: