SA-PINNs

Model Overview

SA-PINNs (Self-Adaptive Physics-Informed Neural Networks) assign learnable positive attention weights to observation points, boundary points, and PDE collocation points, enabling the model to focus automatically on regions that are difficult to fit during training.

This model package provides examples for the one-dimensional Laplace equation, the two-dimensional Helmholtz equation, and the one-dimensional time-dependent Burgers equation.

Paper: Self-Adaptive Physics-Informed Neural Networks using a Soft Attention Mechanism
https://arxiv.org/abs/2009.04544

Model Description

SA-PINNs use min–max saddle-point optimization: network parameters reduce the weighted physics loss through gradient descent, while attention parameters increase the weights assigned to difficult locations through gradient ascent. The attention weights are constructed from normalized exp(alpha), ensuring that they remain positive with a mean close to 1. The Adam stage updates both the network and attention parameters, whereas the L-BFGS stage freezes the attention parameters and refines the network.

Use Cases

Use Case Description
One-dimensional Laplace equation Examine how attention focuses on collocation points with high residuals
Two-dimensional Helmholtz equation Solve a two-dimensional analytical solution with high-frequency spatial variation
Burgers equation Train jointly on initial conditions, boundary conditions, and nonlinear PDE residuals
Adaptive-weight research Compare a standard PINN with pointwise soft-attention weighting

Usage

1. OneCode

Use the online OneCode environment for an intelligent, one-click AI for Science (AI4S) programming experience:

Launch OneCode for one-click AI4S programming

2. Manual Setup

Hardware Requirements

  • A GPU or DCU is recommended for training.
  • A CPU can be used for small-scale pipeline validation.
  • DCU users must install DTK and a PyTorch environment compatible with the target cluster.

Download the Model Package

hf download OneScience-Group/SA-PINNs --local-dir ./SA-PINNs
cd SA-PINNs

Set Up the Runtime Environment

DCU Environment

# Activate DTK and Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
pip install onescience[cfd-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

GPU Environment

# Activate Conda first
conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
conda activate onescience311
pip install onescience[cfd-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

Training Data

All three examples generate observation points, boundary points, and PDE collocation points from analytical equations and random sampling, with no dependency on external data files. The Burgers example does not include a reference solution and therefore outputs only the predicted field and attention distribution.

Training

Select an example with --case:

python scripts/train.py --case laplace
python scripts/train.py --case helmholtz
python scripts/train.py --case burgers

Checkpoints and training histories are saved to weight/ and result/ by default. Command-line arguments such as --epochs, --lbfgs-iters, --n-pde, and --device can override values in conf/config.yaml.

Model Weights

This repository provides weights trained for all three examples in the weight/ directory.

Inference, Evaluation, and Visualization

After training the selected example, run:

python scripts/inference.py --case laplace
python scripts/inference.py --case helmholtz
python scripts/inference.py --case burgers

Predictions, error plots, and PDE attention distributions are saved to the result/ directory. The Laplace and Helmholtz examples report relative L2 errors. Default model and training parameters can be modified in conf/config.yaml.

Official OneScience Resources

Citations and License

  • McClenny, L. and Braga-Neto, U. Self-Adaptive Physics-Informed Neural Networks using a Soft Attention Mechanism. arXiv:2009.04544, 2020.
  • This model package is released under the Apache-2.0 license and retains attribution to the original paper.

中文说明

模型概览

SA-PINNs 是自适应物理信息神经网络(Self-Adaptive Physics-Informed Neural Networks)。它为观测点、边界点和 PDE 配点分配可学习的正注意力权重,使模型在训练时自动关注难以拟合的区域。

本模型包提供一维 Laplace 方程、二维 Helmholtz 方程及一维时变 Burgers 方程示例。

论文:使用软注意力机制的自适应物理信息神经网络
https://arxiv.org/abs/2009.04544

模型描述

SA-PINNs 使用极小极大鞍点优化。网络参数通过梯度下降减小加权物理损失,注意力参数通过梯度上升增加难拟合位置的权重。注意力权重由归一化的 exp(alpha) 构造,确保权重为正且均值接近 1。Adam 阶段同时更新网络和注意力参数,L-BFGS 阶段冻结注意力参数并进一步优化网络。

使用场景

使用场景 说明
一维 Laplace 方程 观察注意力如何聚焦于残差较高的配点
二维 Helmholtz 方程 求解具有高频空间变化的二维解析解
Burgers 方程 基于初始条件、边界条件和非线性 PDE 残差联合训练
自适应权重研究 比较标准物理信息神经网络与逐点软注意力加权

使用指南

1. OneCode

通过 OneCode 在线环境体验面向科学的人工智能(AI4S)智能一键编程。

启动 OneCode 以使用一键 AI4S 编程

2. 手动配置

硬件要求

  • 建议使用 GPU 或 DCU 训练。
  • 可使用 CPU 进行小规模流程验证。
  • DCU 用户须安装 DTK 及与目标集群兼容的 PyTorch 环境。

下载模型包

hf download OneScience-Group/SA-PINNs --local-dir ./SA-PINNs
cd SA-PINNs

配置运行环境

DCU 环境

# Activate DTK and Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
pip install onescience[cfd-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

GPU 环境

# Activate Conda first
conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
conda activate onescience311
pip install onescience[cfd-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

训练数据

三个示例均通过解析方程和随机采样生成观测点、边界点和 PDE 配点,无需外部数据文件。Burgers 示例未提供参考解,因此仅输出预测场及注意力分布。

训练

通过 --case 选择示例。

python scripts/train.py --case laplace
python scripts/train.py --case helmholtz
python scripts/train.py --case burgers

模型权重(检查点)(checkpoint)及训练历史默认保存到 weight/ 和 result/。--epochs、--lbfgs-iters、--n-pde 和 --device 等命令行参数可覆盖 conf/config.yaml 中的值。

模型权重

本仓库在 weight/ 目录中提供三个示例的训练权重。

推理(inference)、评估与可视化

训练选定示例后,执行以下命令。

python scripts/inference.py --case laplace
python scripts/inference.py --case helmholtz
python scripts/inference.py --case burgers

预测结果、误差图及 PDE 注意力分布保存到 result/ 目录。Laplace 和 Helmholtz 示例报告相对 L2 误差。可在 conf/config.yaml 中修改默认模型及训练参数。

OneScience 官方资源

引用与许可证

  • McClenny, L. and Braga-Neto, U. Self-Adaptive Physics-Informed Neural Networks using a Soft Attention Mechanism. arXiv:2009.04544, 2020.
  • 本模型包采用 Apache-2.0 许可证发布,并保留原始论文的署名。
Downloads last month
19
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Paper for OneScience-Group/SA-PINNs