Skip to content

Commit 710d65d

Browse files
Merge branch 'develop' into add_front_image
2 parents 90b7c85 + fb664aa commit 710d65d

File tree

286 files changed

+1571
-23965
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

286 files changed

+1571
-23965
lines changed

README.md

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,77 @@
1-
*Current version of PaddleScience is v1.0 Beta.*
1+
# PaddleScience
22

3-
# Introduction
3+
> *Developed with [PaddlePaddle](https://www.paddlepaddle.org.cn/)*
44
5-
PaddleScience extends the PaddlePaddle framework with reusable
6-
software components for developing novel scientific computing applications. Such new
7-
applications include Physics-informed Machine Learning, neural network based PDE solvers,
8-
machine learning for CFD, and so on. PaddleScience is currently under active development.
9-
Its design is evolving and its APIs are subject to change.
5+
[![Doc](https://img.shields.io/readthedocs/paddlescience-docs/latest)](https://paddlescience-docs.readthedocs.io/zh/latest/)
6+
[![License](https://img.shields.io/github/license/PaddlePaddle/PaddleScience)](./LICENSE)
107

11-
# Core features and organization
8+
[**PaddleScience使用文档**](https://paddlescience-docs.readthedocs.io/zh/latest/)
129

13-
PaddleScience currently focuses on the PINNs model. The core components are as follows.
10+
## 简介
1411

15-
- PDE, delineating partial differential equations in symbolic forms. Specific PDEs derive the
16-
the base PDE class.
12+
PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计算套件,利用深度神经网络的学习能力和 PaddlePaddle 框架的自动(高阶)微分机制,解决物理、化学、气象等领域的问题。支持物理机理驱动、数据驱动、数理融合三种求解方式,并提供了基础 API 和详尽文档供用户使用与二次开发。
1713

18-
- Geometry, a declarative interface for defining the geometric domain. Automatic
19-
discretization is supported
14+
<div align="center">
15+
<img src="./docs/images/overview/panorama.png" width="80%" height="80%">
16+
</div>
2017

21-
- Neural net, currently supporting fully connected layers with customizable size and depth.
18+
## 特性
2219

23-
- Loss, defining what exact penalties are enforced during the training process. By default,
24-
the L2 loss is applied. In the current design, the total loss is a weighted sum of
25-
four parts, the equation loss, the boundary condition loss, the initial condition loss and the data loss.
20+
- 支持简单几何和复杂 STL 几何的采样与布尔运算。
21+
- 支持包括 Dirichlet、Neumann、Robin 以及自定义边界条件。
22+
- 支持物理机理驱动、数据驱动、数理融合三种问题求解方式。涵盖流体、结构、气象等领域 8+ 案例。
23+
- 支持结果可视化输出与日志结构化保存。
24+
- 完善的 type hints,用户使用和代码贡献全流程文档,经典案例 AI studio 快速体验,降低使用门槛,提高开发效率。
25+
- 更多特性正在开发中...
2626

27-
- Optimizer, specifying which optimizer to use for training. Adam is the default option. More
28-
optimizers, such as BFGS, will be available in the future.
27+
## 安装使用
2928

30-
- Solver, managing the training process given the training data in a batchly fashion.
29+
1. 执行以下命令,从 github 上克隆 PaddleScience 项目,进入 PaddleScience 目录,并将该目录添加到系统环境变量中
3130

32-
- Visualization, an easy access to the graph drawing utilities.
31+
``` shell
32+
git clone https://github.com/PaddlePaddle/PaddleScience.git
33+
cd PaddleScience
34+
export PYTHONPATH=$PWD:$PYTHONPATH
35+
```
3336

34-
# Getting started
37+
2. 安装必要的依赖包
3538

36-
## Prerequisites
39+
``` shell
40+
pip install -r requirements.txt
41+
```
3742

38-
Hardware requirements: NVIDIA GPU V100, NVIDIA GPU A100
43+
3. 验证安装
3944

40-
Package dependencies: paddle, cuda (11.0 or higher), numpy, scipy, sympy, matplotlib, vtk, pyevtk, wget.
45+
``` py
46+
python -c "import ppsci; ppsci.utils.run_check()"
47+
```
4148

42-
PaddleScience currently relies on new features of the Paddle framework so please be advised to download the latest version of Paddle on GitHub or on Gitee.
49+
4. 开始使用
4350

44-
For more details on installation, please refer to the offical [PaddlePaddle repository on GitHub](https://github.com/PaddlePaddle/Paddle) or [PaddlePaddle repository on Gitee](https://gitee.com/paddlepaddle/Paddle).
51+
``` py
52+
import ppsci
4553
46-
## Download and environment setup
54+
# write your code here...
55+
```
4756

48-
``` shell
49-
Download from GitHub: git clone https://github.com/PaddlePaddle/PaddleScience.git
50-
Download from Gitee: git clone https://gitee.com/PaddlePaddle/PaddleScience.git
57+
更多安装方式请参考 [**安装与使用**](https://paddlescience-docs.readthedocs.io/zh/latest/zh/install_setup/)
5158

52-
cd PaddleScience
53-
export PYTHONPATH=$PWD:$PYTHONPATH
59+
## 快速开始
5460

55-
pip install -r requirements.txt
56-
```
61+
参考 [**快速开始**](https://paddlescience-docs.readthedocs.io/zh/latest/zh/quickstart/)
5762

58-
## Run examples
63+
## 经典案例
5964

60-
Some examples are baked in for quick demonstration. Please find them in the `examples` directory. To run an example, just enter the subdirectory and run the demo code in Python commandline.
65+
请参考 [**经典案例**](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/viv/)
6166

62-
``` shell
63-
# Darcy flow (Poisson equation)
64-
cd examples/darcy
65-
python darcy2d.py
67+
## 支持
6668

67-
# LDC steady (Steady Navier-Stokes eqution)
68-
cd examples/ldc
69-
python ldc2d_steady_train.py
69+
如使用过程中遇到问题或想提出开发建议,欢迎在 [**Issue**](https://github.com/PaddlePaddle/PaddleScience/issues/new) 页面新建 issue。
7070

71-
# Lid Driven Cavity unsteady with continue-time method (Unsteady Navier-Stokes equation)
72-
cd examples/ldc
73-
python ldc2d_unsteady_t.py
71+
## 贡献代码
7472

75-
# Flow around a circular cylinder with discrete-time method (Unsteady Navier-Stokes equation)
76-
cd examples/cylinder/3d_unsteady_discrete/baseline
77-
python cylinder3d_unsteady.py
73+
PaddleScience 项目欢迎并依赖开发人员和开源社区中的用户,请参阅 [**贡献指南**](https://paddlescience-docs.readthedocs.io/zh/latest/zh/contribute/)。
7874

79-
```
75+
## 证书
8076

81-
## Short tutorials on how to construct and solve a PINN model
82-
83-
[A tutorial on Lid Driven Cavity flow](./examples/ldc/README.md)
84-
85-
[A tutorial on Darcy flow in porous medium](./examples/darcy/README.md)
77+
[Apache License 2.0](https://github.com/PaddlePaddle/PaddleScience/blob/develop/LICENSE)

docs/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计算套件,利用深度神经网络的学习能力和 PaddlePaddle 框架的自动(高阶)微分机制,解决物理、化学、气象等领域的问题。支持物理机理驱动、数据驱动、数理融合三种求解方式,并提供了基础 API 和详尽文档供用户使用与二次开发。
66

7+
![panorama](./images/overview/panorama.png)
8+
79
## 特性
810

911
- 支持简单几何和复杂 STL 几何的采样与布尔运算。
@@ -15,11 +17,11 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
1517

1618
## 支持
1719

18-
- 如使用过程中遇到问题或想提出开发建议,欢迎在 [Issue](https://github.com/PaddlePaddle/PaddleScience/issues/new) 页面新建 issue。
20+
- 如使用过程中遇到问题或想提出开发建议,欢迎在 [**Issue**](https://github.com/PaddlePaddle/PaddleScience/issues/new) 页面新建 issue。
1921

2022
## 贡献代码
2123

22-
PaddleScience 项目欢迎并依赖开发人员和开源社区中的用户,请参阅 [贡献指南](https://paddlescience-docs.readthedocs.io/zh/latest/zh/contribute/)
24+
PaddleScience 项目欢迎并依赖开发人员和开源社区中的用户,请参阅 [**贡献指南**](https://paddlescience-docs.readthedocs.io/zh/latest/zh/contribute/)
2325

2426
## 证书
2527

docs/zh/examples/cylinder2d_unsteady_transformer_physx.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,19 @@ $$Re \sim(100, 750)$$
110110

111111
首先展示代码中定义的各个参数变量,每个参数的具体含义会在下面使用到时进行解释。
112112

113-
``` py linenums="51" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py"
113+
``` py linenums="51" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn.py"
114114
--8<--
115-
examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:51:62
115+
examples/cylinder/2d_unsteady/transformer_physx/train_enn.py:51:62
116116
--8<--
117117
```
118118

119119
#### 3.2.1 约束构建
120120

121121
本案例基于数据驱动的方法求解问题,因此需要使用 PaddleScience 内置的 `SupervisedConstraint` 构建监督约束。在定义约束之前,需要首先指定监督约束中用于数据加载的各个参数,代码如下:
122122

123-
``` py linenums="67" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py"
123+
``` py linenums="67" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn.py"
124124
--8<--
125-
examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:67:84
125+
examples/cylinder/2d_unsteady/transformer_physx/train_enn.py:67:84
126126
--8<--
127127
```
128128

@@ -141,9 +141,9 @@ examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:67:84
141141

142142
定义监督约束的代码如下:
143143

144-
``` py linenums="86" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py"
144+
``` py linenums="86" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn.py"
145145
--8<--
146-
examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:86:94
146+
examples/cylinder/2d_unsteady/transformer_physx/train_enn.py:86:94
147147
--8<--
148148
```
149149

@@ -166,37 +166,37 @@ examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:86:94
166166

167167
用 PaddleScience 代码表示如下:
168168

169-
``` py linenums="99" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py"
169+
``` py linenums="99" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn.py"
170170
--8<--
171-
examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:99:105
171+
examples/cylinder/2d_unsteady/transformer_physx/train_enn.py:99:105
172172
--8<--
173173
```
174174

175175
其中,`CylinderEmbedding` 的前两个参数在前文中已有描述,这里不再赘述,网络模型的第三、四个参数是训练数据集的均值和方差,用于归一化输入数据。计算均值、方差的的代码表示如下:
176176

177-
``` py linenums="28" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py"
177+
``` py linenums="28" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn.py"
178178
--8<--
179-
examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:28:45
179+
examples/cylinder/2d_unsteady/transformer_physx/train_enn.py:28:45
180180
--8<--
181181
```
182182

183183
#### 3.2.3 学习率与优化器构建
184184

185185
本案例中使用的学习率方法为 `ExponentialDecay`,学习率大小设置为0.001。优化器使用 `Adam`,梯度裁剪使用了 Paddle 内置的 `ClipGradByGlobalNorm` 方法。用 PaddleScience 代码表示如下:
186186

187-
``` py linenums="107" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py"
187+
``` py linenums="107" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn.py"
188188
--8<--
189-
examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:107:121
189+
examples/cylinder/2d_unsteady/transformer_physx/train_enn.py:107:121
190190
--8<--
191191
```
192192

193193
#### 3.2.4 评估器构建
194194

195195
本案例训练过程中会按照一定的训练轮数间隔,使用验证集评估当前模型的训练情况,需要使用 `SupervisedValidator` 构建评估器。代码如下:
196196

197-
``` py linenums="123" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py"
197+
``` py linenums="123" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn.py"
198198
--8<--
199-
examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:123:150
199+
examples/cylinder/2d_unsteady/transformer_physx/train_enn.py:123:150
200200
--8<--
201201
```
202202

@@ -206,39 +206,39 @@ examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:123:150
206206

207207
完成上述设置之后,只需要将上述实例化的对象按顺序传递给 `ppsci.solver.Solver`,然后启动训练、评估。
208208

209-
``` py linenums="153" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py"
209+
``` py linenums="153" title="examples/cylinder/2d_unsteady/transformer_physx/train_enn.py"
210210
--8<--
211-
examples/cylinder/2d_unsteady/transformer_physx/train_enn_v2.py:153:
211+
examples/cylinder/2d_unsteady/transformer_physx/train_enn.py:153:
212212
--8<--
213213
```
214214

215215
### 3.3 Transformer 模型
216216

217217
上文介绍了如何构建 Embedding 模型的训练、评估,在本节中将介绍如何使用训练好的 Embedding 模型训练 Transformer 模型。因为训练 Transformer 模型的步骤与训练 Embedding 模型的步骤基本相似,因此本节在两者的重复部分的各个参数不再详细介绍。首先将代码中定义的各个参数变量展示如下,每个参数的具体含义会在下面使用到时进行解释。
218218

219-
``` py linenums="58" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
219+
``` py linenums="58" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
220220
--8<--
221-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:58:74
221+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:58:74
222222
--8<--
223223
```
224224

225225
#### 3.3.1 约束构建
226226

227227
Transformer 模型同样基于数据驱动的方法求解问题,因此需要使用 PaddleScience 内置的 `SupervisedConstraint` 构建监督约束。在定义约束之前,需要首先指定监督约束中用于数据加载的各个参数,代码如下:
228228

229-
``` py linenums="82" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
229+
``` py linenums="82" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
230230
--8<--
231-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:82:99
231+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:82:99
232232
--8<--
233233
```
234234

235235
数据加载的各个参数与 Embedding 模型中的基本一致,不再赘述。需要说明的是由于 Transformer 模型训练的输入数据是 Embedding 模型 Encoder 模块的输出数据,因此我们将训练好的 Embedding 模型作为 `CylinderDataset` 的一个参数,在初始化时首先将训练数据映射到编码空间。
236236

237237
定义监督约束的代码如下:
238238

239-
``` py linenums="101" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
239+
``` py linenums="101" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
240240
--8<--
241-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:101:106
241+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:101:106
242242
--8<--
243243
```
244244

@@ -253,9 +253,9 @@ examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:101:106
253253

254254
用 PaddleScience 代码表示如下:
255255

256-
``` py linenums="111" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
256+
``` py linenums="111" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
257257
--8<--
258-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:111:119
258+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:111:119
259259
--8<--
260260
```
261261

@@ -265,19 +265,19 @@ examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:111:119
265265

266266
本案例中使用的学习率方法为 `CosineWarmRestarts`,学习率大小设置为0.001。优化器使用 `Adam`,梯度裁剪使用了 Paddle 内置的 `ClipGradByGlobalNorm` 方法。用 PaddleScience 代码表示如下:
267267

268-
``` py linenums="121" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
268+
``` py linenums="121" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
269269
--8<--
270-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:121:135
270+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:121:135
271271
--8<--
272272
```
273273

274274
#### 3.3.4 评估器构建
275275

276276
训练过程中会按照一定的训练轮数间隔,使用验证集评估当前模型的训练情况,需要使用 `SupervisedValidator` 构建评估器。用 PaddleScience 代码表示如下:
277277

278-
``` py linenums="137" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
278+
``` py linenums="137" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
279279
--8<--
280-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:137:163
280+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:137:163
281281
--8<--
282282
```
283283

@@ -287,25 +287,25 @@ examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:137:163
287287

288288
在本文中首先定义了对 Transformer 模型输出数据变换到物理状态空间的代码:
289289

290-
``` py linenums="32" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
290+
``` py linenums="32" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
291291
--8<--
292-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:32:52
292+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:32:52
293293
--8<--
294294
```
295295

296-
``` py linenums="78" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
296+
``` py linenums="78" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
297297
--8<--
298-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:78:79
298+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:78:79
299299
--8<--
300300
```
301301

302302
可以看到,程序首先载入了训练好的 Embedding 模型,然后在 `OutputTransform``__call__` 函数内实现了编码向量到物理状态空间的变换。
303303

304304
在定义好了以上代码之后,就可以实现可视化器代码的构建了:
305305

306-
``` py linenums="165" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
306+
``` py linenums="165" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
307307
--8<--
308-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:165:193
308+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:165:193
309309
--8<--
310310
```
311311

@@ -315,23 +315,23 @@ examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:165:193
315315

316316
完成上述设置之后,只需要将上述实例化的对象按顺序传递给 `ppsci.solver.Solver`,然后启动训练、评估。
317317

318-
``` py linenums="193" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
318+
``` py linenums="193" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
319319
--8<--
320-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py:193:
320+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py:193:
321321
--8<--
322322
```
323323

324324
## 4. 完整代码
325325

326-
``` py linenums="1" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
326+
``` py linenums="1" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
327327
--8<--
328-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py
328+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py
329329
--8<--
330330
```
331331

332-
``` py linenums="1" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py"
332+
``` py linenums="1" title="examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py"
333333
--8<--
334-
examples/cylinder/2d_unsteady/transformer_physx/train_transformer_v2.py
334+
examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py
335335
--8<--
336336
```
337337

0 commit comments

Comments
 (0)