From 573fd228e7f9f36850ad5efb2af520e9d228d065 Mon Sep 17 00:00:00 2001 From: wufei Date: Mon, 8 Apr 2024 14:22:56 +0800 Subject: [PATCH 1/9] fix doc bugs --- ppsci/geometry/pointcloud.py | 131 +++++++++++++++++++++++++++++++++-- 1 file changed, 125 insertions(+), 6 deletions(-) diff --git a/ppsci/geometry/pointcloud.py b/ppsci/geometry/pointcloud.py index cad7667a6..117789af1 100644 --- a/ppsci/geometry/pointcloud.py +++ b/ppsci/geometry/pointcloud.py @@ -102,14 +102,78 @@ def on_boundary(self, x): .any(axis=1) ) - def translate(self, translation): + def translate(self, translation: np.ndarray) -> "PointCloud": + """ + Translate the geometry by the given offset. + + Args: + translation (np.ndarray): Translation offset.The shape of translation must be the same as the shape of the interior points. + + Returns: + PointCloud: Translated point cloud. + + Examples: + >>> import ppsci + >>> import numpy as np + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",)) + >>> translation = np.array([1.0]) + >>> print(geom.translate(translation).interior) + [[1. ] + [1.5] + [2. ] + [2.5] + [3. ]] + >>> interior_points_2d = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1)), + ... "y": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom_2d = ppsci.geometry.PointCloud(interior_points_2d, ("x", "y")) + >>> translation_2d = np.array([1.0, 3.0]) + >>> print(geom_2d.translate(translation_2d).interior) + [[1. 3. ] + [1.5 3.5] + [2. 4. ] + [2.5 4.5] + [3. 5. ]] + """ for i, offset in enumerate(translation): self.interior[:, i] += offset if self.boundary: self.boundary += offset return self - def scale(self, scale): + def scale(self, scale: np.ndarray) -> "PointCloud": + """ + Scale the geometry by the given factor. + + Args: + scale (np.ndarray): Scale factor.The shape of scale must be the same as the shape of the interior points. + + Returns: + PointCloud: Scaled point cloud. + + Examples: + >>> import ppsci + >>> import numpy as np + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",)) + >>> scale = np.array([2.0]) + >>> print(geom.scale(scale).interior) + [[0.] + [1.] + [2.] + [3.] + [4.]] + >>> interior_points_2d = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1)), + ... "y": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom_2d = ppsci.geometry.PointCloud(interior_points_2d, ("x", "y")) + >>> scale_2d = np.array([2.0, 0.5]) + >>> print(geom_2d.scale(scale_2d).interior) + [[0. 0. ] + [1. 0.25] + [2. 0.5 ] + [3. 0.75] + [4. 1. ]] + """ for i, _scale in enumerate(scale): self.interior[:, i] *= _scale if self.boundary: @@ -124,7 +188,26 @@ def uniform_boundary_points(self, n: int): "PointCloud do not have 'uniform_boundary_points' method" ) - def random_boundary_points(self, n, random="pseudo"): + def random_boundary_points(self, n: int, random: str = "pseudo") -> np.ndarray: + """Randomly sample points on the boundary. + + Args: + n (int): Number of sample points. + random (str): Random method. Defaults to "pseudo". + + Returns: + np.ndarray: Randomly sampled points on the boundary.The shape of the returned array is (n, ndim). + + Examples: + >>> import ppsci + >>> import numpy as np + >>> np.random.seed(0) + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> boundary_points = {"x": np.array([0.0, 2.0], dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",), boundary_points) + >>> print(geom.random_boundary_points(1)) + [[2.]] + """ assert self.boundary is not None, ( "boundary points can't be empty when call " "'random_boundary_points' method" @@ -137,7 +220,26 @@ def random_boundary_points(self, n, random="pseudo"): np.random.choice(len(self.boundary), size=n, replace=False) ] - def random_points(self, n, random="pseudo"): + def random_points(self, n: int, random: str = "pseudo") -> np.ndarray: + """Randomly sample points in the geometry. + + Args: + n (int): Number of sample points. + random (str): Random method. Defaults to "pseudo". + + Returns: + np.ndarray: Randomly sampled points in the geometry.The shape of the returned array is (n, ndim). + + Examples: + >>> import ppsci + >>> import numpy as np + >>> np.random.seed(0) + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",)) + >>> print(geom.random_points(2)) + [[1.] + [0.]] + """ assert n <= len(self.interior), ( f"number of sample points({n}) " f"can't be more than that in points({len(self.interior)})" @@ -146,8 +248,25 @@ def random_points(self, n, random="pseudo"): np.random.choice(len(self.interior), size=n, replace=False) ] - def uniform_points(self, n: int, boundary=True): - """Compute the equi-spaced points in the geometry.""" + def uniform_points(self, n: int, boundary: bool = True) -> np.ndarray: + """Compute the equi-spaced points in the geometry. + + Args: + n (int): Number of sample points. + boundary (bool): Whether to include boundary points. Defaults to True. + + Returns: + np.ndarray: Equi-spaced points in the geometry.The shape of the returned array is (n, ndim). + + Examples: + >>> import ppsci + >>> import numpy as np + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",)) + >>> print(geom.uniform_points(2)) + [[0. ] + [0.5]] + """ return self.interior[:n] def union(self, other): From dfa2162632b9d88ec7296a81bf3c247d2a86b87a Mon Sep 17 00:00:00 2001 From: wufei Date: Tue, 9 Apr 2024 11:10:05 +0800 Subject: [PATCH 2/9] fix codestyle bugs --- ppsci/geometry/pointcloud.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ppsci/geometry/pointcloud.py b/ppsci/geometry/pointcloud.py index 117789af1..a5eeb10c7 100644 --- a/ppsci/geometry/pointcloud.py +++ b/ppsci/geometry/pointcloud.py @@ -222,14 +222,14 @@ def random_boundary_points(self, n: int, random: str = "pseudo") -> np.ndarray: def random_points(self, n: int, random: str = "pseudo") -> np.ndarray: """Randomly sample points in the geometry. - + Args: n (int): Number of sample points. random (str): Random method. Defaults to "pseudo". Returns: np.ndarray: Randomly sampled points in the geometry.The shape of the returned array is (n, ndim). - + Examples: >>> import ppsci >>> import numpy as np @@ -250,7 +250,7 @@ def random_points(self, n: int, random: str = "pseudo") -> np.ndarray: def uniform_points(self, n: int, boundary: bool = True) -> np.ndarray: """Compute the equi-spaced points in the geometry. - + Args: n (int): Number of sample points. boundary (bool): Whether to include boundary points. Defaults to True. From eb99d69e5b1a38839ed66caf7c9142605764c0bb Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:11:22 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E3=80=90PPSCI=20Export&Infer=20No.15-16?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/examples/ldc2d_steady.md | 12 +++ docs/zh/examples/ldc2d_unsteady.md | 12 +++ examples/ldc/conf/ldc2d_steady_Re10.yaml | 19 ++++ examples/ldc/conf/ldc2d_unsteady_Re10.yaml | 19 ++++ examples/ldc/ldc2d_steady_Re10.py | 60 ++++++++++++- examples/ldc/ldc2d_unsteady_Re10.py | 100 ++++++++++++++++++++- 6 files changed, 220 insertions(+), 2 deletions(-) diff --git a/docs/zh/examples/ldc2d_steady.md b/docs/zh/examples/ldc2d_steady.md index 037dc50bc..8a52e02a3 100644 --- a/docs/zh/examples/ldc2d_steady.md +++ b/docs/zh/examples/ldc2d_steady.md @@ -14,6 +14,18 @@ python ldc2d_steady_Re10.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_steady_Re10/ldc2d_steady_Re10_pretrained.pdparams ``` +=== "模型导出命令" + + ``` sh + python ldc2d_steady_Re10.py mode=export + ``` + +=== "模型推理命令" + + ``` sh + python ldc2d_steady_Re10.py mode=infer + ``` + | 预训练模型 | 指标 | |:--| :--| | [ldc2d_steady_Re10_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_steady_Re10/ldc2d_steady_Re10_pretrained.pdparams) | loss(Residual): 365.36164
MSE.momentum_x(Residual): 0.01435
MSE.continuity(Residual): 0.04072
MSE.momentum_y(Residual): 0.02471 | diff --git a/docs/zh/examples/ldc2d_unsteady.md b/docs/zh/examples/ldc2d_unsteady.md index 869836229..fe6a15726 100644 --- a/docs/zh/examples/ldc2d_unsteady.md +++ b/docs/zh/examples/ldc2d_unsteady.md @@ -14,6 +14,18 @@ python ldc2d_unsteady_Re10.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_unsteady_Re10/ldc2d_unsteady_Re10_pretrained.pdparams ``` +=== "模型导出命令" + + ``` sh + python ldc2d_unsteady_Re10.py mode=export + ``` + +=== "模型推理命令" + + ``` sh + python ldc2d_unsteady_Re10.py mode=infer + ``` + | 预训练模型 | 指标 | |:--| :--| | [ldc2d_unsteady_Re10_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_unsteady_Re10/ldc2d_unsteady_Re10_pretrained.pdparams) | loss(Residual): 155652.67530
MSE.momentum_x(Residual): 6.78030
MSE.continuity(Residual): 0.16590
MSE.momentum_y(Residual): 12.05981 | diff --git a/examples/ldc/conf/ldc2d_steady_Re10.yaml b/examples/ldc/conf/ldc2d_steady_Re10.yaml index 079d1e442..330089927 100644 --- a/examples/ldc/conf/ldc2d_steady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_steady_Re10.yaml @@ -22,6 +22,7 @@ hydra: mode: train # running mode: train/eval seed: 42 output_dir: ${hydra:run.dir} +log_freq: 20 # set working condition NU: 0.01 @@ -55,3 +56,21 @@ EVAL: pretrained_model_path: null batch_size: residual_validator: 8192 + +# inference settings +INFER: + pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_steady_Re10/ldc2d_steady_Re10_pretrained.pdparams + export_path: ./inference/ldc2d_steady_Re10 + pdmodel_path: ${INFER.export_path}.pdmodel + pdpiparams_path: ${INFER.export_path}.pdiparams + onnx_path: ${INFER.export_path}.onnx + device: gpu + engine: native + precision: fp32 + ir_optim: true + min_subgraph_size: 5 + gpu_mem: 2000 + gpu_id: 0 + max_batch_size: 8192 + num_cpu_threads: 10 + batch_size: 8192 \ No newline at end of file diff --git a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml index 0414836af..4f597bd61 100644 --- a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml @@ -22,6 +22,7 @@ hydra: mode: train # running mode: train/eval seed: 42 output_dir: ${hydra:run.dir} +log_freq: 20 # set working condition NU: 0.01 @@ -56,3 +57,21 @@ EVAL: pretrained_model_path: null batch_size: residual_validator: 8192 + +# inference settings +INFER: + pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_unsteady_Re10/ldc2d_unsteady_Re10_pretrained.pdparams + export_path: ./inference/ldc2d_unsteady_Re10 + pdmodel_path: ${INFER.export_path}.pdmodel + pdiparams_path: ${INFER.export_path}.pdiparams + onnx_path: ${INFER.export_path}.onnx + device: gpu + engine: native + precision: fp32 + ir_optim: true + min_subgraph_size: 5 + gpu_mem: 2000 + gpu_id: 0 + max_batch_size: 8192 + num_cpu_threads: 10 + batch_size: 8192 \ No newline at end of file diff --git a/examples/ldc/ldc2d_steady_Re10.py b/examples/ldc/ldc2d_steady_Re10.py index 37cf32541..5e4cda2c7 100644 --- a/examples/ldc/ldc2d_steady_Re10.py +++ b/examples/ldc/ldc2d_steady_Re10.py @@ -234,6 +234,60 @@ def evaluate(cfg: DictConfig): solver.visualize() +def export(cfg: DictConfig): + # set model + model = ppsci.arch.MLP(**cfg.MODEL) + + # initialize solver + solver = ppsci.solver.Solver( + model, + pretrained_model_path=cfg.INFER.pretrained_model_path, + ) + # export model + from paddle.static import InputSpec + + input_spec = [ + {key: InputSpec([None, 1], "float32", name=key) for key in model.input_keys}, + ] + solver.export(input_spec, cfg.INFER.export_path) + + +def inference(cfg: DictConfig): + from deploy.python_infer import pinn_predictor + + predictor = pinn_predictor.PINNPredictor(cfg) + + # set geometry + geom = {"rect": ppsci.geometry.Rectangle((-0.05, -0.05), (0.05, 0.05))} + # manually collate input data for inference + NPOINT_PDE = 99**2 + NPOINT_TOP = 101 + NPOINT_BOTTOM = 101 + NPOINT_LEFT = 99 + NPOINT_RIGHT = 99 + NPOINT_BC = NPOINT_TOP + NPOINT_BOTTOM + NPOINT_LEFT + NPOINT_RIGHT + input_dict = geom["rect"].sample_interior(NPOINT_PDE + NPOINT_BC, evenly=True) + output_dict = predictor.predict( + {key: input_dict[key] for key in cfg.MODEL.input_keys}, cfg.INFER.batch_size + ) + + # mapping data to cfg.INFER.output_keys + output_dict = { + store_key:output_dict[infer_key] + for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) + } + + ppsci.visualize.save_vtu_from_dict( + "./ldc2d_steady_Re10.vtu", + {**input_dict, **output_dict}, + input_dict.keys(), + cfg.MODEL.output_keys, + ) + + + + + @hydra.main( version_base=None, config_path="./conf", config_name="ldc2d_steady_Re10.yaml" ) @@ -242,8 +296,12 @@ def main(cfg: DictConfig): train(cfg) elif cfg.mode == "eval": evaluate(cfg) + elif cfg.mode == "export": + export(cfg) + elif cfg.mode == "infer": + inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") + raise ValueError(f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'") if __name__ == "__main__": diff --git a/examples/ldc/ldc2d_unsteady_Re10.py b/examples/ldc/ldc2d_unsteady_Re10.py index 3ed4ba705..a9fb08b48 100644 --- a/examples/ldc/ldc2d_unsteady_Re10.py +++ b/examples/ldc/ldc2d_unsteady_Re10.py @@ -308,6 +308,100 @@ def evaluate(cfg: DictConfig): solver.visualize() +def export(cfg: DictConfig): + # set model + model = ppsci.arch.MLP(**cfg.MODEL) + + # initialize solver + solver = ppsci.solver.Solver( + model, + pretrained_model_path=cfg.INFER.pretrained_model_path, + ) + # export model + from paddle.static import InputSpec + + input_spec = [ + {key: InputSpec([None, 1], "float32", name=key) for key in model.input_keys}, + ] + solver.export(input_spec, cfg.INFER.export_path) + + +def inference(cfg: DictConfig): + from deploy.python_infer import pinn_predictor + + predictor = pinn_predictor.PINNPredictor(cfg) + + # set timestamps(including initial t0) + timestamps = np.linspace(0.0, 1.5, cfg.NTIME_ALL, endpoint=True) + # set time-geometry + geom = { + "time_rect": ppsci.geometry.TimeXGeometry( + ppsci.geometry.TimeDomain(0.0, 1.5, timestamps=timestamps), + ppsci.geometry.Rectangle((-0.05, -0.05), (0.05, 0.05)), + ) + } + # manually collate input data for inference + NPOINT_PDE = 99**2 + NPOINT_TOP = 101 + NPOINT_DOWN = 101 + NPOINT_LEFT = 99 + NPOINT_RIGHT = 99 + NPOINT_IC = 99**2 + NTIME_PDE = cfg.NTIME_ALL - 1 + NPOINT_BC = NPOINT_TOP + NPOINT_DOWN + NPOINT_LEFT + NPOINT_RIGHT + input_dict = geom["time_rect"].sample_initial_interior( + (NPOINT_IC + NPOINT_BC), evenly=True + ) + del input_dict["sdf"] + input_pde_dict = geom["time_rect"].sample_interior( + (NPOINT_PDE + NPOINT_BC) * NTIME_PDE, evenly=True + ) + # (interior+boundary) x all timestamps + for t in range(NTIME_PDE): + for key in geom["time_rect"].dim_keys: + input_dict[key] = np.concatenate( + ( + input_dict[key], + input_pde_dict[key][ + t + * (NPOINT_PDE + NPOINT_BC) : (t + 1) + * (NPOINT_PDE + NPOINT_BC) + ], + ) + ) + output_dict = predictor.predict( + {key: input_dict[key] for key in cfg.MODEL.input_keys}, cfg.INFER.batch_size + ) + + # mapping data to cfg.INFER.output_keys + output_dict = { + store_key: output_dict[infer_key] + for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) + } + + unique_t_values = np.unique(input_dict['t']) + segmented_input_dict = {} + segmented_output_dict = {} + for idx, t_value in enumerate(unique_t_values): + # Find the indices corresponding to the current t value + indices = np.where(input_dict['t'] == t_value)[0] + # Extract the corresponding x and y values based on the indices + x_values = input_dict['x'][indices] + y_values = input_dict['y'][indices] + u_values = output_dict['u'][indices] + v_values = output_dict['v'][indices] + p_values = output_dict['p'][indices] + # Construct segmented dictionaries + segmented_input_dict = {'x': x_values, 'y': y_values} + segmented_output_dict = {'u': u_values, 'v': v_values, 'p': p_values} + ppsci.visualize.save_vtu_from_dict( + "./ldc2d_unsteady_Re10_pred_"+ str(idx) + ".vtu", + {**segmented_input_dict, **segmented_output_dict}, + input_dict.keys(), + cfg.MODEL.output_keys, + ) + + @hydra.main( version_base=None, config_path="./conf", config_name="ldc2d_unsteady_Re10.yaml" ) @@ -316,8 +410,12 @@ def main(cfg: DictConfig): train(cfg) elif cfg.mode == "eval": evaluate(cfg) + elif cfg.mode == "export": + export(cfg) + elif cfg.mode == "infer": + inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") + raise ValueError(f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'") if __name__ == "__main__": From 2986349051019ed7848916e22098de75a8bbc90a Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:21:00 +0800 Subject: [PATCH 4/9] =?UTF-8?q?fix=20codestyle=20bug=20for=20PPSCI=20Expor?= =?UTF-8?q?t&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/ldc2d_steady_Re10.py | 6 ++++-- examples/ldc/ldc2d_unsteady_Re10.py | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/examples/ldc/ldc2d_steady_Re10.py b/examples/ldc/ldc2d_steady_Re10.py index 5e4cda2c7..9cb4af2ab 100644 --- a/examples/ldc/ldc2d_steady_Re10.py +++ b/examples/ldc/ldc2d_steady_Re10.py @@ -273,7 +273,7 @@ def inference(cfg: DictConfig): # mapping data to cfg.INFER.output_keys output_dict = { - store_key:output_dict[infer_key] + store_key: output_dict[infer_key] for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) } @@ -301,7 +301,9 @@ def main(cfg: DictConfig): elif cfg.mode == "infer": inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'") + raise ValueError( + f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" + ) if __name__ == "__main__": diff --git a/examples/ldc/ldc2d_unsteady_Re10.py b/examples/ldc/ldc2d_unsteady_Re10.py index a9fb08b48..40cbca474 100644 --- a/examples/ldc/ldc2d_unsteady_Re10.py +++ b/examples/ldc/ldc2d_unsteady_Re10.py @@ -352,7 +352,6 @@ def inference(cfg: DictConfig): input_dict = geom["time_rect"].sample_initial_interior( (NPOINT_IC + NPOINT_BC), evenly=True ) - del input_dict["sdf"] input_pde_dict = geom["time_rect"].sample_interior( (NPOINT_PDE + NPOINT_BC) * NTIME_PDE, evenly=True ) @@ -379,23 +378,23 @@ def inference(cfg: DictConfig): for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) } - unique_t_values = np.unique(input_dict['t']) + unique_t_values = np.unique(input_dict["t"]) segmented_input_dict = {} segmented_output_dict = {} for idx, t_value in enumerate(unique_t_values): # Find the indices corresponding to the current t value - indices = np.where(input_dict['t'] == t_value)[0] + indices = np.where(input_dict["t"] == t_value)[0] # Extract the corresponding x and y values based on the indices - x_values = input_dict['x'][indices] - y_values = input_dict['y'][indices] - u_values = output_dict['u'][indices] - v_values = output_dict['v'][indices] - p_values = output_dict['p'][indices] + x_values = input_dict["x"][indices] + y_values = input_dict["y"][indices] + u_values = output_dict["u"][indices] + v_values = output_dict["v"][indices] + p_values = output_dict["p"][indices] # Construct segmented dictionaries - segmented_input_dict = {'x': x_values, 'y': y_values} - segmented_output_dict = {'u': u_values, 'v': v_values, 'p': p_values} + segmented_input_dict = {"x": x_values, "y": y_values} + segmented_output_dict = {"u": u_values, "v": v_values, "p": p_values} ppsci.visualize.save_vtu_from_dict( - "./ldc2d_unsteady_Re10_pred_"+ str(idx) + ".vtu", + "./ldc2d_unsteady_Re10_pred_" + str(idx) + ".vtu", {**segmented_input_dict, **segmented_output_dict}, input_dict.keys(), cfg.MODEL.output_keys, @@ -415,7 +414,9 @@ def main(cfg: DictConfig): elif cfg.mode == "infer": inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'") + raise ValueError( + f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" + ) if __name__ == "__main__": From cfab6002d51b6595ebdd7884ec9fa8e1c2625dfd Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:24:51 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix=20codestyle=20bugs=20for=20=E3=80=90PPS?= =?UTF-8?q?CI=20Export&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/ldc2d_steady_Re10.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/ldc/ldc2d_steady_Re10.py b/examples/ldc/ldc2d_steady_Re10.py index 9cb4af2ab..3c6507932 100644 --- a/examples/ldc/ldc2d_steady_Re10.py +++ b/examples/ldc/ldc2d_steady_Re10.py @@ -284,9 +284,6 @@ def inference(cfg: DictConfig): cfg.MODEL.output_keys, ) - - - @hydra.main( version_base=None, config_path="./conf", config_name="ldc2d_steady_Re10.yaml" From cf0c33f2a9137638c427c9cd99cb9287bcab0a8f Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:29:48 +0800 Subject: [PATCH 6/9] =?UTF-8?q?fix=20codestyle=20bugs=20for=20=E3=80=90PPS?= =?UTF-8?q?CI=20Export&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/conf/ldc2d_steady_Re10.yaml | 3 ++- examples/ldc/conf/ldc2d_unsteady_Re10.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/ldc/conf/ldc2d_steady_Re10.yaml b/examples/ldc/conf/ldc2d_steady_Re10.yaml index 330089927..21dc93e9b 100644 --- a/examples/ldc/conf/ldc2d_steady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_steady_Re10.yaml @@ -73,4 +73,5 @@ INFER: gpu_id: 0 max_batch_size: 8192 num_cpu_threads: 10 - batch_size: 8192 \ No newline at end of file + batch_size: 8192 + \ No newline at end of file diff --git a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml index 4f597bd61..fe744b5a7 100644 --- a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml @@ -74,4 +74,5 @@ INFER: gpu_id: 0 max_batch_size: 8192 num_cpu_threads: 10 - batch_size: 8192 \ No newline at end of file + batch_size: 8192 + \ No newline at end of file From 7f8bfb2f62e098505474b29b8074231dd5d22009 Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:32:13 +0800 Subject: [PATCH 7/9] =?UTF-8?q?fix=20codestyle=20bugs=20for=20=E3=80=90PPS?= =?UTF-8?q?CI=20Export&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/conf/ldc2d_steady_Re10.yaml | 1 - examples/ldc/conf/ldc2d_unsteady_Re10.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/examples/ldc/conf/ldc2d_steady_Re10.yaml b/examples/ldc/conf/ldc2d_steady_Re10.yaml index 21dc93e9b..cc4c62c4e 100644 --- a/examples/ldc/conf/ldc2d_steady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_steady_Re10.yaml @@ -74,4 +74,3 @@ INFER: max_batch_size: 8192 num_cpu_threads: 10 batch_size: 8192 - \ No newline at end of file diff --git a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml index fe744b5a7..e03441980 100644 --- a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml @@ -75,4 +75,3 @@ INFER: max_batch_size: 8192 num_cpu_threads: 10 batch_size: 8192 - \ No newline at end of file From ddee33e7123df89ca9a8cc99a750fabbea627dbc Mon Sep 17 00:00:00 2001 From: wufei Date: Mon, 6 May 2024 16:46:33 +0800 Subject: [PATCH 8/9] =?UTF-8?q?fix=20bugs=20for=20=E3=80=90PPSCI=20Export&?= =?UTF-8?q?Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/ldc2d_unsteady_Re10.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/examples/ldc/ldc2d_unsteady_Re10.py b/examples/ldc/ldc2d_unsteady_Re10.py index 40cbca474..bed7690ae 100644 --- a/examples/ldc/ldc2d_unsteady_Re10.py +++ b/examples/ldc/ldc2d_unsteady_Re10.py @@ -378,27 +378,13 @@ def inference(cfg: DictConfig): for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) } - unique_t_values = np.unique(input_dict["t"]) - segmented_input_dict = {} - segmented_output_dict = {} - for idx, t_value in enumerate(unique_t_values): - # Find the indices corresponding to the current t value - indices = np.where(input_dict["t"] == t_value)[0] - # Extract the corresponding x and y values based on the indices - x_values = input_dict["x"][indices] - y_values = input_dict["y"][indices] - u_values = output_dict["u"][indices] - v_values = output_dict["v"][indices] - p_values = output_dict["p"][indices] - # Construct segmented dictionaries - segmented_input_dict = {"x": x_values, "y": y_values} - segmented_output_dict = {"u": u_values, "v": v_values, "p": p_values} - ppsci.visualize.save_vtu_from_dict( - "./ldc2d_unsteady_Re10_pred_" + str(idx) + ".vtu", - {**segmented_input_dict, **segmented_output_dict}, - input_dict.keys(), - cfg.MODEL.output_keys, - ) + ppsci.visualize.save_vtu_from_dict( + "./ldc2d_unsteady_Re10_pred.vtu", + {**input_dict, **output_dict}, + input_dict.keys(), + cfg.MODEL.output_keys, + cfg.NTIME_ALL + ) @hydra.main( From dfb36490122887b6cf4cc3a59880c8348614461d Mon Sep 17 00:00:00 2001 From: wufei Date: Mon, 6 May 2024 16:52:10 +0800 Subject: [PATCH 9/9] fix codestyle bugs --- examples/ldc/ldc2d_unsteady_Re10.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ldc/ldc2d_unsteady_Re10.py b/examples/ldc/ldc2d_unsteady_Re10.py index bed7690ae..aeb88868c 100644 --- a/examples/ldc/ldc2d_unsteady_Re10.py +++ b/examples/ldc/ldc2d_unsteady_Re10.py @@ -383,7 +383,7 @@ def inference(cfg: DictConfig): {**input_dict, **output_dict}, input_dict.keys(), cfg.MODEL.output_keys, - cfg.NTIME_ALL + cfg.NTIME_ALL, )