Skip to main content

FBPINN with automatic domain decomposition

Project description

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.

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

geofbpinn-0.1.1.tar.gz (39.6 kB view details)

Uploaded Source

Built Distribution

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

geofbpinn-0.1.1-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file geofbpinn-0.1.1.tar.gz.

File metadata

  • Download URL: geofbpinn-0.1.1.tar.gz
  • Upload date:
  • Size: 39.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for geofbpinn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9421638905b6f484d810be0275f93cfb8685f414d4d9a2ae90a27030be790407
MD5 c51477f337158817509e0f031b1bb33e
BLAKE2b-256 e109a7e5abfacfa313bb90e6506855e686bbe7a15530ea63310b3919ce6d5c09

See more details on using hashes here.

File details

Details for the file geofbpinn-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: geofbpinn-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 41.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for geofbpinn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c155f153bf56ea7b1a6721362fbce54f1d6cf4ca58812662378002e9143d282
MD5 de960407e645474672443ab24147881e
BLAKE2b-256 1aeb2a6c53019b0fd7d8d47b840e220e8c7ae758e158a2f47b8d9449b7fb42b4

See more details on using hashes here.

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