Skip to content

Commit

Permalink
Merge branch 'develop' into hackthon5th60_2
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiminzhang0830 committed Dec 21, 2023
2 parents c191b2c + 5b56a81 commit 7f979e3
Show file tree
Hide file tree
Showing 51 changed files with 4,875 additions and 176 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
| 飞行器设计 | [MeshGraphNets](https://aistudio.baidu.com/projectdetail/5322713) | 数据驱动 | GNN | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/184320) | [Paper](https://arxiv.org/abs/2010.03409)|
| 飞行器设计 | [火箭发动机真空羽流](https://aistudio.baidu.com/projectdetail/4486133) | 数据驱动 | CNN | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/167250) | - |
| 飞行器设计 | [Deep-Flow-Prediction](https://aistudio.baidu.com/projectdetail/5671596) | 数据驱动 | TurbNetG | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/197778) | [Paper](https://arxiv.org/abs/1810.08217) |
| 通用流场模拟 | [气动外形设计](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/amgnet/) | 数据驱动 | AMGNet | 监督学习 | [Data](https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip) | [Paper](https://arxiv.org/abs/1810.08217) |
| 流固耦合 | [涡激振动](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/viv) | 机理驱动 | MLP | 半监督学习 | [Data](https://github.com/PaddlePaddle/PaddleScience/blob/develop/examples/fsi/VIV_Training_Neta100.mat) | [Paper](https://arxiv.org/abs/2206.03864)|
| 多相流 | [气液两相流](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/bubble) | 机理驱动 | BubbleNet | 半监督学习 | [Data](https://paddle-org.bj.bcebos.com/paddlescience/datasets/BubbleNet/bubble.mat) | [Paper](https://pubs.aip.org/aip/adv/article/12/3/035153/2819394/Predicting-micro-bubble-dynamics-with-semi-physics)|
| 多相流 | [twophasePINN](https://aistudio.baidu.com/projectdetail/5379212) | 机理驱动 | MLP | 无监督学习 | - | [Paper](https://doi.org/10.1016/j.mlwa.2021.100029)|
Expand Down Expand Up @@ -88,6 +89,8 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
<!-- --8<-- [start:update] -->
## 🕘最近更新

- 添加多目标优化算法 [Relobralo](https://paddlescience-docs.readthedocs.io/zh/latest/zh/api/loss/mtl/#ppsci.loss.mtl.Relobralo)
- 添加气泡流求解案例([Bubble](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/bubble/))、机翼优化案例([DeepCFD](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/deepcfd/))、热传导仿真案例([HeatPINN](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/heat_pinn/))、非线性短临预报模型([Nowcasting(仅推理)](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/nowcastnet))、拓扑优化案例([TopOpt](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/topopt))、矩形平板线弹性方程求解案例([Biharmonic2D](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/biharmonic2d))。
- 添加二维血管案例([LabelFree-DNN-Surrogate](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/labelfree_DNN_surrogate/#4))、空气激波案例([ShockWave](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/shock_wave/))、去噪网络模型([DUCNN](https://github.com/PaddlePaddle/PaddleScience/tree/develop/jointContribution/DU_CNN))、风电预测模型([Deep Spatial Temporal](https://github.com/PaddlePaddle/PaddleScience/tree/develop/jointContribution/Deep-Spatio-Temporal))、域分解模型([XPINNs](https://github.com/PaddlePaddle/PaddleScience/tree/develop/jointContribution/XPINNs))、积分方程求解案例([Volterra Equation](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/volterra_ide/))、分数阶方程求解案例([Fractional Poisson 2D](https://github.com/PaddlePaddle/PaddleScience/blob/develop/examples/fpde/fractional_poisson_2d.py))。
- 针对串联方程和复杂方程场景,`Equation` 模块支持基于 [sympy](https://docs.sympy.org/dev/tutorials/intro-tutorial/intro.html) 的符号计算,并支持和 python 函数混合使用([#507](https://github.com/PaddlePaddle/PaddleScience/pull/507)[#505](https://github.com/PaddlePaddle/PaddleScience/pull/505))。
- `Geometry` 模块和 `InteriorConstraint``InitialConstraint` 支持计算 SDF 微分功能([#539](https://github.com/PaddlePaddle/PaddleScience/pull/539))。
Expand All @@ -102,7 +105,7 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
- 支持物理机理驱动、数据驱动、数理融合三种问题求解方式。涵盖流体、结构、气象等领域 20+ 案例。
- 支持结果可视化输出与日志结构化保存。
- 完善的 type hints,用户使用和代码贡献全流程文档,经典案例 AI studio 快速体验,降低使用门槛,提高开发效率。
- 支持基于 sympy 符号计算库的方程表示
- 支持基于 sympy 符号计算库的方程表示与联立方程组计算
- 更多特性正在开发中...
<!-- --8<-- [end:feature] -->

Expand Down Expand Up @@ -212,6 +215,7 @@ PaddleScience 作为一个开源项目,欢迎来各行各业的伙伴携手共
[Gxinhu](https://github.com/Gxinhu)
[XYM](https://github.com/XYM)
[xusuyong](https://github.com/xusuyong)
[DrownFish19](https://github.com/DrownFish19)
[NKNaN](https://github.com/NKNaN)
[ruoyunbai](https://github.com/ruoyunbai)
[sanbuphy](https://github.com/sanbuphy)
Expand All @@ -224,7 +228,7 @@ PaddleScience 作为一个开源项目,欢迎来各行各业的伙伴携手共
![cooperation](./docs/images/overview/cooperation.png)

<!-- --8<-- [start:license] -->
## 📜证书
## 📜开源协议

[Apache License 2.0](https://github.com/PaddlePaddle/PaddleScience/blob/develop/LICENSE)
<!-- --8<-- [end:license] -->
9 changes: 7 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
| 飞行器设计 | [MeshGraphNets](https://aistudio.baidu.com/projectdetail/5322713) | 数据驱动 | GNN | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/184320) | [Paper](https://arxiv.org/abs/2010.03409)|
| 飞行器设计 | [火箭发动机真空羽流](https://aistudio.baidu.com/projectdetail/4486133) | 数据驱动 | CNN | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/167250) | - |
| 飞行器设计 | [Deep-Flow-Prediction](https://aistudio.baidu.com/projectdetail/5671596) | 数据驱动 | TurbNetG | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/197778) | [Paper](https://arxiv.org/abs/1810.08217) |
| 飞行器设计 | [机翼设计](./zh/examples/amgnet.md) | 数据驱动 | AMGNet | 监督学习 | [Data](https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip) | [Paper](https://arxiv.org/abs/1810.08217) |
| 通用流场模拟 | [气动外形设计](./zh/examples/amgnet.md) | 数据驱动 | AMGNet | 监督学习 | [Data](https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip) | [Paper](https://arxiv.org/abs/1810.08217) |
| 流固耦合 | [涡激振动](./zh/examples/viv.md) | 机理驱动 | MLP | 半监督学习 | [Data](https://github.com/PaddlePaddle/PaddleScience/blob/develop/examples/fsi/VIV_Training_Neta100.mat) | [Paper](https://arxiv.org/abs/2206.03864)|
| 多相流 | [气液两相流](./zh/examples/bubble.md) | 机理驱动 | BubbleNet | 半监督学习 | [Data](https://paddle-org.bj.bcebos.com/paddlescience/datasets/BubbleNet/bubble.mat) | [Paper](https://pubs.aip.org/aip/adv/article/12/3/035153/2819394/Predicting-micro-bubble-dynamics-with-semi-physics)|
| 多相流 | [twophasePINN](https://aistudio.baidu.com/projectdetail/5379212) | 机理驱动 | MLP | 无监督学习 | - | [Paper](https://doi.org/10.1016/j.mlwa.2021.100029)|
Expand Down Expand Up @@ -96,7 +96,11 @@
pip install paddlesci
```

- **完整安装流程**[安装与使用](./zh/install_setup.md)
**完整安装流程**[安装与使用](./zh/install_setup.md)

--8<--
./README.md:update
--8<--

--8<--
./README.md:feature
Expand Down Expand Up @@ -149,6 +153,7 @@
<a href="https://github.com/Gxinhu"><img class="avatar" src="https://avatars.githubusercontent.com/Gxinhu" alt="avatar" /></a>
<a href="https://github.com/XYM-1"><img class="avatar" src="https://avatars.githubusercontent.com/XYM-1" alt="avatar" /></a>
<a href="https://github.com/xusuyong"><img class="avatar" src="https://avatars.githubusercontent.com/xusuyong" alt="avatar" /></a>
<a href="https://github.com/DrownFish19"><img class="avatar" src="https://avatars.githubusercontent.com/DrownFish19" alt="avatar" /></a>
<a href="https://github.com/NKNaN"><img class="avatar" src="https://avatars.githubusercontent.com/NKNaN" alt="avatar" /></a>
<a href="https://github.com/ruoyunbai"><img class="avatar" src="https://avatars.githubusercontent.com/ruoyunbai" alt="avatar" /></a>
<a href="https://github.com/sanbuphy"><img class="avatar" src="https://avatars.githubusercontent.com/sanbuphy" alt="avatar" /></a>
Expand Down
1 change: 1 addition & 0 deletions docs/zh/api/arch.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
- UNetEx
- USCNN
- NowcastNet
- HEDeepONets
show_root_heading: true
heading_level: 3
1 change: 1 addition & 0 deletions docs/zh/api/equation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- PDE
- FractionalPoisson
- Biharmonic
- HeatExchanger
- Laplace
- LinearElasticity
- NavierStokes
Expand Down
13 changes: 1 addition & 12 deletions docs/zh/api/loss.md → docs/zh/api/loss/loss.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Loss(损失函数) 模块
# Loss.loss(损失函数) 模块

::: ppsci.loss
handler: python
Expand All @@ -18,14 +18,3 @@
- PeriodicMSELoss
show_root_heading: true
heading_level: 3

::: ppsci.loss.mtl
handler: python
options:
members:
- AGDA
- LossAggregator
- PCGrad
- Relobralo
show_root_heading: true
heading_level: 3
12 changes: 12 additions & 0 deletions docs/zh/api/loss/mtl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Loss.mtl(多任务学习) 模块

::: ppsci.loss.mtl
handler: python
options:
members:
- AGDA
- LossAggregator
- PCGrad
- Relobralo
show_root_heading: true
heading_level: 3
44 changes: 22 additions & 22 deletions docs/zh/examples/topopt.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ examples/topopt/functions.py:68:101
--8<--
```

``` py linenums="37"
``` py linenums="40"
--8<--
examples/topopt/topopt.py:37:46
examples/topopt/topopt.py:40:48
--8<--
```

Expand All @@ -79,9 +79,9 @@ examples/topopt/topopt.py:37:46
经过 SIMP 的 $N_{0}$ 次初始迭代步骤得到的图像 $I$ 可以看作是模糊了的最终结构。由于最终的优化解给出的图像 $I^*$ 并不包含中间过程的信息,因此 $I^*$ 可以被解释为图像 $I$ 的掩码。于是 $I \rightarrow I^*$ 这一优化过程可以看作是二分类的图像分割或者前景-背景分割过程,因此构建 Unet 模型进行预测,具体网络结构如图所示:
![Unet](https://ai-studio-static-online.cdn.bcebos.com/7a0e54df9c9d48e5841423546e851f620e73ea917f9e4258aefc47c498bba85e)

``` py linenums="87"
``` py linenums="90"
--8<--
examples/topopt/topopt.py:87:89
examples/topopt/topopt.py:90:91
--8<--
```

Expand All @@ -98,9 +98,9 @@ examples/topopt/conf/topopt.yaml:49:54
--8<--
```

``` py linenums="33"
``` py linenums="36"
--8<--
examples/topopt/topopt.py:33:36
examples/topopt/topopt.py:36:38
--8<--
```

Expand All @@ -120,9 +120,9 @@ examples/topopt/functions.py:102:133

在本案例中,我们采用监督学习方式进行训练,所以使用监督约束 `SupervisedConstraint`,代码如下:

``` py linenums="47"
``` py linenums="50"
--8<--
examples/topopt/topopt.py:47:73
examples/topopt/topopt.py:50:75
--8<--
```

Expand Down Expand Up @@ -152,19 +152,19 @@ examples/topopt/functions.py:23:67
--8<--
```

``` py linenums="77"
``` py linenums="80"
--8<--
examples/topopt/topopt.py:77:79
examples/topopt/topopt.py:80:81
--8<--
```

### 3.7 优化器构建

训练过程会调用优化器来更新模型参数,此处选择 `Adam` 优化器。

``` py linenums="90"
``` py linenums="93"
--8<--
examples/topopt/topopt.py:90:94
examples/topopt/topopt.py:93:96
--8<--
```

Expand All @@ -191,9 +191,9 @@ $$

loss 构建代码如下:

``` py linenums="260"
``` py linenums="263"
--8<--
examples/topopt/topopt.py:260:273
examples/topopt/topopt.py:263:274
--8<--
```

Expand All @@ -211,9 +211,9 @@ $$
其中 $n_{0} = w_{00} + w_{01}$ , $n_{1} = w_{10} + w_{11}$ ,$w_{tp}$ 表示实际是 $t$ 类且被预测为 $p$ 类的像素点的数量
metric 构建代码如下:

``` py linenums="274"
``` py linenums="277"
--8<--
examples/topopt/topopt.py:274:316
examples/topopt/topopt.py:277:317
--8<--
```

Expand All @@ -230,9 +230,9 @@ examples/topopt/conf/topopt.yaml:29:31

训练代码如下:

``` py linenums="74"
``` py linenums="77"
--8<--
examples/topopt/topopt.py:74:110
examples/topopt/topopt.py:77:111
--8<--
```

Expand All @@ -245,9 +245,9 @@ examples/topopt/topopt.py:74:110
#### 3.10.1 评估器构建
为应用 PaddleScience API,此处在每一次评估时构建一个评估器 SupervisedValidator 进行评估:

``` py linenums="215"
``` py linenums="218"
--8<--
examples/topopt/topopt.py:215:242
examples/topopt/topopt.py:218:245
--8<--
```

Expand All @@ -258,9 +258,9 @@ examples/topopt/topopt.py:215:242

使用 `ppsci.utils.misc.plot_curve()` 方法直接绘制 Binary Accuracy 和 IoU 的结果:

``` py linenums="182"
``` py linenums="185"
--8<--
examples/topopt/topopt.py:182:192
examples/topopt/topopt.py:185:193
--8<--
```

Expand Down
11 changes: 7 additions & 4 deletions docs/zh/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ Equation 模块负责定义各种常见方程的计算函数,如 `NavierStokes

Geometry 模块负责定义各种常见的几何形状,如 `Interval` 线段几何、`Rectangle` 矩形几何、`Sphere` 球面几何。

### 2.7 [Loss](./api/loss.md)
### 2.7 [Loss](./api/loss/loss.md)

Loss 模块负责定义各种损失函数,在模型前向与方程计算完毕后,将结果与参考值计算损失值,供后续的梯度优化算法使用;
Loss 模块包含 [`ppsci.loss.loss`](./api/loss/loss.md)[`ppsci.loss.mtl`](./api/loss/mtl.md) 两个子模块,如下所示。

同时该模块也提供了常见的多任务学习优化功能,包括 PCGrad、AGDA,进一步提升多个 loss 共同优化(如 PINN 方法)的精度。
| 子模块名称 | 子模块功能 |
| :-- | :-- |
| [ppsci.loss.loss](./api/loss/loss.md)| 损失函数相关 |
| [ppsci.loss.mtl](./api/loss/mtl.md)| 多目标优化相关 |

### 2.8 Optimizer

Expand Down Expand Up @@ -110,7 +113,7 @@ Utils 模块内部存放了一些适用于多种场景下的工具类、函数

### 2.11 [Validate](./api/validate.md)

Validator 模块负责定义各种评估器,用于模型训练完一个 epoch 后自动在指定数据上进行评估(可选,默认不开启训练时评估)并得到评估指标。
Validator 模块负责定义各种评估器,用于在指定数据上进行评估(可选,默认不开启训练时评估)并得到评估指标。

### 2.12 [Visualize](./api/visualize.md)

Expand Down
5 changes: 3 additions & 2 deletions docs/zh/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,15 @@ solver = ppsci.solver.Solver(

### 2.4 多任务学习

在机理驱动、数理融合场景中,往往会同时优化多个损失项,如控制方程残差损失、(初)边值条件损失等。在训练过程中这些损失项对参数的梯度方向可能会互相冲突,阻碍训练精度收敛,而这正是多任务学习方法能解决的问题。因此 PaddleScience 在多任务学习模块中引入了几种常见的算法,其主要通过对不同任务的权重和产生的梯度进行调整,从而缓解该问题,最终提升模型收敛精度。下面以 PCGrad 方法进行举例,使用方式如下:
在机理驱动、数理融合场景中,往往会同时优化多个损失项,如控制方程残差损失、(初)边值条件损失等。在训练过程中这些损失项对参数的梯度方向可能会互相冲突,阻碍训练精度收敛,而这正是多任务学习方法能解决的问题。因此 PaddleScience 在多任务学习模块中引入了几种常见的算法,其主要通过对不同任务的权重或产生的梯度进行调整,从而缓解该问题,最终提升模型收敛精度。下面以 [`Relobralo`](https://paddlescience-docs.readthedocs.io/zh/latest/zh/api/loss/mtl/#ppsci.loss.mtl.Relobralo) 算法进行举例,使用方式如下:

1. 实例化一个多任务学习方法的对象

``` py hl_lines="3"
from ppsci.loss import mtl
model = ...
loss_aggregator = mtl.PCGrad(model)
num_losses = 2 # number of losses to be optimized
loss_aggregator = mtl.Relobralo(num_losses)
```

2. 将该对象作为 `Solver` 的实例化参数之一传入
Expand Down
58 changes: 58 additions & 0 deletions examples/euler_beam/conf/euler_beam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
hydra:
run:
# dynamic output directory according to running time and override name
dir: outputs_euler_beam/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname}
job:
name: ${mode} # name of logfile
chdir: false # keep current working direcotry unchaned
config:
override_dirname:
exclude_keys:
- TRAIN.checkpoint_path
- TRAIN.pretrained_model_path
- EVAL.pretrained_model_path
- mode
- output_dir
- log_freq
sweep:
# output directory for multirun
dir: ${hydra.run.dir}
subdir: ./

# general settings
mode: train # running mode: train/eval
seed: 42
output_dir: ${hydra:run.dir}
log_freq: 20
to_static: false

# set working condition
q: -1.0
D: 1.0

# model settings
MODEL:
input_keys: ["x"]
output_keys: ["u"]
num_layers: 3
hidden_size: 20

# training settings
TRAIN:
epochs: 10000
iters_per_epoch: 1
save_freq: 1000
eval_during_train: true
eval_freq: 1000
learning_rate: 1.0e-3
batch_size:
pde: 100
bc: 4
pretrained_model_path: null
checkpoint_path: null

# evaluation settings
EVAL:
pretrained_model_path: null
eval_with_no_grad: true
total_size: 100

0 comments on commit 7f979e3

Please sign in to comment.