Skip to content

Commit 20028f6

Browse files
Merge branch 'develop' into fix_allen_cahn
2 parents 0d0f508 + c0fa8ca commit 20028f6

20 files changed

+211
-38
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ PaddleScience 是一个基于深度学习框架 PaddlePaddle 开发的科学计
2626
| 问题类型 | 案例名称 | 优化算法 | 模型类型 | 训练方式 | 数据集 | 参考资料 |
2727
|-----|---------|-----|---------|----|---------|---------|
2828
| 微分方程 | [拉普拉斯方程](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/laplace2d) | 机理驱动 | MLP | 无监督学习 | - | - |
29-
| 微分方程 | [伯格斯方程](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/deephpms) | 机理驱动 | MLP | 无监督学习 | [Data](https://github.com/maziarraissi/DeepHPMs/tree/master/Data) | [Paper](https://arxiv.org/pdf/1801.06637.pdf) |</center>
29+
| 微分方程 | [伯格斯方程](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/deephpms) | 机理驱动 | MLP | 无监督学习 | [Data](https://github.com/maziarraissi/DeepHPMs/tree/master/Data) | [Paper](https://arxiv.org/pdf/1801.06637.pdf) |
3030
| 微分方程 | [非线性偏微分方程](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/pirbn) | 机理驱动 | PIRBN | 无监督学习 | - | [Paper](https://arxiv.org/abs/2304.06234) |
3131
| 微分方程 | [洛伦兹方程](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/lorenz) | 数据驱动 | Transformer-Physx | 监督学习 | [Data](https://github.com/zabaras/transformer-physx) | [Paper](https://arxiv.org/abs/2010.03957) |
3232
| 微分方程 | [若斯叻方程](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/rossler) | 数据驱动 | Transformer-Physx | 监督学习 | [Data](https://github.com/zabaras/transformer-physx) | [Paper](https://arxiv.org/abs/2010.03957) |
3333
| 算子学习 | [DeepONet](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/deeponet) | 数据驱动 | MLP | 监督学习 | [Data](https://deepxde.readthedocs.io/en/latest/demos/operator/antiderivative_unaligned.html) | [Paper](https://export.arxiv.org/pdf/1910.03193.pdf) |
3434
| 微分方程 | [梯度增强的物理知识融合 PDE 求解](https://github.com/PaddlePaddle/PaddleScience/blob/develop/examples/gpinn/poisson_1d.py) | 机理驱动 | gPINN | 无监督学习 | - | [Paper](https://doi.org/10.1016/j.cma.2022.114823) |
3535
| 积分方程 | [沃尔泰拉积分方程](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/volterra_ide) | 机理驱动 | MLP | 无监督学习 | - | [Project](https://github.com/lululxvi/deepxde/blob/master/examples/pinn_forward/Volterra_IDE.py) |
3636
| 微分方程 | [分数阶微分方程](https://github.com/PaddlePaddle/PaddleScience/blob/develop/examples/fpde/fractional_poisson_2d.py) | 机理驱动 | MLP | 无监督学习 | - | - |
37+
| 光孤子 | [Optical soliton](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/nlsmb) | 机理驱动 | MLP | 无监督学习 | - | [Paper](https://doi.org/10.1007/s11071-023-08824-w)|
38+
| 光纤怪波 | [Optical rogue wave](https://paddlescience-docs.readthedocs.io/zh/latest/zh/examples/nlsmb) | 机理驱动 | MLP | 无监督学习 | - | [Paper](https://doi.org/10.1007/s11071-023-08824-w)|
3739

3840
<br>
3941
<p align="center"><b>技术科学(AI for Technology)</b></p>

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
| 微分方程 | [梯度增强的物理知识融合 PDE 求解](https://github.com/PaddlePaddle/PaddleScience/blob/develop/examples/gpinn/poisson_1d.py) | 机理驱动 | gPINN | 无监督学习 | - | [Paper](https://doi.org/10.1016/j.cma.2022.114823) |
8080
| 积分方程 | [沃尔泰拉积分方程](./zh/examples/volterra_ide.md) | 机理驱动 | MLP | 无监督学习 | - | [Project](https://github.com/lululxvi/deepxde/blob/master/examples/pinn_forward/Volterra_IDE.py) |
8181
| 微分方程 | [分数阶微分方程](https://github.com/PaddlePaddle/PaddleScience/blob/develop/examples/fpde/fractional_poisson_2d.py) | 机理驱动 | MLP | 无监督学习 | - | - |
82+
| 光孤子 | [Optical soliton](./zh/examples/nlsmb.md) | 机理驱动 | MLP | 无监督学习 | - | [Paper](https://doi.org/10.1007/s11071-023-08824-w)|
83+
| 光纤怪波 | [Optical rogue wave](./zh/examples/nlsmb.md) | 机理驱动 | MLP | 无监督学习 | - | [Paper](https://doi.org/10.1007/s11071-023-08824-w)|
8284

8385
<br>
8486
<p align="center"><b>技术科学(AI for Technology)</b></p>

docs/zh/examples/biharmonic2d.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
python biharmonic2d.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/biharmonic2d/biharmonic2d_pretrained.pdparams
1515
```
1616

17+
=== "模型导出命令"
18+
19+
``` sh
20+
python biharmonic2d.py mode=export
21+
```
22+
23+
=== "模型推理命令"
24+
25+
``` sh
26+
python biharmonic2d.py mode=infer
27+
```
28+
1729
| 预训练模型 | 指标 |
1830
|:--| :--|
1931
| [biharmonic2d_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/biharmonic2d/biharmonic2d_pretrained.pdparams) | l2_error: 0.02774 |

docs/zh/examples/nlsmb.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141

4242
| 预训练模型 | 指标 |
4343
|:--| :--|
44-
| [NLS-MB_soliton_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/NLS-MB/NLS-MB_soliton_pretrained.pdparams) | loss(Residual): 0.00007<br>MSE.Schrodinger_1(Residual): 0.00002<br>MSE.Schrodinger_2(Residual): 0.00002<br>MSE.Maxwell_1(Residual): 0.00001<br>MSE.Maxwell_2(Residual): 0.00001<br>MSE.Bloch(Residual): 0.00001 |
44+
| [NLS-MB_soliton_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/NLS-MB/NLS-MB_soliton_pretrained.pdparams) | Residual/loss: 0.00000<br>Residual/MSE.Schrodinger_1: 0.00000<br>Residual/MSE.Schrodinger_2: 0.00000<br>Residual/MSE.Maxwell_1: 0.00000<br>Residual/MSE.Maxwell_2: 0.00000<br>Residual/MSE.Bloch: 0.00000 |
45+
| [NLS-MB_optical_rogue_wave.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/NLS-MB/NLS-MB_optical_rogue_wave.pdparams) | Residual/loss: 0.00001<br>Residual/MSE.Schrodinger_1: 0.00000<br>Residual/MSE.Schrodinger_2: 0.00000<br>Residual/MSE.Maxwell_1: 0.00000<br>Residual/MSE.Maxwell_2: 0.00000<br>Residual/MSE.Bloch: 0.00000 |
4546

4647
## 1. 背景简介
4748

@@ -238,18 +239,18 @@ examples/NLS-MB/NLS-MB_optical_soliton.py
238239

239240
<figure markdown>
240241
![optical_soliton](https://paddle-org.bj.bcebos.com/paddlescience/docs/NLS-MB/pred_optical_soliton.png){ loading=lazy}
241-
<figcaption>解析解结果与 PINN 预测结果对比,从上到下分别为:慢变电场(E),共振偏量(p)以及粒子数反转程度($\eta$)</figcaption>
242+
<figcaption>解析解结果与 PINN 预测结果对比,从上到下分别为:慢变电场(E),共振偏量(p)以及粒子数反转程度(eta)</figcaption>
242243
</figure>
243244

244245
### 5.2 optical_rogue_wave
245246

246247
<figure markdown>
247248
![optical_rogue_wave](https://paddle-org.bj.bcebos.com/paddlescience/docs/NLS-MB/pred_optical_rogue_wave.png){ loading=lazy}
248-
<figcaption>解析解结果与 PINN 预测结果对比,从上到下分别为:慢变电场(E),共振偏量(p)以及粒子数反转程度($\eta$)</figcaption>
249+
<figcaption>解析解结果与 PINN 预测结果对比,从上到下分别为:慢变电场(E),共振偏量(p)以及粒子数反转程度(eta)</figcaption>
249250
</figure>
250251

251252
可以看到PINN预测与解析解的结果基本一致。
252253

253254
## 6. 参考资料
254255

255-
[1] [S.-Y. Xu, Q. Zhou, and W. Liu, Prediction of Soliton Evolution and Equation Parameters for NLS–MB Equation Based on the phPINN Algorithm, Nonlinear Dyn (2023)](https://doi.org/10.1007/s11071-023-08824-w).
256+
[1] [S.-Y. Xu, Q. Zhou, and W. Liu, Prediction of Soliton Evolution and Equation Parameters for NLS–MB Equation Based on the phPINN Algorithm, Nonlinear Dyn (2023)](https://doi.org/10.1007/s11071-023-08824-w).

examples/NLS-MB/NLS-MB_optical_rogue_wave.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
def analytic_solution(out):
2727
I = 1j
28-
x = out["x"]
2928
t = out["t"]
29+
x = out["x"]
3030
EExact = (
3131
(-1565 * x**2 + (648 * I + 76 * t) * x - 68 * t**2 + 51)
3232
* np.exp(-I / 8 * (-12 * t + 65 * x))
@@ -149,14 +149,14 @@ def train(cfg: DictConfig):
149149
idx_ub = np.random.choice(np.where(ub)[0], 200, replace=False)
150150
icbc_idx = np.hstack((idx_lb, idx_ic, idx_ub))
151151
X_u_train = X_star[icbc_idx].astype("float32")
152-
X_u_train = {"x": X_u_train[:, 0:1], "t": X_u_train[:, 1:2]}
152+
X_u_train = {"t": X_u_train[:, 1:2], "x": X_u_train[:, 0:1]}
153153

154154
Eu_train, Ev_train, pu_train, pv_train, eta_train = analytic_solution(X_u_train)
155155

156156
train_dataloader_cfg = {
157157
"dataset": {
158158
"name": "NamedArrayDataset",
159-
"input": {"x": X_u_train["x"], "t": X_u_train["t"]},
159+
"input": {"t": X_u_train["t"], "x": X_u_train["x"]},
160160
"label": {
161161
"Eu": Eu_train,
162162
"Ev": Ev_train,
@@ -278,8 +278,8 @@ def train(cfg: DictConfig):
278278
vis_points = geom["time_interval"].sample_interior(20000, evenly=True)
279279
Eu_true, Ev_true, pu_true, pv_true, eta_true = analytic_solution(vis_points)
280280
pred = solver.predict(vis_points, return_numpy=True)
281-
x = vis_points["x"][:, 0]
282281
t = vis_points["t"][:, 0]
282+
x = vis_points["x"][:, 0]
283283
E_ref = np.sqrt(Eu_true**2 + Ev_true**2)[:, 0]
284284
E_pred = np.sqrt(pred["Eu"] ** 2 + pred["Ev"] ** 2)[:, 0]
285285
p_ref = np.sqrt(pu_true**2 + pv_true**2)[:, 0]
@@ -354,8 +354,8 @@ def evaluate(cfg: DictConfig):
354354
vis_points = geom["time_interval"].sample_interior(20000, evenly=True)
355355
Eu_true, Ev_true, pu_true, pv_true, eta_true = analytic_solution(vis_points)
356356
pred = solver.predict(vis_points, return_numpy=True)
357-
x = vis_points["x"][:, 0]
358357
t = vis_points["t"][:, 0]
358+
x = vis_points["x"][:, 0]
359359
E_ref = np.sqrt(Eu_true**2 + Ev_true**2)[:, 0]
360360
E_pred = np.sqrt(pred["Eu"] ** 2 + pred["Ev"] ** 2)[:, 0]
361361
p_ref = np.sqrt(pu_true**2 + pv_true**2)[:, 0]
@@ -417,11 +417,25 @@ def inference(cfg: DictConfig):
417417
store_key: output_dict[infer_key]
418418
for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys())
419419
}
420+
# TODO: Fix this mapping diff in dy2st
421+
(
422+
output_dict["Eu"],
423+
output_dict["Ev"],
424+
output_dict["eta"],
425+
output_dict["pu"],
426+
output_dict["pv"],
427+
) = (
428+
output_dict["Eu"],
429+
output_dict["Ev"],
430+
output_dict["pu"],
431+
output_dict["pv"],
432+
output_dict["eta"],
433+
)
420434

421435
# visualize prediction
422436
Eu_true, Ev_true, pu_true, pv_true, eta_true = analytic_solution(input_dict)
423-
x = input_dict["x"][:, 0]
424437
t = input_dict["t"][:, 0]
438+
x = input_dict["x"][:, 0]
425439
E_ref = np.sqrt(Eu_true**2 + Ev_true**2)[:, 0]
426440
E_pred = np.sqrt(output_dict["Eu"] ** 2 + output_dict["Ev"] ** 2)[:, 0]
427441
p_ref = np.sqrt(pu_true**2 + pv_true**2)[:, 0]

examples/NLS-MB/NLS-MB_optical_soliton.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def analytic_solution(out):
27-
x, t = out["x"], out["t"]
27+
t, x = out["t"], out["x"]
2828
Eu_true = 2 * np.cos(2 * t) / np.cosh(2 * t + 6 * x)
2929

3030
Ev_true = -2 * np.sin(2 * t) / np.cosh(2 * t + 6 * x)
@@ -83,7 +83,6 @@ def plot(
8383
plt.subplot(3, 3, 9)
8484
plt.title("eta_diff")
8585
plt.tricontourf(x, t, np.abs(eta_ref - eta_pred), levels=256, cmap="jet")
86-
8786
fig_path = osp.join(output_dir, "pred_optical_soliton.png")
8887
print(f"Saving figure to {fig_path}")
8988
fig.savefig(fig_path, bbox_inches="tight", dpi=400)
@@ -127,14 +126,14 @@ def train(cfg: DictConfig):
127126
idx_ub = np.random.choice(np.where(ub)[0], 200, replace=False)
128127
icbc_idx = np.hstack((idx_lb, idx_ic, idx_ub))
129128
X_u_train = X_star[icbc_idx].astype("float32")
130-
X_u_train = {"x": X_u_train[:, 0:1], "t": X_u_train[:, 1:2]}
129+
X_u_train = {"t": X_u_train[:, 1:2], "x": X_u_train[:, 0:1]}
131130

132131
Eu_train, Ev_train, pu_train, pv_train, eta_train = analytic_solution(X_u_train)
133132

134133
train_dataloader_cfg = {
135134
"dataset": {
136135
"name": "NamedArrayDataset",
137-
"input": {"x": X_u_train["x"], "t": X_u_train["t"]},
136+
"input": {"t": X_u_train["t"], "x": X_u_train["x"]},
138137
"label": {
139138
"Eu": Eu_train,
140139
"Ev": Ev_train,
@@ -256,8 +255,8 @@ def train(cfg: DictConfig):
256255
vis_points = geom["time_interval"].sample_interior(20000, evenly=True)
257256
Eu_true, Ev_true, pu_true, pv_true, eta_true = analytic_solution(vis_points)
258257
pred = solver.predict(vis_points, return_numpy=True)
259-
x = vis_points["x"][:, 0]
260258
t = vis_points["t"][:, 0]
259+
x = vis_points["x"][:, 0]
261260
E_ref = np.sqrt(Eu_true**2 + Ev_true**2)[:, 0]
262261
E_pred = np.sqrt(pred["Eu"] ** 2 + pred["Ev"] ** 2)[:, 0]
263262
p_ref = np.sqrt(pu_true**2 + pv_true**2)[:, 0]
@@ -332,8 +331,8 @@ def evaluate(cfg: DictConfig):
332331
vis_points = geom["time_interval"].sample_interior(20000, evenly=True)
333332
Eu_true, Ev_true, pu_true, pv_true, eta_true = analytic_solution(vis_points)
334333
pred = solver.predict(vis_points, return_numpy=True)
335-
x = vis_points["x"][:, 0]
336334
t = vis_points["t"][:, 0]
335+
x = vis_points["x"][:, 0]
337336
E_ref = np.sqrt(Eu_true**2 + Ev_true**2)[:, 0]
338337
E_pred = np.sqrt(pred["Eu"] ** 2 + pred["Ev"] ** 2)[:, 0]
339338
p_ref = np.sqrt(pu_true**2 + pv_true**2)[:, 0]
@@ -395,11 +394,25 @@ def inference(cfg: DictConfig):
395394
store_key: output_dict[infer_key]
396395
for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys())
397396
}
397+
# TODO: Fix this mapping diff in dy2st
398+
(
399+
output_dict["Eu"],
400+
output_dict["Ev"],
401+
output_dict["eta"],
402+
output_dict["pu"],
403+
output_dict["pv"],
404+
) = (
405+
output_dict["Eu"],
406+
output_dict["Ev"],
407+
output_dict["pu"],
408+
output_dict["pv"],
409+
output_dict["eta"],
410+
)
398411

399412
# visualize prediction
400413
Eu_true, Ev_true, pu_true, pv_true, eta_true = analytic_solution(input_dict)
401-
x = input_dict["x"][:, 0]
402414
t = input_dict["t"][:, 0]
415+
x = input_dict["x"][:, 0]
403416
E_ref = np.sqrt(Eu_true**2 + Ev_true**2)[:, 0]
404417
E_pred = np.sqrt(output_dict["Eu"] ** 2 + output_dict["Ev"] ** 2)[:, 0]
405418
p_ref = np.sqrt(pu_true**2 + pv_true**2)[:, 0]

examples/NLS-MB/conf/NLS-MB_rogue_wave.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ hydra:
2525
# general settings
2626
mode: train # running mode: train/eval
2727
seed: 42
28-
log_freq: 20
28+
log_freq: 100
2929
output_dir: ${hydra:run.dir}
3030
NPOINT_INTERIOR: 20000
3131
NPOINT_BC: 600
3232
NTIME_ALL: 200
3333

34-
3534
# model settings
3635
MODEL:
37-
input_keys: ["x", "t"]
36+
input_keys: ["t", "x"]
3837
output_keys: ["Eu", "Ev", "pu", "pv", "eta"]
3938
num_layers: 5
4039
hidden_size: 64
@@ -57,7 +56,7 @@ TRAIN:
5756
# evaluation settings
5857
EVAL:
5958
pretrained_model_path: null
60-
eval_with_no_grad: true
59+
eval_with_no_grad: false
6160

6261
INFER:
6362
pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/NLS-MB/NLS-MB_rogue_wave_pretrained.pdparams

examples/NLS-MB/conf/NLS-MB_soliton.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ hydra:
2525
# general settings
2626
mode: train # running mode: train/eval
2727
seed: 42
28-
log_freq: 20
28+
log_freq: 100
2929
output_dir: ${hydra:run.dir}
3030
NPOINT_INTERIOR: 20000
3131
NPOINT_BC: 600
3232
NTIME_ALL: 200
3333

3434
# model settings
3535
MODEL:
36-
input_keys: ["x", "t"]
36+
input_keys: ["t", "x"]
3737
output_keys: ["Eu", "Ev", "pu", "pv", "eta"]
3838
num_layers: 5
3939
hidden_size: 64
@@ -56,7 +56,7 @@ TRAIN:
5656
# evaluation settings
5757
EVAL:
5858
pretrained_model_path: null
59-
eval_with_no_grad: true
59+
eval_with_no_grad: false
6060

6161
INFER:
6262
pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/NLS-MB/NLS-MB_soliton_pretrained.pdparams

0 commit comments

Comments
 (0)