?一、軟件介紹
文末提供程序和源碼下載
PINA 是一個開源 Python 庫,旨在簡化和加速科學機器學習 (SciML) 解決方案的開發。PINA 基于 PyTorch、PyTorch Lightning 和 PyTorch Geometry 構建,提供了一個直觀的框架,用于使用神經網絡、物理信息神經網絡 (PINN)、神經運算符等定義、試驗和解決復雜問題
-
Modular Architecture: Designed with modularity in mind and relying on powerful yet composable abstractions, PINA allows users to easily plug, replace, or extend components, making experimentation and customization straightforward.
模塊化架構:PINA 在設計時考慮了模塊化,并依賴于強大但可組合的抽象,允許用戶輕松插入、替換或擴展組件,使實驗和定制變得簡單明了。 -
Scalable Performance: With native support for multi-device training, PINA handles large datasets efficiently, offering performance close to hand-crafted implementations with minimal overhead.
可擴展的性能:憑借對多設備訓練的原生支持,PINA 可以高效處理大型數據集,以最小的開銷提供接近手工構建的性能。 -
Highly Flexible: Whether you're looking for full automation or granular control, PINA adapts to your workflow. High-level abstractions simplify model definition, while expert users can dive deep to fine-tune every aspect of the training and inference process.
高度靈活:無論您是在尋找完全自動化還是精細控制,PINA 都能適應您的工作流程。高級抽象簡化了模型定義,而專家用戶可以深入研究以微調訓練和推理過程的各個方面。
二、Installation?安裝
Installing a stable PINA release
安裝穩定的 PINA 版本
Install using pip:?使用 pip 安裝:
pip install "pina-mathlab"
Install from source:?從源碼安裝:
git clone https://github.com/mathLab/PINA
cd PINA
git checkout master
pip install .
Install with extra packages:
使用額外的軟件包進行安裝:
To install extra dependencies required to run tests or tutorials directories, please use the following command:
要安裝運行 tests 或 tutorials 目錄所需的額外依賴項,請使用以下命令:
pip install "pina-mathlab[extras]"
Available extras include:
可用的額外服務包括:
dev
?for development purpuses, use this if you want to?Contribute.
dev
?對于開發目的,如果您想要 貢獻,請使用此項。test
?for running test locally.
test
?用于在本地運行 TEST。doc
?for building documentation locally.
doc
?用于本地構建文檔。tutorial
?for running?Tutorials.
tutorial
?用于運行 Tutorials。
三、Quick Tour for New Users新用戶快速導覽
Solving a differential problem in?PINA?follows the?four steps pipeline:
在 PINA 中求解差分問題遵循四個步驟 pipeline:
-
Define the problem to be solved with its constraints using the?Problem API.
使用 Problem API 定義要解決的問題及其約束。 -
Design your model using PyTorch, or for graph-based problems, leverage PyTorch Geometric to build Graph Neural Networks. You can also import models directly from the?Model API.
使用 PyTorch 設計模型,或者對于基于圖形的問題,利用 PyTorch Geometric 構建圖形神經網絡。您還可以直接從 Model API 導入模型。 -
Select or build a Solver for the Problem, e.g., supervised solvers, or physics-informed (e.g., PINN) solvers.?PINA Solvers?are modular and can be used as-is or customized.
為問題選擇或構建求解器,例如,監督式求解器或物理信息(例如 PINN)求解器。PINA 求解器是模塊化的,可以按原樣使用或自定義使用。 -
Train the model using the?Trainer API?class, built on PyTorch Lightning, which supports efficient, scalable training with advanced features.
使用基于 PyTorch Lightning 構建的 Trainer API 類訓練模型,該類支持具有高級功能的高效、可擴展訓練。
Do you want to learn more about it? Look at our?Tutorials.
您想了解更多相關信息嗎?查看我們的教程。
四、Solve Data Driven Problems解決數據驅動的問題
Data driven modelling aims to learn a function that given some input data gives an output (e.g. regression, classification, ...). In PINA you can easily do this by:
數據驅動建模旨在學習給定一些輸入數據給出輸出的函數(例如回歸、分類等)。在 PINA 中,您可以通過以下方式輕松做到這一點:
from pina import Trainer
from pina.model import FeedForward
from pina.solver import SupervisedSolver
from pina.problem.zoo import SupervisedProbleminput_tensor = torch.rand((10, 1))
output_tensor = input_tensor.pow(3)# Step 1. Define problem
problem = SupervisedProblem(input_tensor, target_tensor)
# Step 2. Design model (you can use your favourite torch.nn.Module in here)
model = FeedForward(input_dimensions=1, output_dimensions=1, layers=[64, 64])
# Step 3. Define Solver
solver = SupervisedSolver(problem, model)
# Step 4. Train
trainer = Trainer(solver, max_epochs=1000, accelerator='gpu')
trainer.train()
Solve Physics Informed Problems
解決 Physics Informed 問題
Physics-informed modeling aims to learn functions that not only fit data, but also satisfy known physical laws, such as differential equations or boundary conditions. For example, the following differential problem:
基于物理場的建模旨在學習不僅擬合數據,而且滿足已知物理定律(例如微分方程或邊界條件)的函數。例如,以下 differential 問題:
{����(�)=�(�)�∈(0,1)�(�=0)=1
in PINA, can be easily implemented by:
在 PINA 中,可以通過以下方式輕松實現:
from pina import Trainer, Condition
from pina.problem import SpatialProblem
from pina.operator import grad
from pina.solver import PINN
from pina.model import FeedForward
from pina.domain import CartesianDomain
from pina.equation import Equation, FixedValuedef ode_equation(input_, output_):u_x = grad(output_, input_, components=["u"], d=["x"])u = output_.extract(["u"])return u_x - u# build the problem
class SimpleODE(SpatialProblem):output_variables = ["u"]spatial_domain = CartesianDomain({"x": [0, 1]})domains = {"x0": CartesianDomain({"x": 0.0}),"D": CartesianDomain({"x": [0, 1]}),}conditions = {"bound_cond": Condition(domain="x0", equation=FixedValue(1.0)),"phys_cond": Condition(domain="D", equation=Equation(ode_equation)),}# Step 1. Define problem
problem = SimpleODE()
# Step 2. Design model (you can use your favourite torch.nn.Module in here)
model = FeedForward(input_dimensions=1, output_dimensions=1, layers=[64, 64])
# Step 3. Define Solver
solver = PINN(problem, model)
# Step 4. Train
trainer = Trainer(solver, max_epochs=1000, accelerator='gpu')
trainer.train()
五、Application Programming Interface
應用程序編程接口
Here's a quick look at PINA's main module. For a better experience and full details, check out the?documentation.
以下是 PINA 的主模塊的快速瀏覽。要獲得更好的體驗和完整的詳細信息,請查看文檔。
五、軟件下載
迅雷云盤
本文信息來源于GitHub作者地址:https://github.com/mathLab/PINA