From 20ad460c469585246c4b16f8923b67bdb039569a Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Mon, 6 Nov 2023 22:08:26 +0800 Subject: [PATCH 01/15] add shock_wave --- docs/zh/examples/shock_wave.md | 23 +++++ examples/shock_wave/conf/shock_wave.yaml | 88 +++++++++++++++++ examples/shock_wave/shock_wave.py | 119 ++++++++++++----------- 3 files changed, 171 insertions(+), 59 deletions(-) create mode 100644 examples/shock_wave/conf/shock_wave.yaml diff --git a/docs/zh/examples/shock_wave.md b/docs/zh/examples/shock_wave.md index c094ae938..e6466970c 100644 --- a/docs/zh/examples/shock_wave.md +++ b/docs/zh/examples/shock_wave.md @@ -2,6 +2,29 @@ AI Studio快速体验 + + + + +=== "模型训练命令" + + ``` sh + python poiseuille_flow.py + ``` + +=== "模型评估命令" + + ``` sh + python poiseuille_flow.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/poiseuille_flow/poiseuille_flow_pretrained.pdparams + ``` + + + + + + + + ## 1. 背景简介 激波是自然界以及工程应用中经常发现的现象。它们不仅广泛地存在于航空航天领域的可压缩流动中,而且也表现在理论与应用物理以及工程应用等其它领域。在超声速与高超声速流动中,激波的出现对流体流动的整体特征会产生重要影响。激波捕捉问题已在CFD领域发展了数十年,以弱解的数学理论为基础的激波捕捉方法以其简单易实现的特点发展迅速,并在复杂超声速、高超声速流动数值模拟中得到了广泛应用。 diff --git a/examples/shock_wave/conf/shock_wave.yaml b/examples/shock_wave/conf/shock_wave.yaml new file mode 100644 index 000000000..de7325099 --- /dev/null +++ b/examples/shock_wave/conf/shock_wave.yaml @@ -0,0 +1,88 @@ +hydra: + run: + # dynamic output directory according to running time and override name + dir: outputs_bracket/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname} + job: + name: ${mode} # name of logfile + chdir: false # keep current working direcotry unchaned + config: + override_dirname: + exclude_keys: + - TRAIN.checkpoint_path + - TRAIN.pretrained_model_path + - EVAL.pretrained_model_path + - mode + - output_dir + - log_freq + sweep: + # output directory for multirun + dir: ${hydra.run.dir} + subdir: ./ + +# general settings +mode: train # running mode: train/eval +seed: 2023 +output_dir: ${hydra:run.dir} +log_freq: 20 + +# set working condition +MA: 2.0 + +# set hyper-parameters +Lt: 0.4 +Lx: 1.5 +Ly: 2.0 +rx: 1.0 +ry: 1.0 +rd: 0.25 +N_INTERIOR: 100000 +N_BOUNDARY: 10000 +RHO1: 2.112 +P1: 3.001 +GAMMA: 1.4 +V1: 0.0 + + +# visualize prediction +Nd: 600 +T: 0.4 + +# model settings +MODEL: + model: + input_keys: ["t", "x", "y"] + output_keys: ["u", "v", "p", "rho"] + num_layers: 9 + hidden_size: 90 + activation: "tanh" + + +# training settings +TRAIN: + epochs: 2000 + iters_per_epoch: 1000 + save_freq: 50 + eval_during_train: true + eval_freq: 20 + lr_scheduler: + epochs: ${TRAIN.epochs} + iters_per_epoch: ${TRAIN.iters_per_epoch} + learning_rate: 1e-1 + max_iter: 100 + # batch_size: + # bc_back: 1024 + # bc_front: 128 + # bc_surface: 4096 + # support_interior: 2048 + # bracket_interior: 1024 + # weight: + # bc_back: {"u": 10, "v": 10, "w": 10} + pretrained_model_path: null + checkpoint_path: null + +# evaluation settings +EVAL: + pretrained_model_path: null + eval_with_no_grad: true + # batch_size: + # sup_validator: 128 diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index 303ad2ae0..72cbeb18f 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -14,11 +14,17 @@ from os import path as osp +import hydra import lhs import numpy as np import paddle from matplotlib import pyplot as plt + +from omegaconf import DictConfig + +import sys; sys.path.append(r"") + import ppsci from ppsci import equation from ppsci.autodiff import jacobian @@ -236,64 +242,49 @@ def generate_bc_left_points( return u_init, v_init, p_init, rho_init -if __name__ == "__main__": - args = config.parse_args() +def train(cfg: DictConfig): + # set random seed for reproducibility - SEED = 42 - ppsci.utils.misc.set_random_seed(SEED) - MA = 2.0 - # MA = 0.728 + ppsci.utils.misc.set_random_seed(cfg.seed) + # set output directory OUTPUT_DIR = ( - f"./output_shock_wave_{MA:.3f}" if not args.output_dir else args.output_dir + f"./output_shock_wave_{cfg.MA:.3f}" if not cfg.output_dir else cfg.output_dir ) # initialize logger - logger.init_logger("ppsci", f"{OUTPUT_DIR}/train.log", "info") + logger.init_logger("ppsci", osp.join(cfg.output_dir, "train.log"), "info") # set model - model = ppsci.arch.MLP(("t", "x", "y"), ("u", "v", "p", "rho"), 9, 90, "tanh") + model = ppsci.arch.MLP(**cfg.MODEL.model) # set equation equation = {"Euler2D": Euler2D(), "BC_EQ": BC_EQ()} - # set hyper-parameters - Lt = 0.4 - Lx = 1.5 - Ly = 2.0 - rx = 1.0 - ry = 1.0 - rd = 0.25 - N_INTERIOR = 100000 - N_BOUNDARY = 10000 - RHO1 = 2.112 - P1 = 3.001 - GAMMA = 1.4 - V1 = 0.0 # Latin HyperCube Sampling # generate PDE data - xlimits = np.array([[0.0, 0.0, 0.0], [Lt, Lx, Ly]]).T - name_value = ("t", "x", "y") - doe_lhs = lhs.LHS(N_INTERIOR, xlimits) + xlimits = np.array([[0.0, 0.0, 0.0], [cfg.Lt, cfg.Lx, cfg.Ly]]).T + name_value = cfg.MODEL.model.input_keys + doe_lhs = lhs.LHS(cfg.N_INTERIOR, xlimits) x_int_train = doe_lhs.get_sample() x_int_train = x_int_train[ - ~((x_int_train[:, 1] - rx) ** 2 + (x_int_train[:, 2] - ry) ** 2 < rd**2) + ~((x_int_train[:, 1] - cfg.rx) ** 2 + (x_int_train[:, 2] - cfg.ry) ** 2 < cfg.rd**2) ] x_int_train_dict = misc.convert_to_dict(x_int_train, name_value) - y_int_train = np.zeros([len(x_int_train), len(model.output_keys)], dtype) + y_int_train = np.zeros([len(x_int_train), len(cfg.MODEL.model.output_keys)], dtype) y_int_train_dict = misc.convert_to_dict( y_int_train, tuple(equation["Euler2D"].equations.keys()) ) # generate BC data(left, right side) - xlimits = np.array([[0.0, 0.0, 0.0], [Lt, 0.0, Ly]]).T - doe_lhs = lhs.LHS(N_BOUNDARY, xlimits) + xlimits = np.array([[0.0, 0.0, 0.0], [cfg.Lt, 0.0, cfg.Ly]]).T + doe_lhs = lhs.LHS(cfg.N_BOUNDARY, xlimits) x_bcL_train = doe_lhs.get_sample() x_bcL_train_dict = misc.convert_to_dict(x_bcL_train, name_value) u_bcL_train, v_bcL_train, p_bcL_train, rho_bcL_train = generate_bc_left_points( - x_bcL_train, MA, RHO1, P1, V1, GAMMA + x_bcL_train, cfg.MA, cfg.RHO1, cfg.P1, cfg.V1, cfg.GAMMA ) y_bcL_train = np.concatenate( [ @@ -310,7 +301,7 @@ def generate_bc_left_points( ) x_bcI_train, sin_bcI_train, cos_bcI_train = generate_bc_down_circle_points( - Lt, rx, ry, rd, N_BOUNDARY + cfg.Lt, cfg.rx, cfg.ry, cfg.rd, cfg.N_BOUNDARY ) x_bcI_train_dict = misc.convert_to_dict( np.concatenate([x_bcI_train, sin_bcI_train, cos_bcI_train], axis=1), @@ -322,20 +313,20 @@ def generate_bc_left_points( ) # generate IC data - xlimits = np.array([[0.0, 0.0, 0.0], [0.0, Lx, Ly]]).T - doe_lhs = lhs.LHS(N_BOUNDARY, xlimits) + xlimits = np.array([[0.0, 0.0, 0.0], [0.0, cfg.Lx, cfg.Ly]]).T + doe_lhs = lhs.LHS(cfg.N_BOUNDARY, xlimits) x_ic_train = doe_lhs.get_sample() x_ic_train = x_ic_train[ - ~((x_ic_train[:, 1] - rx) ** 2 + (x_ic_train[:, 2] - ry) ** 2 < rd**2) + ~((x_ic_train[:, 1] - cfg.rx) ** 2 + (x_ic_train[:, 2] - cfg.ry) ** 2 < cfg.rd**2) ] x_ic_train_dict = misc.convert_to_dict(x_ic_train, name_value) - U1 = np.sqrt(GAMMA * P1 / RHO1) * MA + U1 = np.sqrt(cfg.GAMMA * cfg.P1 / cfg.RHO1) * cfg.MA y_ic_train = np.concatenate( [ np.full([len(x_ic_train), 1], U1, dtype), np.full([len(x_ic_train), 1], 0, dtype), - np.full([len(x_ic_train), 1], P1, dtype), - np.full([len(x_ic_train), 1], RHO1, dtype), + np.full([len(x_ic_train), 1], cfg.P1, dtype), + np.full([len(x_ic_train), 1], cfg.RHO1, dtype), ], axis=1, ) @@ -345,7 +336,6 @@ def generate_bc_left_points( ) # set constraints - ITERS_PER_EPOCH = 1 pde_constraint = ppsci.constraint.SupervisedConstraint( { "dataset": { @@ -353,7 +343,7 @@ def generate_bc_left_points( "input": x_int_train_dict, "label": y_int_train_dict, }, - "iters_per_epoch": ITERS_PER_EPOCH, + "iters_per_epoch": cfg.TRAIN.iters_per_epoch, }, ppsci.loss.MSELoss("mean"), output_expr=equation["Euler2D"].equations, @@ -366,7 +356,7 @@ def generate_bc_left_points( "input": x_ic_train_dict, "label": y_ic_train_dict, }, - "iters_per_epoch": ITERS_PER_EPOCH, + "iters_per_epoch": cfg.TRAIN.iters_per_epoch, }, ppsci.loss.MSELoss("mean", weight=10), name="IC", @@ -378,7 +368,7 @@ def generate_bc_left_points( "input": x_bcI_train_dict, "label": y_bcI_train_dict, }, - "iters_per_epoch": ITERS_PER_EPOCH, + "iters_per_epoch": cfg.TRAIN.iters_per_epoch, }, ppsci.loss.MSELoss("mean", weight=10), output_expr=equation["BC_EQ"].equations, @@ -391,7 +381,7 @@ def generate_bc_left_points( "input": x_bcL_train_dict, "label": y_bcL_train_dict, }, - "iters_per_epoch": ITERS_PER_EPOCH, + "iters_per_epoch": cfg.TRAIN.iters_per_epoch, }, ppsci.loss.MSELoss("mean", weight=10), name="BCL", @@ -404,10 +394,11 @@ def generate_bc_left_points( } # set optimizer - optimizer = ppsci.optimizer.LBFGS(1e-1, max_iter=100)(model) + optimizer = ppsci.optimizer.LBFGS(cfg.TRAIN.lr_scheduler.learning_rate, + max_iter=cfg.TRAIN.lr_scheduler.max_iter)(model) # initialize solver - EPOCHS = 100 if not args.epochs else args.epochs + EPOCHS = 100 if not cfg.TRAIN.epochs else cfg.TRAIN.epochs solver = ppsci.solver.Solver( model, constraint, @@ -415,10 +406,10 @@ def generate_bc_left_points( optimizer, None, EPOCHS, - ITERS_PER_EPOCH, - save_freq=50, - log_freq=20, - seed=SEED, + cfg.TRAIN.iters_per_epoch, + save_freq=cfg.TRAIN.save_freq, + log_freq=cfg.log_freq, + seed=cfg.seed, equation=equation, eval_with_no_grad=True, ) @@ -431,11 +422,9 @@ def generate_bc_left_points( solver.train() # visualize prediction - Nd = 600 - T = 0.4 - t = np.linspace(T, T, 1) - x = np.linspace(0.0, Lx, Nd) - y = np.linspace(0.0, Ly, Nd) + t = np.linspace(cfg.T, cfg.T, 1) + x = np.linspace(0.0, cfg.Lx, cfg.Nd) + y = np.linspace(0.0, cfg.Ly, cfg.Nd) _, x_grid, y_grid = np.meshgrid(t, x, y) x_test = misc.cartesian_product(t, x, y) @@ -452,16 +441,16 @@ def generate_bc_left_points( output_dict["rho"], ) - zero_mask = ((x_test[:, 1] - rx) ** 2 + (x_test[:, 2] - ry) ** 2) < rd**2 + zero_mask = ((x_test[:, 1] - cfg.rx) ** 2 + (x_test[:, 2] - cfg.ry) ** 2) < cfg.rd**2 u[zero_mask] = 0 v[zero_mask] = 0 p[zero_mask] = 0 rho[zero_mask] = 0 - u = u.reshape(Nd, Nd) - v = v.reshape(Nd, Nd) - p = p.reshape(Nd, Nd) - rho = rho.reshape(Nd, Nd) + u = u.reshape(cfg.Nd, cfg.Nd) + v = v.reshape(cfg.Nd, cfg.Nd) + p = p.reshape(cfg.Nd, cfg.Nd) + rho = rho.reshape(cfg.Nd, cfg.Nd) fig, ax = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(15, 15)) @@ -501,4 +490,16 @@ def generate_bc_left_points( axe.set_aspect(1) plt.colorbar() - plt.savefig(osp.join(OUTPUT_DIR, f"shock_wave(Ma_{MA:.3f}).png")) + plt.savefig(osp.join(OUTPUT_DIR, f"shock_wave(Ma_{cfg.MA:.3f}).png")) + + +@hydra.main(version_base=None, config_path="./conf", config_name="shock_wave.yaml") +def main(cfg: DictConfig): + if cfg.mode == "train": + train(cfg) + else: + raise ValueError(f"cfg.mode should in ['train'], but got '{cfg.mode}'") + + +if __name__ == "__main__": + main() \ No newline at end of file From f6e34bc7b4cf9ddea3f6d1edf8e682e5cd99e219 Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Mon, 6 Nov 2023 15:03:45 +0000 Subject: [PATCH 02/15] add py yaml --- examples/shock_wave/conf/shock_wave.yaml | 16 ++------- examples/shock_wave/shock_wave.py | 45 ++++++++++++------------ 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/examples/shock_wave/conf/shock_wave.yaml b/examples/shock_wave/conf/shock_wave.yaml index de7325099..3977cf6b3 100644 --- a/examples/shock_wave/conf/shock_wave.yaml +++ b/examples/shock_wave/conf/shock_wave.yaml @@ -1,7 +1,7 @@ hydra: run: # dynamic output directory according to running time and override name - dir: outputs_bracket/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname} + dir: outputs_shock_wave/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname} job: name: ${mode} # name of logfile chdir: false # keep current working direcotry unchaned @@ -59,8 +59,8 @@ MODEL: # training settings TRAIN: - epochs: 2000 - iters_per_epoch: 1000 + epochs: 100 + iters_per_epoch: 1 save_freq: 50 eval_during_train: true eval_freq: 20 @@ -69,14 +69,6 @@ TRAIN: iters_per_epoch: ${TRAIN.iters_per_epoch} learning_rate: 1e-1 max_iter: 100 - # batch_size: - # bc_back: 1024 - # bc_front: 128 - # bc_surface: 4096 - # support_interior: 2048 - # bracket_interior: 1024 - # weight: - # bc_back: {"u": 10, "v": 10, "w": 10} pretrained_model_path: null checkpoint_path: null @@ -84,5 +76,3 @@ TRAIN: EVAL: pretrained_model_path: null eval_with_no_grad: true - # batch_size: - # sup_validator: 128 diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index 72cbeb18f..a20828aa3 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -19,11 +19,11 @@ import numpy as np import paddle from matplotlib import pyplot as plt +from functools import partial from omegaconf import DictConfig -import sys; sys.path.append(r"") import ppsci from ppsci import equation @@ -32,7 +32,6 @@ from ppsci.utils import logger from ppsci.utils import misc - class Euler2D(equation.PDE): def __init__(self): super().__init__() @@ -40,10 +39,10 @@ def __init__(self): # compute loss factor `relu` dynamically. self.solver: ppsci.solver.Solver = None - def continuity_compute_func(out): + def continuity_compute_func(self, out): relu = max( 0.0, - (solver.global_step // solver.iters_per_epoch + 1) / solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs - 0.05, ) t, x, y = out["t"], out["x"], out["y"] @@ -62,12 +61,12 @@ def continuity_compute_func(out): continuity = (rho__t + rho_u__x + rho_v__y) / lam return continuity - self.add_equation("continuity", continuity_compute_func) + self.add_equation("continuity", partial(continuity_compute_func, self)) - def x_momentum_compute_func(out): + def x_momentum_compute_func(self, out): relu = max( 0.0, - (solver.global_step // solver.iters_per_epoch + 1) / solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs - 0.05, ) t, x, y = out["t"], out["x"], out["y"] @@ -88,12 +87,12 @@ def x_momentum_compute_func(out): x_momentum = (rho_u__t + u1__x + u2__y) / lam return x_momentum - self.add_equation("x_momentum", x_momentum_compute_func) + self.add_equation("x_momentum", partial(x_momentum_compute_func, self)) - def y_momentum_compute_func(out): + def y_momentum_compute_func(self, out): relu = max( 0.0, - (solver.global_step // solver.iters_per_epoch + 1) / solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs - 0.05, ) t, x, y = out["t"], out["x"], out["y"] @@ -114,12 +113,12 @@ def y_momentum_compute_func(out): y_momentum = (rho_v__t + u2__x + u3__y) / lam return y_momentum - self.add_equation("y_momentum", y_momentum_compute_func) + self.add_equation("y_momentum", partial(y_momentum_compute_func, self)) - def energy_compute_func(out): + def energy_compute_func(self, out): relu = max( 0.0, - (solver.global_step // solver.iters_per_epoch + 1) / solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs - 0.05, ) t, x, y = out["t"], out["x"], out["y"] @@ -140,7 +139,7 @@ def energy_compute_func(out): energy = (e__t + e1__x + e2__y) / lam return energy - self.add_equation("energy", energy_compute_func) + self.add_equation("energy", partial(energy_compute_func, self)) class BC_EQ(equation.PDE): @@ -150,10 +149,10 @@ def __init__(self): # compute loss factor `relu` dynamically. self.solver: ppsci.solver.Solver = None - def item1_compute_func(out): + def item1_compute_func(self, out): relu = max( 0.0, - (solver.global_step // solver.iters_per_epoch + 1) / solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs - 0.05, ) x, y = out["x"], out["y"] @@ -168,12 +167,12 @@ def item1_compute_func(out): return item1 - self.add_equation("item1", item1_compute_func) + self.add_equation("item1", partial(item1_compute_func, self)) - def item2_compute_func(out): + def item2_compute_func(self, out): relu = max( 0.0, - (solver.global_step // solver.iters_per_epoch + 1) / solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs - 0.05, ) x, y = out["x"], out["y"] @@ -190,12 +189,12 @@ def item2_compute_func(out): return item2 - self.add_equation("item2", item2_compute_func) + self.add_equation("item2", partial(item2_compute_func, self)) - def item3_compute_func(out): + def item3_compute_func(self, out): relu = max( 0.0, - (solver.global_step // solver.iters_per_epoch + 1) / solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs - 0.05, ) x, y = out["x"], out["y"] @@ -212,7 +211,7 @@ def item3_compute_func(out): return item3 - self.add_equation("item3", item3_compute_func) + self.add_equation("item3", partial(item3_compute_func, self)) dtype = paddle.get_default_dtype() From b6b9552f02bc8d20cb00932db8417015de23a326 Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Mon, 6 Nov 2023 15:26:44 +0000 Subject: [PATCH 03/15] add md --- docs/zh/examples/shock_wave.md | 121 ++++++++++++--------------------- 1 file changed, 43 insertions(+), 78 deletions(-) diff --git a/docs/zh/examples/shock_wave.md b/docs/zh/examples/shock_wave.md index e6466970c..72a3e30a7 100644 --- a/docs/zh/examples/shock_wave.md +++ b/docs/zh/examples/shock_wave.md @@ -4,27 +4,6 @@ - - -=== "模型训练命令" - - ``` sh - python poiseuille_flow.py - ``` - -=== "模型评估命令" - - ``` sh - python poiseuille_flow.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/poiseuille_flow/poiseuille_flow_pretrained.pdparams - ``` - - - - - - - - ## 1. 背景简介 激波是自然界以及工程应用中经常发现的现象。它们不仅广泛地存在于航空航天领域的可压缩流动中,而且也表现在理论与应用物理以及工程应用等其它领域。在超声速与高超声速流动中,激波的出现对流体流动的整体特征会产生重要影响。激波捕捉问题已在CFD领域发展了数十年,以弱解的数学理论为基础的激波捕捉方法以其简单易实现的特点发展迅速,并在复杂超声速、高超声速流动数值模拟中得到了广泛应用。 @@ -90,9 +69,9 @@ $$ 上式中 $g$ 即为 MLP 模型本身,用 PaddleScience 代码表示如下 -``` py linenums="253" +``` py linenums="256" --8<-- -examples/shock_wave/shock_wave.py:253:254 +examples/shock_wave/shock_wave.py:256:257 --8<-- ``` @@ -104,15 +83,15 @@ examples/shock_wave/shock_wave.py:253:254 本案例涉及二维欧拉方程和边界上的方程,如下所示 -``` py linenums="30" +``` py linenums="35" --8<-- -examples/shock_wave/shock_wave.py:30:209 +examples/shock_wave/shock_wave.py:35:214 --8<-- ``` -``` py linenums="256" +``` py linenums="259" --8<-- -examples/shock_wave/shock_wave.py:256:257 +examples/shock_wave/shock_wave.py:259:260 --8<-- ``` @@ -120,9 +99,9 @@ examples/shock_wave/shock_wave.py:256:257 本案例的计算域为 0 ~ 0.4 单位时间,长为 1.5,宽为 2.0 的长方形区域,其内含有一个圆心坐标为 [1, 1],半径为 0.25 的圆,代码如下所示 -``` py linenums="259" +``` py linenums="31" --8<-- -examples/shock_wave/shock_wave.py:259:271 +examples/shock_wave/conf/shock_wave.yaml:31:43 --8<-- ``` @@ -132,21 +111,21 @@ examples/shock_wave/shock_wave.py:259:271 我们将欧拉方程施加在计算域的内部点上,并且使用拉丁超立方(Latin HyperCube Sampling, LHS)方法采样共 `N_INTERIOR` 个训练点,代码如下所示: -``` py linenums="266" +``` py linenums="38" --8<-- -examples/shock_wave/shock_wave.py:266:266 +examples/shock_wave/conf/shock_wave.yaml:38:38 --8<-- ``` -``` py linenums="273" +``` py linenums="263" --8<-- -examples/shock_wave/shock_wave.py:273:287 +examples/shock_wave/shock_wave.py:263:277 --8<-- ``` -``` py linenums="347" +``` py linenums="337" --8<-- -examples/shock_wave/shock_wave.py:347:361 +examples/shock_wave/shock_wave.py:337:350 --8<-- ``` @@ -154,21 +133,21 @@ examples/shock_wave/shock_wave.py:347:361 我们将边界条件施加在计算域的边界点上,同样使用拉丁超立方(Latin HyperCube Sampling, LHS)方法在边界上采样共 `N_BOUNDARY` 个训练点,代码如下所示: -``` py linenums="267" +``` py linenums="39" --8<-- -examples/shock_wave/shock_wave.py:267:267 +examples/shock_wave/conf/shock_wave.yaml:39:39 --8<-- ``` -``` py linenums="289" +``` py linenums="279" --8<-- -examples/shock_wave/shock_wave.py:289:322 +examples/shock_wave/shock_wave.py:279:312 --8<-- ``` -``` py linenums="374" +``` py linenums="363" --8<-- -examples/shock_wave/shock_wave.py:374:398 +examples/shock_wave/shock_wave.py:363:387 --8<-- ``` @@ -176,23 +155,23 @@ examples/shock_wave/shock_wave.py:374:398 我们将边界条件施加在计算域的初始时刻的点上,同样使用拉丁超立方(Latin HyperCube Sampling, LHS)方法在初始时刻的计算域内采样共 `N_BOUNDARY` 个训练点,代码如下所示: -``` py linenums="324" +``` py linenums="314" --8<-- -examples/shock_wave/shock_wave.py:324:345 +examples/shock_wave/shock_wave.py:314:335 --8<-- ``` -``` py linenums="362" +``` py linenums="351" --8<-- -examples/shock_wave/shock_wave.py:362:373 +examples/shock_wave/shock_wave.py:351:362 --8<-- ``` 在以上三个约束构建完毕之后,需要将他们包装成一个字典,方便后续作为参数传递 -``` py linenums="399" +``` py linenums="388" --8<-- -examples/shock_wave/shock_wave.py:399:404 +examples/shock_wave/shock_wave.py:388:393 --8<-- ``` @@ -200,9 +179,9 @@ examples/shock_wave/shock_wave.py:399:404 接下来我们需要指定训练轮数和学习率,此处我们按实验经验,使用 100 轮训练轮数。 -``` py linenums="410" +``` py linenums="400" --8<-- -examples/shock_wave/shock_wave.py:410:410 +examples/shock_wave/shock_wave.py:400:400 --8<-- ``` @@ -210,9 +189,9 @@ examples/shock_wave/shock_wave.py:410:410 训练过程会调用优化器来更新模型参数,此处选择 `L-BFGS` 优化器并设定 `max_iter` 为 100。 -``` py linenums="406" +``` py linenums="395" --8<-- -examples/shock_wave/shock_wave.py:406:407 +examples/shock_wave/shock_wave.py:395:397 --8<-- ``` @@ -220,57 +199,43 @@ examples/shock_wave/shock_wave.py:406:407 完成上述设置之后,只需要将上述实例化的对象按顺序传递给 `ppsci.solver.Solver`。 -``` py linenums="410" +``` py linenums="401" --8<-- -examples/shock_wave/shock_wave.py:410:424 +examples/shock_wave/shock_wave.py:401:414 --8<-- ``` 本案例需要根据每一轮训练的 epoch 值,计算PDE、BC方程内的权重系数 `relu`。因此在 solver 实例化完毕之后,需额外将其传递给方程本身,代码如下: -``` py linenums="425" +``` py linenums="415" --8<-- -examples/shock_wave/shock_wave.py:425:428 +examples/shock_wave/shock_wave.py:415:418 --8<-- ``` 最后启动训练即可: -``` py linenums="430" +``` py linenums="420" --8<-- -examples/shock_wave/shock_wave.py:430:431 +examples/shock_wave/shock_wave.py:420:421 --8<-- ``` 训练完毕后,我们可视化最后一个时刻的计算域内辨率为 600x600 的激波,共 360000 个点,代码如下: -``` py linenums="433" +``` py linenums="423" --8<-- -examples/shock_wave/shock_wave.py:433:504 +examples/shock_wave/shock_wave.py:423:492 --8<-- ``` ## 4. 完整代码 -=== "Ma=2.0" - - ``` py linenums="1" title="shock_wave.py" - --8<-- - examples/shock_wave/shock_wave.py - --8<-- - ``` - -=== "Ma=0.728" - - ``` py linenums="1" title="shock_wave.py" - --8<-- - examples/shock_wave/shock_wave.py::243 - --8<-- - MA=0.728 - --8<-- - examples/shock_wave/shock_wave.py:246: - --8<-- - ``` +``` py linenums="1" title="shock_wave.py" +--8<-- +examples/shock_wave/shock_wave.py +--8<-- +``` ## 5. 结果展示 From 4722ca0da79e8d632c2ba0d54624ea196adcaaec Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Sun, 12 Nov 2023 18:36:51 +0800 Subject: [PATCH 04/15] need evaluate --- ...hock_wave.yaml => shock_wave_Ma0.728.yaml} | 23 +++--- .../shock_wave/conf/shock_wave_Ma2.0.yaml | 73 +++++++++++++++++++ examples/shock_wave/shock_wave.py | 71 ++++++++++-------- 3 files changed, 121 insertions(+), 46 deletions(-) rename examples/shock_wave/conf/{shock_wave.yaml => shock_wave_Ma0.728.yaml} (79%) create mode 100644 examples/shock_wave/conf/shock_wave_Ma2.0.yaml diff --git a/examples/shock_wave/conf/shock_wave.yaml b/examples/shock_wave/conf/shock_wave_Ma0.728.yaml similarity index 79% rename from examples/shock_wave/conf/shock_wave.yaml rename to examples/shock_wave/conf/shock_wave_Ma0.728.yaml index 3977cf6b3..1d9dbe209 100644 --- a/examples/shock_wave/conf/shock_wave.yaml +++ b/examples/shock_wave/conf/shock_wave_Ma0.728.yaml @@ -42,33 +42,28 @@ P1: 3.001 GAMMA: 1.4 V1: 0.0 - # visualize prediction Nd: 600 T: 0.4 # model settings MODEL: - model: - input_keys: ["t", "x", "y"] - output_keys: ["u", "v", "p", "rho"] - num_layers: 9 - hidden_size: 90 - activation: "tanh" - + input_keys: ["t", "x", "y"] + output_keys: ["u", "v", "p", "rho"] + num_layers: 9 + hidden_size: 90 + activation: "tanh" # training settings TRAIN: epochs: 100 iters_per_epoch: 1 save_freq: 50 - eval_during_train: true + eval_during_train: false eval_freq: 20 - lr_scheduler: - epochs: ${TRAIN.epochs} - iters_per_epoch: ${TRAIN.iters_per_epoch} - learning_rate: 1e-1 - max_iter: 100 + learning_rate: 1e-1 + max_iter: 100 + pretrained_model_path: null checkpoint_path: null diff --git a/examples/shock_wave/conf/shock_wave_Ma2.0.yaml b/examples/shock_wave/conf/shock_wave_Ma2.0.yaml new file mode 100644 index 000000000..1d9dbe209 --- /dev/null +++ b/examples/shock_wave/conf/shock_wave_Ma2.0.yaml @@ -0,0 +1,73 @@ +hydra: + run: + # dynamic output directory according to running time and override name + dir: outputs_shock_wave/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname} + job: + name: ${mode} # name of logfile + chdir: false # keep current working direcotry unchaned + config: + override_dirname: + exclude_keys: + - TRAIN.checkpoint_path + - TRAIN.pretrained_model_path + - EVAL.pretrained_model_path + - mode + - output_dir + - log_freq + sweep: + # output directory for multirun + dir: ${hydra.run.dir} + subdir: ./ + +# general settings +mode: train # running mode: train/eval +seed: 2023 +output_dir: ${hydra:run.dir} +log_freq: 20 + +# set working condition +MA: 2.0 + +# set hyper-parameters +Lt: 0.4 +Lx: 1.5 +Ly: 2.0 +rx: 1.0 +ry: 1.0 +rd: 0.25 +N_INTERIOR: 100000 +N_BOUNDARY: 10000 +RHO1: 2.112 +P1: 3.001 +GAMMA: 1.4 +V1: 0.0 + +# visualize prediction +Nd: 600 +T: 0.4 + +# model settings +MODEL: + input_keys: ["t", "x", "y"] + output_keys: ["u", "v", "p", "rho"] + num_layers: 9 + hidden_size: 90 + activation: "tanh" + +# training settings +TRAIN: + epochs: 100 + iters_per_epoch: 1 + save_freq: 50 + eval_during_train: false + eval_freq: 20 + learning_rate: 1e-1 + max_iter: 100 + + pretrained_model_path: null + checkpoint_path: null + +# evaluation settings +EVAL: + pretrained_model_path: null + eval_with_no_grad: true diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index a20828aa3..e32ba170e 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from functools import partial from os import path as osp import hydra @@ -19,19 +20,15 @@ import numpy as np import paddle from matplotlib import pyplot as plt -from functools import partial - - from omegaconf import DictConfig - import ppsci from ppsci import equation from ppsci.autodiff import jacobian -from ppsci.utils import config from ppsci.utils import logger from ppsci.utils import misc + class Euler2D(equation.PDE): def __init__(self): super().__init__() @@ -42,7 +39,8 @@ def __init__(self): def continuity_compute_func(self, out): relu = max( 0.0, - (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) + / self.solver.epochs - 0.05, ) t, x, y = out["t"], out["x"], out["y"] @@ -66,7 +64,8 @@ def continuity_compute_func(self, out): def x_momentum_compute_func(self, out): relu = max( 0.0, - (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) + / self.solver.epochs - 0.05, ) t, x, y = out["t"], out["x"], out["y"] @@ -92,7 +91,8 @@ def x_momentum_compute_func(self, out): def y_momentum_compute_func(self, out): relu = max( 0.0, - (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) + / self.solver.epochs - 0.05, ) t, x, y = out["t"], out["x"], out["y"] @@ -118,7 +118,8 @@ def y_momentum_compute_func(self, out): def energy_compute_func(self, out): relu = max( 0.0, - (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) + / self.solver.epochs - 0.05, ) t, x, y = out["t"], out["x"], out["y"] @@ -152,7 +153,8 @@ def __init__(self): def item1_compute_func(self, out): relu = max( 0.0, - (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) + / self.solver.epochs - 0.05, ) x, y = out["x"], out["y"] @@ -172,7 +174,8 @@ def item1_compute_func(self, out): def item2_compute_func(self, out): relu = max( 0.0, - (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) + / self.solver.epochs - 0.05, ) x, y = out["x"], out["y"] @@ -194,7 +197,8 @@ def item2_compute_func(self, out): def item3_compute_func(self, out): relu = max( 0.0, - (self.solver.global_step // self.solver.iters_per_epoch + 1) / self.solver.epochs + (self.solver.global_step // self.solver.iters_per_epoch + 1) + / self.solver.epochs - 0.05, ) x, y = out["x"], out["y"] @@ -242,36 +246,34 @@ def generate_bc_left_points( def train(cfg: DictConfig): - + # set random seed for reproducibility ppsci.utils.misc.set_random_seed(cfg.seed) - - # set output directory - OUTPUT_DIR = ( - f"./output_shock_wave_{cfg.MA:.3f}" if not cfg.output_dir else cfg.output_dir - ) + # initialize logger logger.init_logger("ppsci", osp.join(cfg.output_dir, "train.log"), "info") # set model - model = ppsci.arch.MLP(**cfg.MODEL.model) + model = ppsci.arch.MLP(**cfg.MODEL) # set equation equation = {"Euler2D": Euler2D(), "BC_EQ": BC_EQ()} - # Latin HyperCube Sampling # generate PDE data xlimits = np.array([[0.0, 0.0, 0.0], [cfg.Lt, cfg.Lx, cfg.Ly]]).T - name_value = cfg.MODEL.model.input_keys + name_value = cfg.MODEL.input_keys doe_lhs = lhs.LHS(cfg.N_INTERIOR, xlimits) x_int_train = doe_lhs.get_sample() x_int_train = x_int_train[ - ~((x_int_train[:, 1] - cfg.rx) ** 2 + (x_int_train[:, 2] - cfg.ry) ** 2 < cfg.rd**2) + ~( + (x_int_train[:, 1] - cfg.rx) ** 2 + (x_int_train[:, 2] - cfg.ry) ** 2 + < cfg.rd**2 + ) ] x_int_train_dict = misc.convert_to_dict(x_int_train, name_value) - y_int_train = np.zeros([len(x_int_train), len(cfg.MODEL.model.output_keys)], dtype) + y_int_train = np.zeros([len(x_int_train), len(cfg.MODEL.output_keys)], dtype) y_int_train_dict = misc.convert_to_dict( y_int_train, tuple(equation["Euler2D"].equations.keys()) ) @@ -316,7 +318,10 @@ def train(cfg: DictConfig): doe_lhs = lhs.LHS(cfg.N_BOUNDARY, xlimits) x_ic_train = doe_lhs.get_sample() x_ic_train = x_ic_train[ - ~((x_ic_train[:, 1] - cfg.rx) ** 2 + (x_ic_train[:, 2] - cfg.ry) ** 2 < cfg.rd**2) + ~( + (x_ic_train[:, 1] - cfg.rx) ** 2 + (x_ic_train[:, 2] - cfg.ry) ** 2 + < cfg.rd**2 + ) ] x_ic_train_dict = misc.convert_to_dict(x_ic_train, name_value) U1 = np.sqrt(cfg.GAMMA * cfg.P1 / cfg.RHO1) * cfg.MA @@ -393,18 +398,18 @@ def train(cfg: DictConfig): } # set optimizer - optimizer = ppsci.optimizer.LBFGS(cfg.TRAIN.lr_scheduler.learning_rate, - max_iter=cfg.TRAIN.lr_scheduler.max_iter)(model) + optimizer = ppsci.optimizer.LBFGS( + cfg.TRAIN.learning_rate, max_iter=cfg.TRAIN.max_iter + )(model) # initialize solver - EPOCHS = 100 if not cfg.TRAIN.epochs else cfg.TRAIN.epochs solver = ppsci.solver.Solver( model, constraint, - OUTPUT_DIR, + cfg.output_dir, optimizer, None, - EPOCHS, + cfg.TRAIN.epochs, cfg.TRAIN.iters_per_epoch, save_freq=cfg.TRAIN.save_freq, log_freq=cfg.log_freq, @@ -440,7 +445,9 @@ def train(cfg: DictConfig): output_dict["rho"], ) - zero_mask = ((x_test[:, 1] - cfg.rx) ** 2 + (x_test[:, 2] - cfg.ry) ** 2) < cfg.rd**2 + zero_mask = ( + (x_test[:, 1] - cfg.rx) ** 2 + (x_test[:, 2] - cfg.ry) ** 2 + ) < cfg.rd**2 u[zero_mask] = 0 v[zero_mask] = 0 p[zero_mask] = 0 @@ -489,7 +496,7 @@ def train(cfg: DictConfig): axe.set_aspect(1) plt.colorbar() - plt.savefig(osp.join(OUTPUT_DIR, f"shock_wave(Ma_{cfg.MA:.3f}).png")) + plt.savefig(osp.join(cfg.output_dir, f"shock_wave(Ma_{cfg.MA:.3f}).png")) @hydra.main(version_base=None, config_path="./conf", config_name="shock_wave.yaml") @@ -501,4 +508,4 @@ def main(cfg: DictConfig): if __name__ == "__main__": - main() \ No newline at end of file + main() From 6df5844ea2232fb4e49ceea0f8d5f916b640e2e6 Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Sun, 12 Nov 2023 18:53:21 +0800 Subject: [PATCH 05/15] update evaluate --- .../shock_wave/conf/shock_wave_Ma0.728.yaml | 2 +- examples/shock_wave/shock_wave.py | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/examples/shock_wave/conf/shock_wave_Ma0.728.yaml b/examples/shock_wave/conf/shock_wave_Ma0.728.yaml index 1d9dbe209..b76f7b7ae 100644 --- a/examples/shock_wave/conf/shock_wave_Ma0.728.yaml +++ b/examples/shock_wave/conf/shock_wave_Ma0.728.yaml @@ -26,7 +26,7 @@ output_dir: ${hydra:run.dir} log_freq: 20 # set working condition -MA: 2.0 +MA: 0.728 # set hyper-parameters Lt: 0.4 diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index e32ba170e..c7b93c956 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -425,6 +425,37 @@ def train(cfg: DictConfig): # train model solver.train() + +def evaluate(cfg: DictConfig): + + # set random seed for reproducibility + ppsci.utils.misc.set_random_seed(cfg.seed) + + # initialize logger + logger.init_logger("ppsci", osp.join(cfg.output_dir, "eval.log"), "info") + + # set model + model = ppsci.arch.MLP(**cfg.MODEL) + + # set equation + equation = {"Euler2D": Euler2D(), "BC_EQ": BC_EQ()} + + # initialize solver + solver = ppsci.solver.Solver( + model, + output_dir=cfg.output_dir, + seed=cfg.seed, + equation=equation, + eval_with_no_grad=True, + pretrained_model_path=cfg.EVAL.pretrained_model_path, + ) + # HACK: Given entire solver to euaqtion object for tracking run-time epoch + # to compute factor `relu` dynamically. + equation["Euler2D"].solver = solver + equation["BC_EQ"].solver = solver + + solver.eval() + # visualize prediction t = np.linspace(cfg.T, cfg.T, 1) x = np.linspace(0.0, cfg.Lx, cfg.Nd) @@ -432,6 +463,7 @@ def train(cfg: DictConfig): _, x_grid, y_grid = np.meshgrid(t, x, y) x_test = misc.cartesian_product(t, x, y) + name_value = cfg.MODEL.input_keys x_test_dict = misc.convert_to_dict( x_test, name_value, @@ -503,8 +535,10 @@ def train(cfg: DictConfig): def main(cfg: DictConfig): if cfg.mode == "train": train(cfg) + elif cfg.mode == "eval": + evaluate(cfg) else: - raise ValueError(f"cfg.mode should in ['train'], but got '{cfg.mode}'") + raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") if __name__ == "__main__": From 8be30862953ef6eb07cde6ece4f6bb3211e796f0 Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Tue, 14 Nov 2023 19:15:42 +0800 Subject: [PATCH 06/15] fix code style --- .../shock_wave/conf/shock_wave_Ma0.728.yaml | 1 - .../shock_wave/conf/shock_wave_Ma2.0.yaml | 1 - examples/shock_wave/shock_wave.py | 50 +++++++------------ 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/examples/shock_wave/conf/shock_wave_Ma0.728.yaml b/examples/shock_wave/conf/shock_wave_Ma0.728.yaml index b76f7b7ae..446d81064 100644 --- a/examples/shock_wave/conf/shock_wave_Ma0.728.yaml +++ b/examples/shock_wave/conf/shock_wave_Ma0.728.yaml @@ -63,7 +63,6 @@ TRAIN: eval_freq: 20 learning_rate: 1e-1 max_iter: 100 - pretrained_model_path: null checkpoint_path: null diff --git a/examples/shock_wave/conf/shock_wave_Ma2.0.yaml b/examples/shock_wave/conf/shock_wave_Ma2.0.yaml index 1d9dbe209..42ea2da76 100644 --- a/examples/shock_wave/conf/shock_wave_Ma2.0.yaml +++ b/examples/shock_wave/conf/shock_wave_Ma2.0.yaml @@ -63,7 +63,6 @@ TRAIN: eval_freq: 20 learning_rate: 1e-1 max_iter: 100 - pretrained_model_path: null checkpoint_path: null diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index c7b93c956..3dbb63f5b 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from functools import partial from os import path as osp import hydra @@ -36,7 +35,7 @@ def __init__(self): # compute loss factor `relu` dynamically. self.solver: ppsci.solver.Solver = None - def continuity_compute_func(self, out): + def continuity_compute_func(out): relu = max( 0.0, (self.solver.global_step // self.solver.iters_per_epoch + 1) @@ -59,9 +58,9 @@ def continuity_compute_func(self, out): continuity = (rho__t + rho_u__x + rho_v__y) / lam return continuity - self.add_equation("continuity", partial(continuity_compute_func, self)) + self.add_equation("continuity", continuity_compute_func) - def x_momentum_compute_func(self, out): + def x_momentum_compute_func(out): relu = max( 0.0, (self.solver.global_step // self.solver.iters_per_epoch + 1) @@ -86,9 +85,9 @@ def x_momentum_compute_func(self, out): x_momentum = (rho_u__t + u1__x + u2__y) / lam return x_momentum - self.add_equation("x_momentum", partial(x_momentum_compute_func, self)) + self.add_equation("x_momentum", x_momentum_compute_func) - def y_momentum_compute_func(self, out): + def y_momentum_compute_func(out): relu = max( 0.0, (self.solver.global_step // self.solver.iters_per_epoch + 1) @@ -113,9 +112,9 @@ def y_momentum_compute_func(self, out): y_momentum = (rho_v__t + u2__x + u3__y) / lam return y_momentum - self.add_equation("y_momentum", partial(y_momentum_compute_func, self)) + self.add_equation("y_momentum", y_momentum_compute_func) - def energy_compute_func(self, out): + def energy_compute_func(out): relu = max( 0.0, (self.solver.global_step // self.solver.iters_per_epoch + 1) @@ -140,7 +139,7 @@ def energy_compute_func(self, out): energy = (e__t + e1__x + e2__y) / lam return energy - self.add_equation("energy", partial(energy_compute_func, self)) + self.add_equation("energy", energy_compute_func) class BC_EQ(equation.PDE): @@ -150,7 +149,7 @@ def __init__(self): # compute loss factor `relu` dynamically. self.solver: ppsci.solver.Solver = None - def item1_compute_func(self, out): + def item1_compute_func(out): relu = max( 0.0, (self.solver.global_step // self.solver.iters_per_epoch + 1) @@ -169,9 +168,9 @@ def item1_compute_func(self, out): return item1 - self.add_equation("item1", partial(item1_compute_func, self)) + self.add_equation("item1", item1_compute_func) - def item2_compute_func(self, out): + def item2_compute_func(out): relu = max( 0.0, (self.solver.global_step // self.solver.iters_per_epoch + 1) @@ -192,9 +191,9 @@ def item2_compute_func(self, out): return item2 - self.add_equation("item2", partial(item2_compute_func, self)) + self.add_equation("item2", item2_compute_func) - def item3_compute_func(self, out): + def item3_compute_func(out): relu = max( 0.0, (self.solver.global_step // self.solver.iters_per_epoch + 1) @@ -215,7 +214,7 @@ def item3_compute_func(self, out): return item3 - self.add_equation("item3", partial(item3_compute_func, self)) + self.add_equation("item3", item3_compute_func) dtype = paddle.get_default_dtype() @@ -262,7 +261,6 @@ def train(cfg: DictConfig): # Latin HyperCube Sampling # generate PDE data xlimits = np.array([[0.0, 0.0, 0.0], [cfg.Lt, cfg.Lx, cfg.Ly]]).T - name_value = cfg.MODEL.input_keys doe_lhs = lhs.LHS(cfg.N_INTERIOR, xlimits) x_int_train = doe_lhs.get_sample() x_int_train = x_int_train[ @@ -271,7 +269,7 @@ def train(cfg: DictConfig): < cfg.rd**2 ) ] - x_int_train_dict = misc.convert_to_dict(x_int_train, name_value) + x_int_train_dict = misc.convert_to_dict(x_int_train, cfg.MODEL.input_keys) y_int_train = np.zeros([len(x_int_train), len(cfg.MODEL.output_keys)], dtype) y_int_train_dict = misc.convert_to_dict( @@ -282,7 +280,7 @@ def train(cfg: DictConfig): xlimits = np.array([[0.0, 0.0, 0.0], [cfg.Lt, 0.0, cfg.Ly]]).T doe_lhs = lhs.LHS(cfg.N_BOUNDARY, xlimits) x_bcL_train = doe_lhs.get_sample() - x_bcL_train_dict = misc.convert_to_dict(x_bcL_train, name_value) + x_bcL_train_dict = misc.convert_to_dict(x_bcL_train, cfg.MODEL.input_keys) u_bcL_train, v_bcL_train, p_bcL_train, rho_bcL_train = generate_bc_left_points( x_bcL_train, cfg.MA, cfg.RHO1, cfg.P1, cfg.V1, cfg.GAMMA @@ -306,7 +304,7 @@ def train(cfg: DictConfig): ) x_bcI_train_dict = misc.convert_to_dict( np.concatenate([x_bcI_train, sin_bcI_train, cos_bcI_train], axis=1), - name_value + ("sin", "cos"), + cfg.MODEL.input_keys + ("sin", "cos"), ) y_bcI_train_dict = misc.convert_to_dict( np.zeros((len(x_bcI_train), 3), dtype), @@ -323,7 +321,7 @@ def train(cfg: DictConfig): < cfg.rd**2 ) ] - x_ic_train_dict = misc.convert_to_dict(x_ic_train, name_value) + x_ic_train_dict = misc.convert_to_dict(x_ic_train, cfg.MODEL.input_keys) U1 = np.sqrt(cfg.GAMMA * cfg.P1 / cfg.RHO1) * cfg.MA y_ic_train = np.concatenate( [ @@ -427,7 +425,6 @@ def train(cfg: DictConfig): def evaluate(cfg: DictConfig): - # set random seed for reproducibility ppsci.utils.misc.set_random_seed(cfg.seed) @@ -437,22 +434,14 @@ def evaluate(cfg: DictConfig): # set model model = ppsci.arch.MLP(**cfg.MODEL) - # set equation - equation = {"Euler2D": Euler2D(), "BC_EQ": BC_EQ()} - # initialize solver solver = ppsci.solver.Solver( model, output_dir=cfg.output_dir, seed=cfg.seed, - equation=equation, eval_with_no_grad=True, pretrained_model_path=cfg.EVAL.pretrained_model_path, ) - # HACK: Given entire solver to euaqtion object for tracking run-time epoch - # to compute factor `relu` dynamically. - equation["Euler2D"].solver = solver - equation["BC_EQ"].solver = solver solver.eval() @@ -463,10 +452,9 @@ def evaluate(cfg: DictConfig): _, x_grid, y_grid = np.meshgrid(t, x, y) x_test = misc.cartesian_product(t, x, y) - name_value = cfg.MODEL.input_keys x_test_dict = misc.convert_to_dict( x_test, - name_value, + cfg.MODEL.input_keys, ) output_dict = solver.predict(x_test_dict, return_numpy=True) From 7dfd205e091ed415c1cb599220bfcc8b42e21103 Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Tue, 14 Nov 2023 20:46:12 +0800 Subject: [PATCH 07/15] change seed && add some config --- examples/shock_wave/conf/shock_wave_Ma0.728.yaml | 2 +- examples/shock_wave/conf/shock_wave_Ma2.0.yaml | 2 +- examples/shock_wave/shock_wave.py | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/shock_wave/conf/shock_wave_Ma0.728.yaml b/examples/shock_wave/conf/shock_wave_Ma0.728.yaml index 446d81064..805f7840d 100644 --- a/examples/shock_wave/conf/shock_wave_Ma0.728.yaml +++ b/examples/shock_wave/conf/shock_wave_Ma0.728.yaml @@ -21,7 +21,7 @@ hydra: # general settings mode: train # running mode: train/eval -seed: 2023 +seed: 42 output_dir: ${hydra:run.dir} log_freq: 20 diff --git a/examples/shock_wave/conf/shock_wave_Ma2.0.yaml b/examples/shock_wave/conf/shock_wave_Ma2.0.yaml index 42ea2da76..75d2b7283 100644 --- a/examples/shock_wave/conf/shock_wave_Ma2.0.yaml +++ b/examples/shock_wave/conf/shock_wave_Ma2.0.yaml @@ -21,7 +21,7 @@ hydra: # general settings mode: train # running mode: train/eval -seed: 2023 +seed: 42 output_dir: ${hydra:run.dir} log_freq: 20 diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index 3dbb63f5b..4228b9e32 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -304,7 +304,7 @@ def train(cfg: DictConfig): ) x_bcI_train_dict = misc.convert_to_dict( np.concatenate([x_bcI_train, sin_bcI_train, cos_bcI_train], axis=1), - cfg.MODEL.input_keys + ("sin", "cos"), + cfg.MODEL.input_keys + ["sin", "cos"], ) y_bcI_train_dict = misc.convert_to_dict( np.zeros((len(x_bcI_train), 3), dtype), @@ -413,7 +413,9 @@ def train(cfg: DictConfig): log_freq=cfg.log_freq, seed=cfg.seed, equation=equation, - eval_with_no_grad=True, + pretrained_model_path=cfg.TRAIN.pretrained_model_path, + checkpoint_path=cfg.TRAIN.checkpoint_path, + eval_with_no_grad=cfg.EVAL.eval_with_no_grad, ) # HACK: Given entire solver to euaqtion object for tracking run-time epoch # to compute factor `relu` dynamically. From d4a19d7717c24927e91199f77f7adce1c84c109e Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Tue, 14 Nov 2023 20:48:15 +0800 Subject: [PATCH 08/15] True => cfg.EVAL.eval_with_no_grad --- examples/shock_wave/shock_wave.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index 4228b9e32..228ad9c70 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -441,7 +441,7 @@ def evaluate(cfg: DictConfig): model, output_dir=cfg.output_dir, seed=cfg.seed, - eval_with_no_grad=True, + eval_with_no_grad=cfg.EVAL.eval_with_no_grad, pretrained_model_path=cfg.EVAL.pretrained_model_path, ) From be1be4b310c9379be80aada402b1f44450998d83 Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Wed, 15 Nov 2023 10:04:05 +0800 Subject: [PATCH 09/15] update md && rm .eval --- docs/zh/examples/shock_wave.md | 27 +++++++++++++++++++++++++++ examples/shock_wave/shock_wave.py | 2 -- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/zh/examples/shock_wave.md b/docs/zh/examples/shock_wave.md index 72a3e30a7..e51080b7a 100644 --- a/docs/zh/examples/shock_wave.md +++ b/docs/zh/examples/shock_wave.md @@ -4,6 +4,33 @@ +=== "模型训练命令" + + ``` sh + # linux + wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams + wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams + # windows + # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams + # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams + + python bracket.py + ``` + +=== "模型评估命令" + + ``` sh + # linux + wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams + wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams + # windows + # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams + # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams + + python bracket.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams + ``` + + ## 1. 背景简介 激波是自然界以及工程应用中经常发现的现象。它们不仅广泛地存在于航空航天领域的可压缩流动中,而且也表现在理论与应用物理以及工程应用等其它领域。在超声速与高超声速流动中,激波的出现对流体流动的整体特征会产生重要影响。激波捕捉问题已在CFD领域发展了数十年,以弱解的数学理论为基础的激波捕捉方法以其简单易实现的特点发展迅速,并在复杂超声速、高超声速流动数值模拟中得到了广泛应用。 diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index 228ad9c70..72ad5b973 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -445,8 +445,6 @@ def evaluate(cfg: DictConfig): pretrained_model_path=cfg.EVAL.pretrained_model_path, ) - solver.eval() - # visualize prediction t = np.linspace(cfg.T, cfg.T, 1) x = np.linspace(0.0, cfg.Lx, cfg.Nd) From 9fed90dc89964e27ec080a2e5c1cef849b6afc28 Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Wed, 15 Nov 2023 10:21:37 +0800 Subject: [PATCH 10/15] change line num --- docs/zh/examples/shock_wave.md | 64 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/docs/zh/examples/shock_wave.md b/docs/zh/examples/shock_wave.md index e51080b7a..5f4b8fbb3 100644 --- a/docs/zh/examples/shock_wave.md +++ b/docs/zh/examples/shock_wave.md @@ -96,9 +96,9 @@ $$ 上式中 $g$ 即为 MLP 模型本身,用 PaddleScience 代码表示如下 -``` py linenums="256" +``` py linenums="255" --8<-- -examples/shock_wave/shock_wave.py:256:257 +examples/shock_wave/shock_wave.py:255:256 --8<-- ``` @@ -110,15 +110,15 @@ examples/shock_wave/shock_wave.py:256:257 本案例涉及二维欧拉方程和边界上的方程,如下所示 -``` py linenums="35" +``` py linenums="31" --8<-- -examples/shock_wave/shock_wave.py:35:214 +examples/shock_wave/shock_wave.py:31:217 --8<-- ``` -``` py linenums="259" +``` py linenums="258" --8<-- -examples/shock_wave/shock_wave.py:259:260 +examples/shock_wave/shock_wave.py:258:259 --8<-- ``` @@ -128,7 +128,7 @@ examples/shock_wave/shock_wave.py:259:260 ``` py linenums="31" --8<-- -examples/shock_wave/conf/shock_wave.yaml:31:43 +examples/shock_wave/conf/shock_wave_Ma2.0.yaml:31:43 --8<-- ``` @@ -140,19 +140,19 @@ examples/shock_wave/conf/shock_wave.yaml:31:43 ``` py linenums="38" --8<-- -examples/shock_wave/conf/shock_wave.yaml:38:38 +examples/shock_wave/conf/shock_wave_Ma2.0.yaml:38:38 --8<-- ``` -``` py linenums="263" +``` py linenums="261" --8<-- -examples/shock_wave/shock_wave.py:263:277 +examples/shock_wave/shock_wave.py:261:277 --8<-- ``` -``` py linenums="337" +``` py linenums="340" --8<-- -examples/shock_wave/shock_wave.py:337:350 +examples/shock_wave/shock_wave.py:340:353 --8<-- ``` @@ -162,7 +162,7 @@ examples/shock_wave/shock_wave.py:337:350 ``` py linenums="39" --8<-- -examples/shock_wave/conf/shock_wave.yaml:39:39 +examples/shock_wave/conf/shock_wave_Ma2.0.yaml:39:39 --8<-- ``` @@ -172,9 +172,9 @@ examples/shock_wave/shock_wave.py:279:312 --8<-- ``` -``` py linenums="363" +``` py linenums="366" --8<-- -examples/shock_wave/shock_wave.py:363:387 +examples/shock_wave/shock_wave.py:366:390 --8<-- ``` @@ -184,21 +184,21 @@ examples/shock_wave/shock_wave.py:363:387 ``` py linenums="314" --8<-- -examples/shock_wave/shock_wave.py:314:335 +examples/shock_wave/shock_wave.py:314:338 --8<-- ``` -``` py linenums="351" +``` py linenums="354" --8<-- -examples/shock_wave/shock_wave.py:351:362 +examples/shock_wave/shock_wave.py:354:365 --8<-- ``` 在以上三个约束构建完毕之后,需要将他们包装成一个字典,方便后续作为参数传递 -``` py linenums="388" +``` py linenums="391" --8<-- -examples/shock_wave/shock_wave.py:388:393 +examples/shock_wave/shock_wave.py:391:396 --8<-- ``` @@ -206,9 +206,9 @@ examples/shock_wave/shock_wave.py:388:393 接下来我们需要指定训练轮数和学习率,此处我们按实验经验,使用 100 轮训练轮数。 -``` py linenums="400" +``` py linenums="59" --8<-- -examples/shock_wave/shock_wave.py:400:400 +examples/shock_wave/conf/shock_wave_Ma2.0.yaml:59:59 --8<-- ``` @@ -216,9 +216,9 @@ examples/shock_wave/shock_wave.py:400:400 训练过程会调用优化器来更新模型参数,此处选择 `L-BFGS` 优化器并设定 `max_iter` 为 100。 -``` py linenums="395" +``` py linenums="398" --8<-- -examples/shock_wave/shock_wave.py:395:397 +examples/shock_wave/shock_wave.py:398:401 --8<-- ``` @@ -226,33 +226,33 @@ examples/shock_wave/shock_wave.py:395:397 完成上述设置之后,只需要将上述实例化的对象按顺序传递给 `ppsci.solver.Solver`。 -``` py linenums="401" +``` py linenums="403" --8<-- -examples/shock_wave/shock_wave.py:401:414 +examples/shock_wave/shock_wave.py:403:419 --8<-- ``` 本案例需要根据每一轮训练的 epoch 值,计算PDE、BC方程内的权重系数 `relu`。因此在 solver 实例化完毕之后,需额外将其传递给方程本身,代码如下: -``` py linenums="415" +``` py linenums="420" --8<-- -examples/shock_wave/shock_wave.py:415:418 +examples/shock_wave/shock_wave.py:420:423 --8<-- ``` 最后启动训练即可: -``` py linenums="420" +``` py linenums="425" --8<-- -examples/shock_wave/shock_wave.py:420:421 +examples/shock_wave/shock_wave.py:425:426 --8<-- ``` 训练完毕后,我们可视化最后一个时刻的计算域内辨率为 600x600 的激波,共 360000 个点,代码如下: -``` py linenums="423" +``` py linenums="448" --8<-- -examples/shock_wave/shock_wave.py:423:492 +examples/shock_wave/shock_wave.py:448:519 --8<-- ``` From ceed0706314fd34557355a375c05ba6fac75db13 Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Wed, 15 Nov 2023 10:23:12 +0800 Subject: [PATCH 11/15] update yml name --- examples/shock_wave/shock_wave.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/shock_wave/shock_wave.py b/examples/shock_wave/shock_wave.py index 72ad5b973..ff55693df 100644 --- a/examples/shock_wave/shock_wave.py +++ b/examples/shock_wave/shock_wave.py @@ -519,7 +519,9 @@ def evaluate(cfg: DictConfig): plt.savefig(osp.join(cfg.output_dir, f"shock_wave(Ma_{cfg.MA:.3f}).png")) -@hydra.main(version_base=None, config_path="./conf", config_name="shock_wave.yaml") +@hydra.main( + version_base=None, config_path="./conf", config_name="shock_wave_Ma2.0.yaml" +) def main(cfg: DictConfig): if cfg.mode == "train": train(cfg) From fbc4ba7ec978f4ecd59b1ef0734938902e3df3ac Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Wed, 15 Nov 2023 10:32:09 +0800 Subject: [PATCH 12/15] add another config file --- docs/zh/examples/shock_wave.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/zh/examples/shock_wave.md b/docs/zh/examples/shock_wave.md index 5f4b8fbb3..677d6b15c 100644 --- a/docs/zh/examples/shock_wave.md +++ b/docs/zh/examples/shock_wave.md @@ -14,7 +14,9 @@ # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams - python bracket.py + python shock_wave.py + # another configuration file + # python shock_wave.py -cn=shock_wave_Ma0.728 ``` === "模型评估命令" @@ -27,7 +29,9 @@ # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams - python bracket.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams + python shock_wave.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams + # another configuration file + # python shock_wave.py -cn=shock_wave_Ma0.728 mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams ``` From 106d06e5911b68af34c72134a51ce91362cc4b1f Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Wed, 15 Nov 2023 10:54:04 +0800 Subject: [PATCH 13/15] change format --- docs/zh/examples/shock_wave.md | 64 +++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/docs/zh/examples/shock_wave.md b/docs/zh/examples/shock_wave.md index 677d6b15c..e74abb0d4 100644 --- a/docs/zh/examples/shock_wave.md +++ b/docs/zh/examples/shock_wave.md @@ -6,33 +6,49 @@ === "模型训练命令" - ``` sh - # linux - wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams - wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams - # windows - # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams - # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams - - python shock_wave.py - # another configuration file - # python shock_wave.py -cn=shock_wave_Ma0.728 - ``` + === "Ma=2" + + ``` sh + # linux + wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams + # windows + # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams + + python shock_wave.py + ``` + === "Ma=0.728" + + ``` sh + # linux + wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams + # windows + # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams + + python shock_wave.py -cn=shock_wave_Ma0.728 + ``` === "模型评估命令" - ``` sh - # linux - wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams - wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams - # windows - # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams - # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams - - python shock_wave.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams - # another configuration file - # python shock_wave.py -cn=shock_wave_Ma0.728 mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams - ``` + === "Ma=2" + + ``` sh + python shock_wave.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams + + + ``` + === "Ma=0.728" + + ``` sh + python shock_wave.py -cn=shock_wave_Ma0.728 mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams + ``` + + + + + + + + ## 1. 背景简介 From 67490211cf4ac2a50cd68654e0f055e574c80ddd Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Wed, 15 Nov 2023 10:58:53 +0800 Subject: [PATCH 14/15] rm eval download code --- docs/zh/examples/shock_wave.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/docs/zh/examples/shock_wave.md b/docs/zh/examples/shock_wave.md index e74abb0d4..b28181463 100644 --- a/docs/zh/examples/shock_wave.md +++ b/docs/zh/examples/shock_wave.md @@ -3,7 +3,6 @@ AI Studio快速体验 - === "模型训练命令" === "Ma=2" @@ -13,7 +12,6 @@ wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams # windows # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams - python shock_wave.py ``` === "Ma=0.728" @@ -23,7 +21,6 @@ wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams # windows # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams - python shock_wave.py -cn=shock_wave_Ma0.728 ``` @@ -33,8 +30,6 @@ ``` sh python shock_wave.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams - - ``` === "Ma=0.728" @@ -42,15 +37,6 @@ python shock_wave.py -cn=shock_wave_Ma0.728 mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams ``` - - - - - - - - - ## 1. 背景简介 激波是自然界以及工程应用中经常发现的现象。它们不仅广泛地存在于航空航天领域的可压缩流动中,而且也表现在理论与应用物理以及工程应用等其它领域。在超声速与高超声速流动中,激波的出现对流体流动的整体特征会产生重要影响。激波捕捉问题已在CFD领域发展了数十年,以弱解的数学理论为基础的激波捕捉方法以其简单易实现的特点发展迅速,并在复杂超声速、高超声速流动数值模拟中得到了广泛应用。 From a1c1813c29ea8f90997c4aeac43bfd69a79499ed Mon Sep 17 00:00:00 2001 From: drryanhuang Date: Wed, 15 Nov 2023 14:33:58 +0800 Subject: [PATCH 15/15] fix doc --- docs/zh/examples/shock_wave.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/docs/zh/examples/shock_wave.md b/docs/zh/examples/shock_wave.md index b28181463..b12f71350 100644 --- a/docs/zh/examples/shock_wave.md +++ b/docs/zh/examples/shock_wave.md @@ -5,28 +5,22 @@ === "模型训练命令" - === "Ma=2" + === "Ma=2.0" ``` sh # linux - wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams - # windows - # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams --output shock_wave_Ma2_pretrained.pdparams python shock_wave.py ``` === "Ma=0.728" ``` sh # linux - wget https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams - # windows - # curl https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma0728_pretrained.pdparams --output shock_wave_Ma0728_pretrained.pdparams python shock_wave.py -cn=shock_wave_Ma0.728 ``` -=== "模型评估命令" +=== "模型预测命令" - === "Ma=2" + === "Ma=2.0" ``` sh python shock_wave.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/shockwave/shock_wave_Ma2_pretrained.pdparams