Skip to content

Commit 0ec4019

Browse files
[Fix] Fix phylstm (#943)
* fix phylstm running error * update version warning * fix amgnet doc(test=document_fix) * fix deepcfd * fix deepcfd
1 parent 8c76122 commit 0ec4019

File tree

6 files changed

+43
-41
lines changed

6 files changed

+43
-41
lines changed

docs/zh/examples/amgnet.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ unzip data.zip
183183

184184
=== "airfoil"
185185

186-
``` yaml linenums="41"
186+
``` yaml linenums="50"
187187
--8<--
188-
examples/amgnet/conf/amgnet_airfoil.yaml:41:51
188+
examples/amgnet/conf/amgnet_airfoil.yaml:50:52
189189
--8<--
190190
```
191191

192192
=== "cylinder"
193193

194-
``` yaml linenums="41"
194+
``` yaml linenums="50"
195195
--8<--
196-
examples/amgnet/conf/amgnet_cylinder.yaml:41:51
196+
examples/amgnet/conf/amgnet_cylinder.yaml:50:52
197197
--8<--
198198
```
199199

@@ -280,14 +280,14 @@ unzip data.zip
280280

281281
``` py linenums="138"
282282
--8<--
283-
examples/amgnet/amgnet_airfoil.py:138:
283+
examples/amgnet/amgnet_airfoil.py:138:151
284284
--8<--
285285
```
286286
=== "cylinder"
287287

288288
``` py linenums="138"
289289
--8<--
290-
examples/amgnet/amgnet_cylinder.py:138:
290+
examples/amgnet/amgnet_cylinder.py:138:151
291291
--8<--
292292
```
293293

docs/zh/examples/phylstm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ examples/phylstm/phylstm2.py:148:170
126126

127127
接下来我们需要指定训练轮数,此处我们按实验经验,使用 100 轮训练轮数。
128128

129-
``` yaml linenums="39"
129+
``` yaml linenums="38"
130130
--8<--
131-
examples/phylstm/conf/phylstm2.yaml:39:39
131+
examples/phylstm/conf/phylstm2.yaml:38:40
132132
--8<--
133133
```
134134

examples/deepcfd/deepcfd.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import hydra
2222
import numpy as np
23+
import paddle
2324
from matplotlib import pyplot as plt
2425
from omegaconf import DictConfig
2526

@@ -34,7 +35,9 @@ def split_tensors(
3435
3536
Args:
3637
tensors (List[np.array]): Non-empty tensor list.
37-
ratio (float): Split ratio. For example, tensor list A is split to A1 and A2. len(A1) / len(A) = ratio.
38+
ratio (float): Split ratio. For example, tensor list A is split to A1 and A2.
39+
len(A1) / len(A) = ratio.
40+
3841
Returns:
3942
Tuple[List[np.array], List[np.array]]: Split tensors.
4043
"""
@@ -192,10 +195,7 @@ def predict_and_save_plot(
192195
plt.colorbar(orientation="horizontal")
193196
plt.tight_layout()
194197
plt.show()
195-
plt.savefig(
196-
os.path.join(plot_dir, f"cfd_{index}.png"),
197-
bbox_inches="tight",
198-
)
198+
plt.savefig(os.path.join(plot_dir, f"cfd_{index}.png"), bbox_inches="tight")
199199

200200

201201
def train(cfg: DictConfig):
@@ -376,17 +376,17 @@ def evaluate(cfg: DictConfig):
376376

377377
# define loss
378378
def loss_expr(
379-
output_dict: Dict[str, np.ndarray],
380-
label_dict: Dict[str, np.ndarray] = None,
381-
weight_dict: Dict[str, np.ndarray] = None,
382-
) -> float:
379+
output_dict: Dict[str, "paddle.Tensor"],
380+
label_dict: Dict[str, "paddle.Tensor"] = None,
381+
weight_dict: Dict[str, "paddle.Tensor"] = None,
382+
) -> Dict[str, "paddle.Tensor"]:
383383
output = output_dict["output"]
384384
y = label_dict["output"]
385385
loss_u = (output[:, 0:1, :, :] - y[:, 0:1, :, :]) ** 2
386386
loss_v = (output[:, 1:2, :, :] - y[:, 1:2, :, :]) ** 2
387387
loss_p = (output[:, 2:3, :, :] - y[:, 2:3, :, :]).abs()
388388
loss = (loss_u + loss_v + loss_p) / CHANNELS_WEIGHTS
389-
return loss.sum()
389+
return {"custom_loss": loss.sum()}
390390

391391
# manually build validator
392392
eval_dataloader_cfg = {
@@ -404,10 +404,10 @@ def loss_expr(
404404
}
405405

406406
def metric_expr(
407-
output_dict: Dict[str, np.ndarray],
408-
label_dict: Dict[str, np.ndarray] = None,
409-
weight_dict: Dict[str, np.ndarray] = None,
410-
) -> Dict[str, float]:
407+
output_dict: Dict[str, "paddle.Tensor"],
408+
label_dict: Dict[str, "paddle.Tensor"] = None,
409+
weight_dict: Dict[str, "paddle.Tensor"] = None,
410+
) -> Dict[str, "paddle.Tensor"]:
411411
output = output_dict["output"]
412412
y = label_dict["output"]
413413
total_mse = ((output - y) ** 2).sum() / len(test_x)

examples/phylstm/conf/phylstm2.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
defaults:
2+
- ppsci_default
3+
- TRAIN: train_default
4+
- TRAIN/ema: ema_default
5+
- TRAIN/swa: swa_default
6+
- EVAL: eval_default
7+
- INFER: infer_default
8+
- hydra/job/config/override_dirname/exclude_keys: exclude_keys_default
9+
- _self_
10+
111
hydra:
212
run:
313
# dynamic output directory according to running time and override name
414
dir: outputs_PhyLSTM2/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname}
515
job:
616
name: ${mode} # name of logfile
717
chdir: false # keep current working directory unchanged
8-
config:
9-
override_dirname:
10-
exclude_keys:
11-
- TRAIN.checkpoint_path
12-
- TRAIN.pretrained_model_path
13-
- EVAL.pretrained_model_path
14-
- mode
15-
- output_dir
16-
- log_freq
1718
sweep:
1819
# output directory for multirun
1920
dir: ${hydra.run.dir}

examples/phylstm/conf/phylstm3.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
defaults:
2+
- ppsci_default
3+
- TRAIN: train_default
4+
- TRAIN/ema: ema_default
5+
- TRAIN/swa: swa_default
6+
- EVAL: eval_default
7+
- INFER: infer_default
8+
- hydra/job/config/override_dirname/exclude_keys: exclude_keys_default
9+
- _self_
10+
111
hydra:
212
run:
313
# dynamic output directory according to running time and override name
414
dir: outputs_PhyLSTM3/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname}
515
job:
616
name: ${mode} # name of logfile
717
chdir: false # keep current working directory unchanged
8-
config:
9-
override_dirname:
10-
exclude_keys:
11-
- TRAIN.checkpoint_path
12-
- TRAIN.pretrained_model_path
13-
- EVAL.pretrained_model_path
14-
- mode
15-
- output_dir
16-
- log_freq
1718
sweep:
1819
# output directory for multirun
1920
dir: ${hydra.run.dir}

ppsci/solver/solver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def dist_wrapper(model: nn.Layer) -> paddle.DataParallel:
450450
if version.Version(paddle.__version__) < version.Version("2.6.0"):
451451
logger.warning(
452452
f"Detected paddlepaddle version is '{paddle_version}', "
453-
"currently it is recommended to use release 2.6 or develop version."
453+
"currently it is recommended to use paddlepaddle >= 2.6 or develop version."
454454
)
455455
else:
456456
paddle_version = f"develop({paddle.version.commit[:7]})"

0 commit comments

Comments
 (0)