Skip to main content

nops: Neural Operators made simple — with physics-informed losses for FNO, DeepONet, and GNO

Project description

nops logo

Neural Operators made simple.

PyPI version Python License: MIT Code Style: Black

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.

  1. Fork the repository.
  2. Create a Feature Branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. 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.


Built with ❤️ by the nops community.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nops-0.2.0.tar.gz (480.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nops-0.2.0-py3-none-any.whl (57.3 kB view details)

Uploaded Python 3

File details

Details for the file nops-0.2.0.tar.gz.

File metadata

  • Download URL: nops-0.2.0.tar.gz
  • Upload date:
  • Size: 480.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nops-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7781787e553836c7ddbbd9ce2613e7f9632050d3b08cea63543a34ca236b74c0
MD5 48c32a44728bde22d9970ab501b29f87
BLAKE2b-256 b39bfe8c20f3693ee6d03dcbd412b81189be070f5db8dec3684590a499bb5941

See more details on using hashes here.

Provenance

The following attestation bundles were made for nops-0.2.0.tar.gz:

Publisher: pypi.yml on abelsr/nops

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nops-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nops-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 57.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nops-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bd7cb91338bac7db3c742ff34f5b5a8872cf6c710c467594e6efb89a0265fad
MD5 55c3820db476ccd07265484f4f39ce4d
BLAKE2b-256 8b32dd508b206debb9bc5f487df01d3eea34ef4c2d4dcafca691ce5b60cea4af

See more details on using hashes here.

Provenance

The following attestation bundles were made for nops-0.2.0-py3-none-any.whl:

Publisher: pypi.yml on abelsr/nops

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page