-
Notifications
You must be signed in to change notification settings - Fork 204
【快乐开源】迁移 DeepCFD 案例至 PaddleScience #529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for your contribution! |
ppsci/arch/unetex.py
Outdated
wn=True, | ||
bn=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
===> weight_norm, batch_norm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ppsci/arch/unetex.py
Outdated
activation=nn.ReLU, | ||
convolution=nn.Conv2D, | ||
): | ||
assert kernel_size % 2 == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于参数的检查使用if-raise ValueError(xxx),assert一般用于内部生成的变量,不要滥用assert来做参数的检查
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ppsci/arch/unetex.py
Outdated
wn=True, | ||
bn=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcdf/deepcdf.py
Outdated
constraint=constraint, | ||
output_dir=OUTPUT_DIR, | ||
optimizer=optimizer, | ||
epochs=EPOCHS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constraint,
OUTPUT_DIR,
optimizer,
epochs=EPOCHS,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcdf/deepcdf.py
Outdated
solver.train() | ||
|
||
############### evaluation after training ############### | ||
output_dict = solver.predict({"input": test_x}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加一个参数 return_numpy=True,会返回numpy.ndarray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcdf/deepcdf.py
Outdated
p_MSE = ((out[:, 2, :, :] - test_y[:, 2, :, :]) ** 2).sum() / len(test_x) | ||
|
||
logger.info( | ||
f"Total MSE is {Total_MSE.detach().numpy()[0]}, Ux MSE is {Ux_MSE.detach().numpy()[0]}, Uy MSE is {Uy_MSE.detach().numpy()[0]}, p MSE is {p_MSE.detach().numpy()[0]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 上面改完就可以删除.detach().numpy()[0]了
- 建议加上
xxx:.5f
,保留一下位数,不然太长很难看
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ppsci/arch/unetex.py
Outdated
from typing import Tuple | ||
|
||
import paddle | ||
import paddle.nn as nn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==> from paddle import nn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ppsci/arch/unetex.py
Outdated
import paddle | ||
import paddle.nn as nn | ||
import paddle.nn.functional as F | ||
from paddle.nn.utils import weight_norm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除该行,建议使用 nn.utils.weight_norm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ppsci/arch/unetex.py
Outdated
tensor = tensors.pop() | ||
size = sizes.pop() | ||
ind = indices.pop() | ||
# 反池化操作,为上采样 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==> # upsample operations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@MayYouBeProsperous review好了,有时间可以修改一下代码 |
辛苦了,已修改代码 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
几处稍微修改下应该没什么问题了
另外案例文档撰写的时候,数据集下载地址可以填写如下:
examples/deepcdf/deepcdf.py
Outdated
with open(os.path.join(DATASET_PATH, "dataX.pkl"), "rb") as file: | ||
x = pickle.load(file) | ||
with open(os.path.join(DATASET_PATH, "dataY.pkl"), "rb") as file: | ||
y = pickle.load(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦哦,那先不加了吧
examples/deepcdf/deepcdf.py
Outdated
tensors (List[np.array]): non-empty tensor list. | ||
ratio (float): split ratio. For example, tensor list A is split to A1 and A2. len(A1) / len(A) = ratio. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
英文句子开头大写
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcdf/deepcdf.py
Outdated
}, | ||
"batch_size": BATCH_SIZE, | ||
"sampler": { | ||
"name": "DistributedBatchSampler", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该只需要用 BatchSampler
就行了,多卡的情况下会在 build_dataloader
中自动替换成 DistributedBatchSampler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
整个项目的命名是不是错了,应该是CFD而不是CDF,整个目录全部替换一下 |
记得补充下案例文档哈 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
辛苦大佬写的文档,主要有一些代码上的小问题和文档整体代码块错位,修改后应该可以合了
docs/zh/examples/deepcfd.md
Outdated
| dataX | [dataX.pkl](https://paddle-org.bj.bcebos.com/paddlescience/datasets/DeepCFD/dataX.pkl) | | ||
| dataY | [dataY.pkl](https://paddle-org.bj.bcebos.com/paddlescience/datasets/DeepCFD/dataY.pkl) | | ||
|
||
数据集官网为:https://zenodo.org/record/3666056/files/DeepCFD.zip?download=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
官网==》原始下载地址
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/zh/examples/deepcfd.md
Outdated
``` py linenums="145" title="examples/deepcfd/deepcfd.py" | ||
--8<-- | ||
examples/deepcfd/deepcfd.py:145:163 | ||
--8<-- | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/zh/examples/deepcfd.md
Outdated
|
||
第二个参数是损失函数的定义,这里使用自定义的损失函数,分别计算 Ux 和 Uy 的均方误差,以及 p 的标准差,然后三者加权求和。 | ||
|
||
第三个参数是约束条件的名字,方便后续对其索引。此次命名为 sup_constraint。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sup_constraint ==> "sup_constraint"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcfd/deepcfd.py
Outdated
eval_during_train=True, | ||
eval_freq=50, | ||
validator=validator, | ||
# visualizer=visualizer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这行注释可以删掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcfd/deepcfd.py
Outdated
CHANNELS_WEIGHTS = np.reshape( | ||
np.sqrt( | ||
np.mean( | ||
np.transpose(y, (0, 2, 3, 1)).reshape((981 * 172 * 79, 3)) ** 2, axis=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
981、172、79应该属于magic number,可以用全大写变量表示一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
return split1, split2 | ||
|
||
|
||
def predict_and_save_plot( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同样,docstring加上返回值
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数没有返回值
examples/deepcfd/deepcfd.py
Outdated
train_x, train_y = train_dataset[:] | ||
test_x, test_y = test_dataset[:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是否需要[:]浅复制操作?后续应该不涉及对输入数据的修改吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
examples/deepcfd/deepcfd.py
Outdated
# evaluate after finished training | ||
solver.eval() | ||
|
||
PLOT_DIR = os.path.join(OUTPUT_DIR, "visu") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
visu ==> visual
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ppsci/arch/unetex.py
Outdated
in_channel (int): Number of channels of input. | ||
out_channel (int): Number of channels of output. | ||
kernel_size (int): Size of kernel of convolution layer. Defaults to 3. | ||
filters (Tuple[int, ...]): Number of filters. Defaults to [16, 32, 64]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 默认值非None的参数,docstring中类型后面加上
, optional
,比如:Tuple[int, ...], optional
- 默认值为None的参数,docstring中类型用
Optional[...]
,比如Optional[Type[nn.Layer]]
- docstring中出现了
paddle.nn.Layer
,这应该是没更新导致的,可以基于autodocstring重新生成最新的docstring进行修改 - 默认值最好不要使用可变类型如list、dict,可以使用None然后在代码里面对入参判None,赋予默认值;或者使用小括号
(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的感谢
docs/zh/examples/deepcfd.md
Outdated
``` py linenums="1" title="examples/deepcfd/deepcfd.py" | ||
--8<-- | ||
examples/deepcfd/deepcfd.py:1:304 | ||
--8<-- | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
完整代码可以不加 :1:304
,直接使用整个文件即可
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的 已按照要求修改了
docs/zh/examples/deepcfd.md
Outdated
``` py linenums="1" title="examples/deepcfd/deepcfd.py" | ||
--8<-- | ||
examples/deepcfd/deepcfd.py:1:304 | ||
--8<-- | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/zh/examples/deepcfd.md
Outdated
| dataX | [dataX.pkl](https://paddle-org.bj.bcebos.com/paddlescience/datasets/DeepCFD/dataX.pkl) | | ||
| dataY | [dataY.pkl](https://paddle-org.bj.bcebos.com/paddlescience/datasets/DeepCFD/dataY.pkl) | | ||
|
||
数据集官网为:https://zenodo.org/record/3666056/files/DeepCFD.zip?download=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/zh/examples/deepcfd.md
Outdated
``` py linenums="145" title="examples/deepcfd/deepcfd.py" | ||
--8<-- | ||
examples/deepcfd/deepcfd.py:145:163 | ||
--8<-- | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/zh/examples/deepcfd.md
Outdated
|
||
第二个参数是损失函数的定义,这里使用自定义的损失函数,分别计算 Ux 和 Uy 的均方误差,以及 p 的标准差,然后三者加权求和。 | ||
|
||
第三个参数是约束条件的名字,方便后续对其索引。此次命名为 sup_constraint。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcfd/deepcfd.py
Outdated
CHANNELS_WEIGHTS = np.reshape( | ||
np.sqrt( | ||
np.mean( | ||
np.transpose(y, (0, 2, 3, 1)).reshape((981 * 172 * 79, 3)) ** 2, axis=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcfd/deepcfd.py
Outdated
eval_during_train=True, | ||
eval_freq=50, | ||
validator=validator, | ||
# visualizer=visualizer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
examples/deepcfd/deepcfd.py
Outdated
# evaluate after finished training | ||
solver.eval() | ||
|
||
PLOT_DIR = os.path.join(OUTPUT_DIR, "visu") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ppsci/arch/unetex.py
Outdated
in_channel (int): Number of channels of input. | ||
out_channel (int): Number of channels of output. | ||
kernel_size (int): Size of kernel of convolution layer. Defaults to 3. | ||
filters (Tuple[int, ...]): Number of filters. Defaults to [16, 32, 64]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的感谢
docs/zh/examples/deepcfd.md
Outdated
|
||
$$\rho(\frac{\partial}{\partial t} + \bf{u} \cdot div ) \bf{u} = - \nabla p + - \nabla \tau + \bf{f}$$ | ||
|
||
其中 $\bf{u}$ 是速度差(具有 x 和 y 两个维度),$\rho$ 是密度, $p$ 是压强场,$\bf{f}$ 是体积力(例如重力)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
速度差 ==> 速度场?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/zh/examples/deepcfd.md
Outdated
|
||
<figure markdown> | ||
{ loading=lazy} | ||
<figcaption>OpenFOAM 计算结果与 DeepCFD 预测结果对比</figcaption> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ==>
OpenFOAM 计算结果与 DeepCFD 预测结果对比,从左到右分别为:水平速度分量(Ux),垂直速度分量(Uy)以及流体压强(p)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
{ loading=lazy} | ||
<figcaption>OpenFOAM 计算结果与 DeepCFD 预测结果对比</figcaption> | ||
</figure> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
图片下面加一句简单结论:可以看到DeepCFD方法与OpenFOAM的结果基本一致
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* add deepcdf * fix bugs * add comment * add comment * add comment * code style * add license * code style * fix * fix * fix * fix * fix * add validator * fix * add validator * add doc * fix * fix * fix * fix * refine doc
PR types
Others
PR changes
Others
Describe
题目:#439
复现的验收标准如下:
Total MSE = 2.03±0.136
Ux MSE = 0.773±0.0897
Uy MSE =0.2153±0.0186
p MSE =1.042±0.0431
本次复现的实现指标如下:
Total MSE = 2.07983
Ux MSE = 0.79234
Uy MSE = 0.21595
p MSE = 1.07154