Skip to content

Commit 223f746

Browse files
Merge pull request #286 from HydrogenSulfate/add_run_checker
refine setup doc and add simple running checker
2 parents 68c1a02 + 2883eb6 commit 223f746

File tree

8 files changed

+208
-38
lines changed

8 files changed

+208
-38
lines changed

docs/index.md

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
# 欢迎使用 PaddleScience
22

3-
## 安装
3+
## 1. 开始安装
44

5-
1. 安装 PaddlePaddle
5+
### 1.1 安装 PaddlePaddle
66

7-
请在 [PaddlePaddle](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/develop/install/pip/linux-pip.html) 官网按照您的运行环境,安装 **develop** 版的 PaddlePaddle
7+
请在 [PaddlePaddle](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/develop/install/pip/linux-pip.html) 官网按照您的运行环境,安装 **develop** 版的 PaddlePaddle
88

9-
2. 下载 PaddleScience
9+
### 1.2 安装 PaddleScience
1010

11-
请按以下命令从 github 上克隆 PaddleScience 项目,进入到 PaddleScience 目录下
11+
[1.2.1 git 安装](#121-git)[1.2.2 pip 安装](#122-pip) 任选一种安装方式即可
1212

13-
```shell linenums="1"
13+
#### 1.2.1 git 安装
14+
15+
1. 执行以下命令,从 github 上克隆 PaddleScience 项目,进入 PaddleScience 目录,并将该目录添加到系统环境变量中
16+
17+
``` shell
1418
git clone https://github.com/PaddlePaddle/PaddleScience.git
1519
cd PaddleScience
20+
export PYTHONPATH=$PWD:$PYTHONPATH
1621
```
1722

18-
3. 安装必要的依赖包
23+
2. 安装必要的依赖包
1924

20-
```shell linenums="1"
25+
``` shell
2126
pip install -r requirements.txt
2227
2328
# 安装较慢时可以加上-i选项,提升下载速度
@@ -28,36 +33,52 @@
2833

2934
如需使用外部导入STL文件来构建几何,以及使用加密采样等功能,还需额外安装 [pymesh](https://pymesh.readthedocs.io/en/latest/installation.html#download-the-source)(推荐编译安装) 和 [open3d](https://github.com/isl-org/Open3D/tree/master#python-quick-start)(推荐pip安装)
3035

31-
## 使用
36+
#### 1.2.2 pip 安装
3237

33-
1. 添加 PaddleScience 目录到系统环境变量 PYTHONPATH 中
38+
**coming soon**
3439

35-
``` shell linenums="1"
36-
export PYTHONPATH=$PWD:$PYTHONPATH
37-
```
40+
<div style='display: none'>
41+
执行以下命令进行 pip 安装
42+
43+
``` shell
44+
pip install -i https://pypi.org/simple/ paddlesci
45+
```
46+
47+
</div>
3848

39-
2. 运行案例
49+
## 2. 验证安装
4050

41-
- 运行内置的案例(以 **ldc2d_unsteady_Re10.py** 为例)
51+
执行以下代码,验证安装的 PaddleScience 基础功能是否正常
4252

43-
``` shell linenums="1"
44-
cd examples/ldc/
45-
python ./ldc2d_unsteady_Re10.py
46-
```
53+
``` py
54+
import ppsci
55+
ppsci.utils.run_check()
56+
```
4757

48-
- 编写自己的案例(假设案例名为demo)
58+
如果出现 `PaddleScience is installed successfully.✨ 🍰 ✨`,则说明安装验证成功。
4959

50-
推荐在 `examples/` 下新建 `demo` 文件夹,然后在 `demo` 文件夹下新建 `demo.py`,最后在 `demo.py` 文件中使用 PaddleScience 提供的 [API](./zh/api/arch.md) 编写代码
60+
## 3. 开始使用
5161

52-
```py linenums="1" title="examples/demo/demo.py"
53-
import ppsci
62+
- 运行内置的案例(以 **ldc2d_unsteady_Re10.py** 为例)
5463

55-
# write your code here...
56-
```
64+
``` shell
65+
cd examples/ldc/
66+
python ./ldc2d_unsteady_Re10.py
67+
```
68+
69+
- 编写自己的案例(假设案例名为demo)
5770

58-
编写完毕后运行你的代码
71+
推荐在 `examples/` 下新建 `demo` 文件夹,然后在 `demo` 文件夹下新建 `demo.py`,最后在 `demo.py` 文件中使用 PaddleScience 提供的 [API](./zh/api/arch.md) 编写代码
5972

60-
```shell linenums="1"
61-
cd examples/demo
62-
python ./demo.py
63-
```
73+
``` py linenums="1" title="examples/demo/demo.py"
74+
import ppsci
75+
76+
# write your code here...
77+
```
78+
79+
编写完毕后运行你的代码
80+
81+
``` shell
82+
cd examples/demo
83+
python ./demo.py
84+
```

docs/zh/api/utils.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
handler: python
55
options:
66
members:
7+
- initializer
78
- logger
89
- misc
10+
- reader
11+
- run_check
912
- AttrDict
1013
- ExpressionSolver
1114
- AverageMeter

ppsci/data/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from functools import partial
1818

1919
import numpy as np
20-
import paddle
2120
import paddle.device as device
2221
import paddle.distributed as dist
2322
import paddle.io as io

ppsci/data/dataset/csv_dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Union
2121

2222
import numpy as np
23+
import paddle
2324
from paddle import io
2425
from paddle import vision
2526

ppsci/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ppsci.utils import misc
1818
from ppsci.utils import reader
1919
from ppsci.utils.checker import dynamic_import_to_globals
20+
from ppsci.utils.checker import run_check
2021
from ppsci.utils.config import AttrDict
2122
from ppsci.utils.expression import ExpressionSolver
2223
from ppsci.utils.misc import AverageMeter
@@ -31,6 +32,7 @@
3132
"misc",
3233
"reader",
3334
"dynamic_import_to_globals",
35+
"run_check",
3436
"AttrDict",
3537
"ExpressionSolver",
3638
"AverageMeter",

ppsci/utils/checker.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,92 @@
2020
from ppsci.utils import logger
2121

2222

23+
def run_check() -> None:
24+
"""Check whether PaddleScience is installed correctly and running successfully on
25+
your system.
26+
27+
Examples:
28+
>>> import ppsci
29+
>>> ppsci.utils.run_check()
30+
Runing test code [1/2] [1/5]
31+
Runing test code [1/2] [2/5]
32+
Runing test code [1/2] [3/5]
33+
Runing test code [1/2] [4/5]
34+
Runing test code [1/2] [5/5]
35+
Runing test code [2/2] [1/5]
36+
Runing test code [2/2] [2/5]
37+
Runing test code [2/2] [3/5]
38+
Runing test code [2/2] [4/5]
39+
Runing test code [2/2] [5/5]
40+
PaddleScience is installed successfully.✨ 🍰 ✨
41+
"""
42+
43+
# test demo code below.
44+
import logging
45+
46+
import ppsci
47+
48+
try:
49+
model = ppsci.arch.MLP(("x", "y"), ("u", "v", "p"), 9, 50, "tanh", False, False)
50+
51+
equation = {"NavierStokes": ppsci.equation.NavierStokes(0.01, 1.0, 2, False)}
52+
53+
geom = {"rect": ppsci.geometry.Rectangle((-0.05, -0.05), (0.05, 0.05))}
54+
55+
iters_per_epoch = 5
56+
train_dataloader_cfg = {
57+
"dataset": "IterableNamedArrayDataset",
58+
"iters_per_epoch": iters_per_epoch,
59+
}
60+
61+
npoint_pde = 99**2
62+
pde_constraint = ppsci.constraint.InteriorConstraint(
63+
equation["NavierStokes"].equations,
64+
{"continuity": 0, "momentum_x": 0, "momentum_y": 0},
65+
geom["rect"],
66+
{**train_dataloader_cfg, "batch_size": npoint_pde},
67+
ppsci.loss.MSELoss("sum"),
68+
evenly=True,
69+
weight_dict={
70+
"continuity": 0.0001,
71+
"momentum_x": 0.0001,
72+
"momentum_y": 0.0001,
73+
},
74+
name="EQ",
75+
)
76+
77+
epochs = 2
78+
optimizer = ppsci.optimizer.Adam(0.001)((model,))
79+
for _epoch in range(1, epochs + 1):
80+
for _iter_id in range(1, iters_per_epoch + 1):
81+
input_dict, label_dict, weight_dict = next(pde_constraint.data_iter)
82+
for v in input_dict.values():
83+
v.stop_gradient = False
84+
evaluator = ppsci.utils.ExpressionSolver(
85+
pde_constraint.input_keys, pde_constraint.output_keys, model
86+
)
87+
for output_name, output_formula in pde_constraint.output_expr.items():
88+
if output_name in label_dict:
89+
evaluator.add_target_expr(output_formula, output_name)
90+
91+
output_dict = evaluator(input_dict)
92+
loss = pde_constraint.loss(output_dict, label_dict, weight_dict)
93+
loss.backward()
94+
optimizer.step()
95+
optimizer.clear_grad()
96+
print(
97+
f"Runing test code [{_epoch}/{epochs}]"
98+
f" [{_iter_id}/{iters_per_epoch}]"
99+
)
100+
except Exception as e:
101+
logging.warning(
102+
f"PaddleScience meets some problem with \n {repr(e)} \nplease check whether "
103+
"Paddle's version and PaddleScience's version are both correct."
104+
)
105+
else:
106+
print("PaddleScience is installed successfully.✨ 🍰 ✨")
107+
108+
23109
def dynamic_import_to_globals(
24110
names: Union[str, Tuple[str, ...]], alias: Dict[str, str] = None
25111
) -> bool:

ppsci/utils/misc.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import numpy as np
1919
import paddle
20-
import paddle.distributed as dist
2120

2221
__all__ = [
2322
"all_gather",
@@ -141,8 +140,8 @@ def stack_dict_list(dict_list):
141140
return ret
142141

143142

144-
def typename(obj):
145-
return obj.__class__.__name__
143+
def typename(object):
144+
return object.__class__.__name__
146145

147146

148147
def combine_array_with_time(x, t):
@@ -155,7 +154,6 @@ def combine_array_with_time(x, t):
155154

156155

157156
def set_random_seed(seed):
158-
rank = dist.get_rank()
159-
paddle.seed(seed + rank)
160-
np.random.seed(seed + rank)
161-
random.seed(seed + rank)
157+
paddle.seed(seed)
158+
np.random.seed(seed)
159+
random.seed(seed)

pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[build-system]
2+
requires = ["setuptools>=65"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "paddlesci"
7+
version = "1.0.1"
8+
description = "A library for scientific machine learning"
9+
readme = "README.md"
10+
license = {text = "Apache-2.0"}
11+
authors = [
12+
{ name = "PaddlePaddle" },
13+
]
14+
requires-python = ">=3.7"
15+
keywords = [
16+
"Deep learning",
17+
"Differential equations",
18+
"AI4Science",
19+
"Physics-informed neural networks",
20+
"PaddlePaddle",
21+
]
22+
classifiers = [
23+
"Development Status :: 5 - Production/Stable",
24+
"Intended Audience :: Science/Research",
25+
"License :: OSI Approved :: Apache Software License",
26+
"Programming Language :: Python :: 3 :: Only",
27+
"Programming Language :: Python :: 3.7",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3.9",
30+
"Programming Language :: Python :: 3.10",
31+
"Topic :: Scientific/Engineering",
32+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
33+
"Topic :: Scientific/Engineering :: Mathematics",
34+
]
35+
dependencies = [
36+
"numpy",
37+
"scipy",
38+
"sympy",
39+
"matplotlib",
40+
"vtk",
41+
"pyevtk",
42+
"wget",
43+
"scipy",
44+
"visualdl",
45+
"pyvista==0.37.0",
46+
"pysdf",
47+
"pyyaml",
48+
"scikit-optimize",
49+
"h5py",
50+
]
51+
52+
[project.urls]
53+
Homepage = "https://github.com/PaddlePaddle/PaddleScience"
54+
"Bug Tracker" = "https://github.com/PaddlePaddle/PaddleScience/issues"
55+
Changelog = "https://github.com/PaddlePaddle/PaddleScience/releases"
56+
Documentation = "https://paddlescience-docs.readthedocs.io/zh/latest/"
57+
58+
[tool.setuptools.packages.find]
59+
where = ["."]
60+
exclude = ["docs*", "examples*", "jointContribution*", "paddlescience*", "test_tipc*", "tests*", "tools*"]

0 commit comments

Comments
 (0)