Skip to main content

Check code style Run tests

FBPINN

FBPINNs are described in detail here: Finite Basis Physics-Informed Neural Networks (FBPINNs): a scalable domain decomposition approach for solving differential equations, B. Moseley, T. Nissen-Meyer and A. Markham, Jul 2023 Advances in Computational Mathematics.

See the original repository.

GeoFBPINN

FBPINN with automatic domain decomposition. Supports N-dimensional rectangular domains and arbitrary 2D polygon domains (including holes).


Requirements

  • Python 3.10+
  • PyTorch 2.8+

Installation

pip install geofbpinn

Or from source:

git clone https://github.com/Krekep/FBPINN.git
cd FBPINN
pip install -e .

For development tools (pytest, black, pre-commit):

pip install -e ".[dev]"

Usage

More examples look in ./examples/.

1. Define domain decomposition

Rectangular N-dimensional domain:

from geofbpinn.geometry.base_decomposition import RectangleDomain
from geofbpinn.geometry.decomposition import DecompositionND

domain = RectangleDomain(left_corner=[0.0, 0.0], right_corner=[1.0, 1.0])

decomp = DecompositionND(
    domain=domain,
    bbox_left=[0.0, 0.0],
    bbox_right=[1.0, 1.0],
    overlap=[0.1, 0.1],
    block_size=[0.4, 0.4],
    block_scales=[1.0, 1.0],
    block_shift=[0.0, 0.0],
    points_per_block=200,
    device="cuda",
)

2D polygon domain (with optional holes):

from geofbpinn.geometry.polygon_decomposition import Decomposition2DPolygon

polygon = [(0, 0), (1, 0), (1, 1), (0, 1)]
hole    = [(0.3, 0.3), (0.7, 0.3), (0.7, 0.7), (0.3, 0.7)]

decomp = Decomposition2DPolygon(
    polygon_vertices=polygon,
    bbox_left=(0.0, 0.0),
    bbox_right=(1.0, 1.0),
    block_scales=[1.0, 1.0],
    block_shift=[0.0, 0.0],
    block_size=(0.4, 0.4),
    overlap=(0.1, 0.1),
    points_per_block=200,
    holes=[hole],
    device="cuda",
)

# Optionally remove blocks fully covered by neighbours
decomp.remove_redundant_blocks(samples_per_block=400, tol=0.01)

2. Build and train FBPINN

import torch
from geofbpinn.networks.topology.fbpinn.model import FBPINN
from geofbpinn.networks.topology.fbpinn.fbpinn_train import layer_train
from geofbpinn.networks.schedulers.layer import BaseLayerScheduler
from geofbpinn.networks.schedulers.loss import LossScheduler

def pde_loss(fbpinn, data, active_models):
    # residual of your PDE
    ...

def bc_loss(fbpinn, data, active_models):
    # boundary condition residual
    ...

bc_polygon = [(0, 0), (1, 0), (1, 0.01), (0, 0.01)]  # bottom edge

model = FBPINN(
    input_size=2,
    output_size=1,
    decomposition=decomp,
    physic_loss=pde_loss,
    boundary_loss=[(bc_loss, bc_polygon)],
    activation_func="tanh",
    models_size=[32, 32],
    device="cuda",
)

layer_train(
    fbpinn=model,
    epochs=5000,
    val_input=val_x,
    val_truth=val_y,
    layer_scheduler=BaseLayerScheduler(...),
    loss_scheduler=LossScheduler(...),
    path_to_ckpt="checkpoints/",
    log_interval=500,
)

Training is tracked automatically via MLflow. Start the UI with:

mlflow ui

Project structure

geofbpinn/
├── geometry/
│   ├── base_decomposition.py      # Block, RectangleDomain, BaseDecomposition
│   ├── decomposition.py           # DecompositionND
│   ├── polygon_decomposition.py   # Decomposition2DPolygon, PolygonBlock
│   ├── geometry.py                # Polygon utilities (clip, area, sampling)
│   └── plot.py                    # Decomposition visualisation
└── networks/
    ├── topology/fbpinn/
    │   ├── model.py               # FBPINN
    │   ├── fbpinn_train.py
    │   └── trainer.py             # Main train function
    ├── schedulers/                # Layer, loss, LR schedulers
    ├── layers/dense.py
    ├── activations.py
    ├── optimizers.py
    ├── metrics.py
    └── losses.py

License

Apache-2.0. See LICENSE.

Metadata

Release files for geofbpinn 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geofbpinn 0.1.1
File Size Uploaded
geofbpinn-0.1.1.tar.gz 39.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for geofbpinn 0.1.1
File Interpreter ABI Platform
geofbpinn-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 80.9 kB

Release files / geofbpinn-0.1.1.tar.gz

Download URL geofbpinn-0.1.1.tar.gz
Size 39.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9421638905b6f484d810be0275f93cfb8685f414d4d9a2ae90a27030be790407
BLAKE2b-256 checksum
How to use checksums
e109a7e5abfacfa313bb90e6506855e686bbe7a15530ea63310b3919ce6d5c09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / geofbpinn-0.1.1-py3-none-any.whl

Download URL geofbpinn-0.1.1-py3-none-any.whl
Size 41.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c155f153bf56ea7b1a6721362fbce54f1d6cf4ca58812662378002e9143d282
BLAKE2b-256 checksum
How to use checksums
1aeb2a6c53019b0fd7d8d47b840e220e8c7ae758e158a2f47b8d9449b7fb42b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page