Skip to content

Commit 0d3db44

Browse files
[Fix&Doc] Update homepage and optimize several transforms (#708)
* refine description for AMGNet * add 1 more contributor * change Normalize, Log1p, CropData, SqueezeData to inplace transform to avoid copying data for efficiency * update details in homepage and mtl module * update
1 parent 30a4c01 commit 0d3db44

File tree

8 files changed

+67
-51
lines changed

8 files changed

+67
-51
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
5151
| 飞行器设计 | [MeshGraphNets](https://aistudio.baidu.com/projectdetail/5322713) | 数据驱动 | GNN | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/184320) | [Paper](https://arxiv.org/abs/2010.03409)|
5252
| 飞行器设计 | [火箭发动机真空羽流](https://aistudio.baidu.com/projectdetail/4486133) | 数据驱动 | CNN | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/167250) | - |
5353
| 飞行器设计 | [Deep-Flow-Prediction](https://aistudio.baidu.com/projectdetail/5671596) | 数据驱动 | TurbNetG | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/197778) | [Paper](https://arxiv.org/abs/1810.08217) |
54+
| 通用流场模拟 | [气动外形设计](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) |
5455
| 流固耦合 | [涡激振动](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)|
5556
| 多相流 | [气液两相流](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)|
5657
| 多相流 | [twophasePINN](https://aistudio.baidu.com/projectdetail/5379212) | 机理驱动 | MLP | 无监督学习 | - | [Paper](https://doi.org/10.1016/j.mlwa.2021.100029)|
@@ -88,6 +89,8 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
8889
<!-- --8<-- [start:update] -->
8990
## 🕘最近更新
9091

92+
- 添加多目标优化算法 [Relobralo](https://paddlescience-docs.readthedocs.io/zh/latest/zh/api/loss/mtl/#ppsci.loss.mtl.Relobralo)
93+
- 添加气泡流求解案例([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))。
9194
- 添加二维血管案例([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))。
9295
- 针对串联方程和复杂方程场景,`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))。
9396
- `Geometry` 模块和 `InteriorConstraint``InitialConstraint` 支持计算 SDF 微分功能([#539](https://github.com/PaddlePaddle/PaddleScience/pull/539))。
@@ -102,7 +105,7 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
102105
- 支持物理机理驱动、数据驱动、数理融合三种问题求解方式。涵盖流体、结构、气象等领域 20+ 案例。
103106
- 支持结果可视化输出与日志结构化保存。
104107
- 完善的 type hints,用户使用和代码贡献全流程文档,经典案例 AI studio 快速体验,降低使用门槛,提高开发效率。
105-
- 支持基于 sympy 符号计算库的方程表示
108+
- 支持基于 sympy 符号计算库的方程表示与联立方程组计算
106109
- 更多特性正在开发中...
107110
<!-- --8<-- [end:feature] -->
108111

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

226230
<!-- --8<-- [start:license] -->
227-
## 📜证书
231+
## 📜开源协议
228232

229233
[Apache License 2.0](https://github.com/PaddlePaddle/PaddleScience/blob/develop/LICENSE)
230234
<!-- --8<-- [end:license] -->

docs/index.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
| 飞行器设计 | [MeshGraphNets](https://aistudio.baidu.com/projectdetail/5322713) | 数据驱动 | GNN | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/184320) | [Paper](https://arxiv.org/abs/2010.03409)|
4848
| 飞行器设计 | [火箭发动机真空羽流](https://aistudio.baidu.com/projectdetail/4486133) | 数据驱动 | CNN | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/167250) | - |
4949
| 飞行器设计 | [Deep-Flow-Prediction](https://aistudio.baidu.com/projectdetail/5671596) | 数据驱动 | TurbNetG | 监督学习 | [Data](https://aistudio.baidu.com/datasetdetail/197778) | [Paper](https://arxiv.org/abs/1810.08217) |
50-
| 飞行器设计 | [机翼设计](./zh/examples/amgnet.md) | 数据驱动 | AMGNet | 监督学习 | [Data](https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip) | [Paper](https://arxiv.org/abs/1810.08217) |
50+
| 通用流场模拟 | [气动外形设计](./zh/examples/amgnet.md) | 数据驱动 | AMGNet | 监督学习 | [Data](https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip) | [Paper](https://arxiv.org/abs/1810.08217) |
5151
| 流固耦合 | [涡激振动](./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)|
5252
| 多相流 | [气液两相流](./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)|
5353
| 多相流 | [twophasePINN](https://aistudio.baidu.com/projectdetail/5379212) | 机理驱动 | MLP | 无监督学习 | - | [Paper](https://doi.org/10.1016/j.mlwa.2021.100029)|
@@ -96,7 +96,11 @@
9696
pip install paddlesci
9797
```
9898

99-
- **完整安装流程**[安装与使用](./zh/install_setup.md)
99+
**完整安装流程**[安装与使用](./zh/install_setup.md)
100+
101+
--8<--
102+
./README.md:update
103+
--8<--
100104

101105
--8<--
102106
./README.md:feature
@@ -149,6 +153,7 @@
149153
<a href="https://github.com/Gxinhu"><img class="avatar" src="https://avatars.githubusercontent.com/Gxinhu" alt="avatar" /></a>
150154
<a href="https://github.com/XYM-1"><img class="avatar" src="https://avatars.githubusercontent.com/XYM-1" alt="avatar" /></a>
151155
<a href="https://github.com/xusuyong"><img class="avatar" src="https://avatars.githubusercontent.com/xusuyong" alt="avatar" /></a>
156+
<a href="https://github.com/DrownFish19"><img class="avatar" src="https://avatars.githubusercontent.com/DrownFish19" alt="avatar" /></a>
152157
<a href="https://github.com/NKNaN"><img class="avatar" src="https://avatars.githubusercontent.com/NKNaN" alt="avatar" /></a>
153158
<a href="https://github.com/ruoyunbai"><img class="avatar" src="https://avatars.githubusercontent.com/ruoyunbai" alt="avatar" /></a>
154159
<a href="https://github.com/sanbuphy"><img class="avatar" src="https://avatars.githubusercontent.com/sanbuphy" alt="avatar" /></a>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Loss(损失函数) 模块
1+
# Loss.loss(损失函数) 模块
22

33
::: ppsci.loss
44
handler: python
@@ -18,14 +18,3 @@
1818
- PeriodicMSELoss
1919
show_root_heading: true
2020
heading_level: 3
21-
22-
::: ppsci.loss.mtl
23-
handler: python
24-
options:
25-
members:
26-
- AGDA
27-
- LossAggregator
28-
- PCGrad
29-
- Relobralo
30-
show_root_heading: true
31-
heading_level: 3

docs/zh/api/loss/mtl.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Loss.mtl(多任务学习) 模块
2+
3+
::: ppsci.loss.mtl
4+
handler: python
5+
options:
6+
members:
7+
- AGDA
8+
- LossAggregator
9+
- PCGrad
10+
- Relobralo
11+
show_root_heading: true
12+
heading_level: 3

docs/zh/overview.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ Equation 模块负责定义各种常见方程的计算函数,如 `NavierStokes
7272

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

75-
### 2.7 [Loss](./api/loss.md)
75+
### 2.7 [Loss](./api/loss/loss.md)
7676

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

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

8184
### 2.8 Optimizer
8285

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

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

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

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

docs/zh/user_guide.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,15 @@ solver = ppsci.solver.Solver(
459459
460460
### 2.4 多任务学习
461461
462-
在机理驱动、数理融合场景中,往往会同时优化多个损失项,如控制方程残差损失、(初)边值条件损失等。在训练过程中这些损失项对参数的梯度方向可能会互相冲突,阻碍训练精度收敛,而这正是多任务学习方法能解决的问题。因此 PaddleScience 在多任务学习模块中引入了几种常见的算法,其主要通过对不同任务的权重和产生的梯度进行调整,从而缓解该问题,最终提升模型收敛精度。下面以 PCGrad 方法进行举例,使用方式如下:
462+
在机理驱动、数理融合场景中,往往会同时优化多个损失项,如控制方程残差损失、(初)边值条件损失等。在训练过程中这些损失项对参数的梯度方向可能会互相冲突,阻碍训练精度收敛,而这正是多任务学习方法能解决的问题。因此 PaddleScience 在多任务学习模块中引入了几种常见的算法,其主要通过对不同任务的权重或产生的梯度进行调整,从而缓解该问题,最终提升模型收敛精度。下面以 [`Relobralo`](https://paddlescience-docs.readthedocs.io/zh/latest/zh/api/loss/mtl/#ppsci.loss.mtl.Relobralo) 算法进行举例,使用方式如下:
463463
464464
1. 实例化一个多任务学习方法的对象
465465
466466
``` py hl_lines="3"
467467
from ppsci.loss import mtl
468468
model = ...
469-
loss_aggregator = mtl.PCGrad(model)
469+
num_losses = 2 # number of losses to be optimized
470+
loss_aggregator = mtl.Relobralo(num_losses)
470471
```
471472
472473
2. 将该对象作为 `Solver` 的实例化参数之一传入

mkdocs.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ nav:
8484
- ppsci.data.batch_transform: zh/api/data/process/batch_transform.md
8585
- ppsci.equation: zh/api/equation.md
8686
- ppsci.geometry: zh/api/geometry.md
87-
- ppsci.loss: zh/api/loss.md
87+
- ppsci.loss:
88+
- ppsci.loss.loss: zh/api/loss/loss.md
89+
- ppsci.loss.mtl: zh/api/loss/mtl.md
8890
- ppsci.metric: zh/api/metric.md
8991
- ppsci.optimizer:
9092
- ppsci.optimizer.optimizer: zh/api/optimizer.md

ppsci/data/process/transform/preprocess.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def __call__(self, input_dict, label_dict, weight_dict):
7171
class Normalize:
7272
"""Normalize data class.
7373
74+
NOTE: This transform will modify the input data dict inplace.
75+
7476
Args:
7577
mean (Union[np.ndarray, Tuple[float, ...]]): Mean of training dataset.
7678
std (Union[np.ndarray, Tuple[float, ...]]): Standard Deviation of training dataset.
@@ -96,20 +98,20 @@ def __init__(
9698
self.apply_keys = apply_keys
9799

98100
def __call__(self, input_item, label_item, weight_item):
99-
input_item_copy = {**input_item}
100-
label_item_copy = {**label_item}
101101
if "input" in self.apply_keys:
102-
for key, value in input_item_copy.items():
103-
input_item_copy[key] = (value - self.mean) / self.std
102+
for key, value in input_item.items():
103+
input_item[key] = (value - self.mean) / self.std
104104
if "label" in self.apply_keys:
105-
for key, value in label_item_copy.items():
106-
label_item_copy[key] = (value - self.mean) / self.std
107-
return input_item_copy, label_item_copy, weight_item
105+
for key, value in label_item.items():
106+
label_item[key] = (value - self.mean) / self.std
107+
return input_item, label_item, weight_item
108108

109109

110110
class Log1p:
111111
"""Calculates the natural logarithm of one plus the data, element-wise.
112112
113+
NOTE: This transform will modify the input data dict inplace.
114+
113115
Args:
114116
scale (float, optional): Scale data. Defaults to 1.0.
115117
apply_keys (Tuple[str, ...], optional): Which data is the log1p method applied to. Defaults to ("input", "label").
@@ -132,22 +134,22 @@ def __init__(
132134
self.apply_keys = apply_keys
133135

134136
def __call__(self, input_item, label_item, weight_item):
135-
input_item_copy = {**input_item}
136-
label_item_copy = {**label_item}
137137
if "input" in self.apply_keys:
138-
for key, value in input_item_copy.items():
139-
input_item_copy[key] = np.log1p(value / self.scale)
138+
for key, value in input_item.items():
139+
input_item[key] = np.log1p(value / self.scale)
140140
if "label" in self.apply_keys:
141-
for key, value in label_item_copy.items():
142-
label_item_copy[key] = np.log1p(value / self.scale)
143-
return input_item_copy, label_item_copy, weight_item
141+
for key, value in label_item.items():
142+
label_item[key] = np.log1p(value / self.scale)
143+
return input_item, label_item, weight_item
144144

145145

146146
class CropData:
147147
"""Crop data class.
148148
149149
This class is used to crop data based on a specified bounding box.
150150
151+
NOTE: This transform will modify the input data dict inplace.
152+
151153
Args:
152154
xmin (Tuple[int, ...]): Bottom left corner point, [x0, y0].
153155
xmax (Tuple[int, ...]): Top right corner point, [x1, y1].
@@ -182,24 +184,24 @@ def __init__(
182184
self.apply_keys = apply_keys
183185

184186
def __call__(self, input_item, label_item, weight_item):
185-
input_item_copy = {**input_item}
186-
label_item_copy = {**label_item}
187187
if "input" in self.apply_keys:
188-
for key, value in input_item_copy.items():
189-
input_item_copy[key] = value[
188+
for key, value in input_item.items():
189+
input_item[key] = value[
190190
:, self.xmin[0] : self.xmax[0], self.xmin[1] : self.xmax[1]
191191
]
192192
if "label" in self.apply_keys:
193-
for key, value in label_item_copy.items():
194-
label_item_copy[key] = value[
193+
for key, value in label_item.items():
194+
label_item[key] = value[
195195
:, self.xmin[0] : self.xmax[0], self.xmin[1] : self.xmax[1]
196196
]
197-
return input_item_copy, label_item_copy, weight_item
197+
return input_item, label_item, weight_item
198198

199199

200200
class SqueezeData:
201201
"""Squeeze data class.
202202
203+
NOTE: This transform will modify the input data dict inplace.
204+
203205
Args:
204206
apply_keys (Tuple[str, ...], optional): Which data is the squeeze method applied to. Defaults to ("input", "label").
205207
@@ -216,27 +218,25 @@ def __init__(self, apply_keys: Tuple[str, ...] = ("input", "label")):
216218
self.apply_keys = apply_keys
217219

218220
def __call__(self, input_item, label_item, weight_item):
219-
input_item_copy = {**input_item}
220-
label_item_copy = {**label_item}
221221
if "input" in self.apply_keys:
222-
for key, value in input_item_copy.items():
222+
for key, value in input_item.items():
223223
if value.ndim == 4:
224224
B, C, H, W = value.shape
225-
input_item_copy[key] = value.reshape((B * C, H, W))
225+
input_item[key] = value.reshape((B * C, H, W))
226226
if value.ndim != 3:
227227
raise ValueError(
228228
f"Only support squeeze data to ndim=3 now, but got ndim={value.ndim}"
229229
)
230230
if "label" in self.apply_keys:
231-
for key, value in label_item_copy.items():
231+
for key, value in label_item.items():
232232
if value.ndim == 4:
233233
B, C, H, W = value.shape
234-
label_item_copy[key] = value.reshape((B * C, H, W))
234+
label_item[key] = value.reshape((B * C, H, W))
235235
if value.ndim != 3:
236236
raise ValueError(
237237
f"Only support squeeze data to ndim=3 now, but got ndim={value.ndim}"
238238
)
239-
return input_item_copy, label_item_copy, weight_item
239+
return input_item, label_item, weight_item
240240

241241

242242
class FunctionalTransform:

0 commit comments

Comments
 (0)