Skip to content

Commit c20809a

Browse files
[WIP] Add several toolkit to ppsci/externals (#1063)
* add Open3D * add contrib/README * add deepali, neuraloperator, and paddle_harmonics * rename contrib to externals * remove contrib * add external toolkits installation guidance * update mesh and external installation guidance * fix typing error * update installation guidance of external tool * add paddle_scatter
1 parent 2706d22 commit c20809a

19 files changed

+120
-13
lines changed

.gitmodules

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
[submodule "competition/IJCAI_2024_CAR"]
22
path = competition/IJCAI_2024_CAR
33
url = https://atomgit.com/paddlenumberone/ijcai_car.git
4+
[submodule "ppsci/externals/Open3D"]
5+
path = ppsci/externals/Open3D
6+
url = https://github.com/PFCCLab/Open3D.git
7+
[submodule "ppsci/externals/deepali"]
8+
path = ppsci/externals/deepali
9+
url = https://github.com/PFCCLab/deepali.git
10+
[submodule "ppsci/externals/paddle_harmonics"]
11+
path = ppsci/externals/paddle_harmonics
12+
url = https://github.com/PFCCLab/paddle_harmonics.git
13+
[submodule "ppsci/externals/neuraloperator"]
14+
path = ppsci/externals/neuraloperator
15+
url = https://github.com/PFCCLab/neuraloperator.git
16+
[submodule "ppsci/externals/tensorly"]
17+
path = ppsci/externals/tensorly
18+
url = https://github.com/tensorly/tensorly.git
19+
[submodule "ppsci/externals/warp"]
20+
path = ppsci/externals/warp
21+
url = https://github.com/NVIDIA/warp.git
22+
[submodule "ppsci/externals/paddle_scatter"]
23+
path = ppsci/externals/paddle_scatter
24+
url = https://github.com/PFCCLab/paddle_scatter

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ python -c "import paddle; paddle.utils.run_check()"
256256
| [TensorLy](https://tensorly.org/dev/index.html) | 张量计算库 | 全量支持 |
257257
| [NVIDIA/warp](https://github.com/NVIDIA/warp) | 高性能仿真/图形库 | 全量支持 |
258258
| [DLPACK(v0.8)](https://dmlc.github.io/dlpack/latest/index.html) | 跨框架张量内存共享协议 | 全量支持 |
259+
| [Open3D](https://github.com/PFCCLab/Open3D.git) | 三维图形库 | 全量支持 |
260+
| [paddle_scatter](https://github.com/PFCCLab/paddle_scatter) | 张量稀疏计算库 | 全量支持 |
261+
| [paddle_harmonics](https://dmlc.github.io/dlpack/latest/index.html) | 球面谐波变换库 | 全量支持 |
262+
| [neuraloperator](https://dmlc.github.io/dlpack/latest/index.html) | 神经算子库 | 全量支持 |
263+
| [tensorly](https://dmlc.github.io/dlpack/latest/index.html) | 张量运算库 | 全量支持 |
264+
| [warp](https://dmlc.github.io/dlpack/latest/index.html) | 基于 Python 的 GPU 高性能仿真和图形库 | 全量支持 |
259265
<!-- --8<-- [end:adaptation] -->
260266

261267
<!-- --8<-- [start:support] -->

docs/zh/examples/aneurysm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ tar -xvf aneurysm_dataset.tar
119119

120120
???+ warning "注意"
121121

122-
**使用 `Mesh` 类之前,必须先按照[1.4.2 额外依赖安装[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
122+
**使用 `Mesh` 类之前,必须先按照[1.4.2 安装Mesh几何[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142-mesh)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
123123

124124
然后通过 PaddleScience 内置的 STL 几何类 `Mesh` 来读取、解析这些几何文件,并且通过布尔运算,组合出各个计算域,代码如下:
125125

docs/zh/examples/bracket.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ tar -xvf bracket_dataset.tar
136136

137137
???+ warning "注意"
138138

139-
**使用 `Mesh` 类之前,必须先按照[1.4.2 额外依赖安装[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
139+
**使用 `Mesh` 类之前,必须先按照[1.4.2 安装Mesh几何[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142-mesh)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
140140

141141
然后通过 PaddleScience 内置的 STL 几何类 `Mesh` 来读取、解析这些几何文件,并且通过布尔运算,组合出各个计算域,代码如下:
142142

docs/zh/examples/control_arm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ examples/control_arm/forward_analysis.py:36:41
179179

180180
???+ warning "注意"
181181

182-
**使用 `Mesh` 类之前,必须先按照[1.4.2 额外依赖安装[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
182+
**使用 `Mesh` 类之前,必须先按照[1.4.2 安装Mesh几何[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142-mesh)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
183183

184184
然后通过 PaddleScience 内置的 STL 几何类 `ppsci.geometry.Mesh` 即可读取、解析几何文件,得到计算域,并获取几何结构边界:
185185

@@ -384,7 +384,7 @@ examples/control_arm/inverse_parameter.py:35:40
384384

385385
???+ warning "注意"
386386

387-
**使用 `Mesh` 类之前,必须先按照[1.4.2 额外依赖安装[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
387+
**使用 `Mesh` 类之前,必须先按照[1.4.2 安装Mesh几何[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142-mesh)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
388388

389389
然后通过 PaddleScience 内置的 STL 几何类 `ppsci.geometry.Mesh` 即可读取、解析几何文件,得到计算域,并获取几何结构边界:
390390

docs/zh/examples/heart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ examples/heart/forward.py:33:35
168168

169169
???+ warning "注意"
170170

171-
**使用 `Mesh` 类之前,必须先按照[1.4.2 额外依赖安装[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
171+
**使用 `Mesh` 类之前,必须先按照[1.4.2 安装Mesh几何[可选]](https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/install_setup/#142-mesh)文档,安装好 open3d、pysdf、PyMesh 3 个几何依赖包。**
172172

173173
然后通过 PaddleScience 内置的 STL 几何类 `ppsci.geometry.Mesh` 即可读取、解析几何文件,得到计算域,并获取几何结构边界:
174174

docs/zh/examples/iops.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Identification of Pollution Sources (IOPS)
22

33
## 背景简介
4+
45
随着城市化进程的加速和工业化的发展,空气污染成为全球面临的严重环境问题之一。污染物的来源复杂且多样,既包括工业排放、交通运输、燃煤等传统污染源,也有农业、建筑工地等其他潜在的污染源。这些污染物对人类健康、生态系统及气候变化造成了深远的影响。因此,准确识别污染源及其溯源,已成为环境保护和公共健康管理的重要课题。
56

67
污染源识别 是指通过监测数据、模型分析等手段,识别出空气污染的主要来源。传统的污染源识别方法往往依赖于单一的监测数据,如监测站点的污染物浓度数据,结合一定的物理化学模型进行推算。然而,单一的数据来源可能无法全面反映污染的复杂性,特别是在不同污染源交织的情况下,难以精确区分各个污染源的贡献。
@@ -11,8 +12,6 @@
1112

1213
污染源识别与溯源的精确化,不仅有助于提升环境质量监控与治理的效果,还能够为环保政策的实施、污染控制措施的部署、以及污染事件的预警和应急响应提供重要的数据支持和科学指导。
1314

14-
15-
1615
---
1716

1817
## 1. 项目概述
@@ -222,7 +221,6 @@ print(classification_report(y_test, test_predictions, target_names=label_encoder
222221

223222
- **分类报告**:通过 `classification_report` 输出每个类别的准确率、召回率和 F1 分数。
224223

225-
226224
模型的损失曲线、准确率曲线与混淆矩阵如下:
227225

228226
![混淆矩阵](https://www.craes-air.cn/official/confusion_matrix.png)

docs/zh/install_setup.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109

110110
上述方式的优点是步骤简单无需安装,缺点是当环境变量生效的终端被关闭后,需要重新执行上述命令设置 `PYTHONPATH` 才能再次使用 PaddleScience,较为繁琐。
111111

112-
#### 1.4.2 安装额外功能[可选]
112+
#### 1.4.2 安装Mesh几何[可选]
113113

114114
PaddleScience 提供了两种复杂几何类型,如下所示:
115115

@@ -204,6 +204,54 @@ PaddleScience 提供了两种复杂几何类型,如下所示:
204204

205205
3. 由于自测工具 nose 未适配 Python>=3.10,因此执行 `pymesh.test()` 会报错,**但这不影响 pymesh 正常使用**
206206
207+
#### 1.4.3 安装第三方库[可选]
208+
209+
PaddleScience 提供了多种第三方库供用户在开发时使用,这些库位于 `ppsci/externals` 目录下,可以通过 `git submodule` 命令进行下载,然后根据需要进行安装和使用。以下是具体操作步骤:
210+
211+
=== "下载"
212+
213+
``` sh
214+
cd PaddleScience
215+
216+
# 下载全部第三方库
217+
git submodule update --init ppsci/externals/
218+
219+
# 下载指定第三方库(以 tensorly 为例)
220+
git submodule update --init ppsci/externals/tensorly
221+
```
222+
223+
=== "安装"
224+
225+
`tensorly` 为例,安装方法如下:
226+
227+
``` sh
228+
cd ppsci/externals/tensorly
229+
pip install -e .
230+
```
231+
232+
其他库的安装方法请参考相应的 GitHub 项目主页上的说明。
233+
234+
=== "使用"
235+
236+
`tensorly` 为例,使用方法如下:
237+
238+
``` python
239+
>>> from ppsci import externals
240+
>>> print(externals.__all__)
241+
['deepali', 'open3d', 'paddle_harmonics', 'tensorly', 'warp']
242+
243+
>>> tl = externals.tensorly
244+
>>> tl.set_backend("paddle")
245+
246+
>>> x = tl.tensor(np.ones((3, 3)))
247+
Tensor(shape=[3, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
248+
[[1., 1., 1.],
249+
[1., 1., 1.],
250+
[1., 1., 1.]])
251+
```
252+
253+
请根据以上步骤下载、安装和使用您所需的第三方库。
254+
207255
## 2. 验证安装
208256

209257
- 执行以下代码,验证安装的 PaddleScience 基础功能是否正常。
@@ -214,7 +262,7 @@ PaddleScience 提供了两种复杂几何类型,如下所示:
214262

215263
如果出现 `PaddleScience is installed successfully.✨ 🍰 ✨`,则说明安装验证成功。
216264

217-
- [可选]如果已按照 [1.4.2 安装额外依赖](#142) 正确安装了 4 个额外依赖库,则可以执行以下代码,
265+
- [可选]如果已按照 [1.4.2 安装Mesh几何](#142-mesh) 正确安装了 4 个依赖库,则可以执行以下代码,
218266
验证 PaddleScience 的 `ppsci.geometry.Mesh` 模块是否能正常运行。
219267

220268
``` sh

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ nav:
6666
- Cylinder2D_unsteady_transform_physx: zh/examples/cylinder2d_unsteady_transformer_physx.md
6767
- Darcy2D: zh/examples/darcy2d.md
6868
- DeepCFD: zh/examples/deepcfd.md
69+
- DrivAerNet: zh/examples/drivaernet.md
6970
- LDC2D_steady: zh/examples/ldc2d_steady.md
7071
- LDC2D_unsteady: zh/examples/ldc2d_unsteady.md
7172
- Labelfree_DNN_surrogate: zh/examples/labelfree_DNN_surrogate.md
@@ -75,7 +76,6 @@ nav:
7576
- tempoGAN: zh/examples/tempoGAN.md
7677
- NSFNet4: zh/examples/nsfnet4.md
7778
- ViV: zh/examples/viv.md
78-
- DrivAerNet: zh/examples/drivaernet.md
7979
- 结构:
8080
- Biharmonic2D: zh/examples/biharmonic2d.md
8181
- Bracket: zh/examples/bracket.md
@@ -101,6 +101,7 @@ nav:
101101
- GraphCast: zh/examples/graphcast.md
102102
- VelocityGAN: zh/examples/velocity_gan.md
103103
- TGCN: zh/examples/tgcn.md
104+
- IOPS: zh/examples/iops.md
104105
- 化学科学(AI for Chemistry):
105106
- Moflow: zh/examples/moflow.md
106107

ppsci/arch/regdgcnn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from __future__ import annotations
3434

35+
from typing import Dict
3536
from typing import Tuple
3637

3738
import numpy as np
@@ -262,7 +263,7 @@ def __init__(
262263
self.dp4 = paddle.nn.Dropout(p=args["dropout"])
263264
self.linear5 = paddle.nn.Linear(in_features=16, out_features=output_channels)
264265

265-
def forward(self, x):
266+
def forward(self, x: paddle.Tensor) -> Dict[str, paddle.Tensor]:
266267
"""
267268
Forward pass of the model to process input data and predict outputs.
268269

0 commit comments

Comments
 (0)