Skip to content

Commit

Permalink
[Fix&Doc] Update homepage and optimize several transforms (PaddlePadd…
Browse files Browse the repository at this point in the history
…le#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
  • Loading branch information
HydrogenSulfate authored Dec 20, 2023
1 parent 2456ae0 commit 77873b2
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 51 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
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
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
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ nav:
- ppsci.data.batch_transform: zh/api/data/process/batch_transform.md
- ppsci.equation: zh/api/equation.md
- ppsci.geometry: zh/api/geometry.md
- ppsci.loss: zh/api/loss.md
- ppsci.loss:
- ppsci.loss.loss: zh/api/loss/loss.md
- ppsci.loss.mtl: zh/api/loss/mtl.md
- ppsci.metric: zh/api/metric.md
- ppsci.optimizer:
- ppsci.optimizer.optimizer: zh/api/optimizer.md
Expand Down
56 changes: 28 additions & 28 deletions ppsci/data/process/transform/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def __call__(self, input_dict, label_dict, weight_dict):
class Normalize:
"""Normalize data class.
NOTE: This transform will modify the input data dict inplace.
Args:
mean (Union[np.ndarray, Tuple[float, ...]]): Mean of training dataset.
std (Union[np.ndarray, Tuple[float, ...]]): Standard Deviation of training dataset.
Expand All @@ -96,20 +98,20 @@ def __init__(
self.apply_keys = apply_keys

def __call__(self, input_item, label_item, weight_item):
input_item_copy = {**input_item}
label_item_copy = {**label_item}
if "input" in self.apply_keys:
for key, value in input_item_copy.items():
input_item_copy[key] = (value - self.mean) / self.std
for key, value in input_item.items():
input_item[key] = (value - self.mean) / self.std
if "label" in self.apply_keys:
for key, value in label_item_copy.items():
label_item_copy[key] = (value - self.mean) / self.std
return input_item_copy, label_item_copy, weight_item
for key, value in label_item.items():
label_item[key] = (value - self.mean) / self.std
return input_item, label_item, weight_item


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

def __call__(self, input_item, label_item, weight_item):
input_item_copy = {**input_item}
label_item_copy = {**label_item}
if "input" in self.apply_keys:
for key, value in input_item_copy.items():
input_item_copy[key] = np.log1p(value / self.scale)
for key, value in input_item.items():
input_item[key] = np.log1p(value / self.scale)
if "label" in self.apply_keys:
for key, value in label_item_copy.items():
label_item_copy[key] = np.log1p(value / self.scale)
return input_item_copy, label_item_copy, weight_item
for key, value in label_item.items():
label_item[key] = np.log1p(value / self.scale)
return input_item, label_item, weight_item


class CropData:
"""Crop data class.
This class is used to crop data based on a specified bounding box.
NOTE: This transform will modify the input data dict inplace.
Args:
xmin (Tuple[int, ...]): Bottom left corner point, [x0, y0].
xmax (Tuple[int, ...]): Top right corner point, [x1, y1].
Expand Down Expand Up @@ -182,24 +184,24 @@ def __init__(
self.apply_keys = apply_keys

def __call__(self, input_item, label_item, weight_item):
input_item_copy = {**input_item}
label_item_copy = {**label_item}
if "input" in self.apply_keys:
for key, value in input_item_copy.items():
input_item_copy[key] = value[
for key, value in input_item.items():
input_item[key] = value[
:, self.xmin[0] : self.xmax[0], self.xmin[1] : self.xmax[1]
]
if "label" in self.apply_keys:
for key, value in label_item_copy.items():
label_item_copy[key] = value[
for key, value in label_item.items():
label_item[key] = value[
:, self.xmin[0] : self.xmax[0], self.xmin[1] : self.xmax[1]
]
return input_item_copy, label_item_copy, weight_item
return input_item, label_item, weight_item


class SqueezeData:
"""Squeeze data class.
NOTE: This transform will modify the input data dict inplace.
Args:
apply_keys (Tuple[str, ...], optional): Which data is the squeeze method applied to. Defaults to ("input", "label").
Expand All @@ -216,27 +218,25 @@ def __init__(self, apply_keys: Tuple[str, ...] = ("input", "label")):
self.apply_keys = apply_keys

def __call__(self, input_item, label_item, weight_item):
input_item_copy = {**input_item}
label_item_copy = {**label_item}
if "input" in self.apply_keys:
for key, value in input_item_copy.items():
for key, value in input_item.items():
if value.ndim == 4:
B, C, H, W = value.shape
input_item_copy[key] = value.reshape((B * C, H, W))
input_item[key] = value.reshape((B * C, H, W))
if value.ndim != 3:
raise ValueError(
f"Only support squeeze data to ndim=3 now, but got ndim={value.ndim}"
)
if "label" in self.apply_keys:
for key, value in label_item_copy.items():
for key, value in label_item.items():
if value.ndim == 4:
B, C, H, W = value.shape
label_item_copy[key] = value.reshape((B * C, H, W))
label_item[key] = value.reshape((B * C, H, W))
if value.ndim != 3:
raise ValueError(
f"Only support squeeze data to ndim=3 now, but got ndim={value.ndim}"
)
return input_item_copy, label_item_copy, weight_item
return input_item, label_item, weight_item


class FunctionalTransform:
Expand Down

0 comments on commit 77873b2

Please sign in to comment.