Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【hydra No.7】Adapt ldc2d_unsteady_Re10 to hydra #580

Merged
merged 6 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix ldc2d_unsteady.md、ldc2d_unsteady_Re10.yaml、ldc2d_unsteady_Re10.py
  • Loading branch information
lknt committed Oct 20, 2023
commit 8972fe3b2279f7374e53b8816050c7f05dabeeb1
4 changes: 1 addition & 3 deletions docs/zh/examples/ldc2d_unsteady.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

=== "模型训练命令"
``` sh
python ldc2d_unsteady_Re10.py
```


=== "模型评估命令"
``` sh
```

## 1. 背景简介

Expand Down
8 changes: 8 additions & 0 deletions examples/ldc/conf/ldc2d_unsteady_Re10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ hydra:
job:
name: ${mode} # name of logfile
chdir: false # keep current working direcotry unchanged
config:
override_dirname:
exclude_keys:
- TRAIN.checkpoint_path
- TRAIN.pretrained_model_path
- EVAL.pretrained_model_path
- mode
- output_dir
sweep:
# output directory for multirun
dir: ${hydra.run.dir}
Expand Down
26 changes: 11 additions & 15 deletions examples/ldc/ldc2d_unsteady_Re10.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@
from omegaconf import DictConfig

import ppsci
# from ppsci.utils import config
from ppsci.utils import logger

def train(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, "train.log"), "info")

# set model
model = ppsci.arch.MLP(**cfg.MODEL.model)

# set equation
equation = {"NavierStokes": ppsci.equation.NavierStokes(0.01, 1.0, 2, True)}

# set timestamps(including initial t0)
timestamps = np.linspace(0.0, 1.5, 16, endpoint=True)

# set time-geometry
geom = {
"time_rect": ppsci.geometry.TimeXGeometry(
Expand Down Expand Up @@ -122,7 +125,6 @@ def train(cfg: DictConfig):
}

# set training hyper-parameters

lr_scheduler = ppsci.optimizer.lr_scheduler.Cosine(
**cfg.TRAIN.lr_scheduler,
warmup_epoch=int(0.05 * cfg.TRAIN.epochs),
Expand Down Expand Up @@ -213,19 +215,24 @@ def evaluate(cfg: DictConfig):
ppsci.utils.misc.set_random_seed(cfg.seed)
# initialize logger
logger.init_logger("ppsci", osp.join(cfg.output_dir, "train.log"), "info")
lknt marked this conversation as resolved.
Show resolved Hide resolved

# set model
model = ppsci.arch.MLP(**cfg.MODEL.model)

# set equation
equation = {"NavierStokes": ppsci.equation.NavierStokes(0.01, 1.0, 2, True)}
lknt marked this conversation as resolved.
Show resolved Hide resolved

# set timestamps(including initial t0)
timestamps = np.linspace(0.0, 1.5, 16, endpoint=True)
lknt marked this conversation as resolved.
Show resolved Hide resolved

# 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)),
)
}

# pde/bc constraint use t1~tn, initial constraint use t0
NTIME_ALL = len(timestamps)
lknt marked this conversation as resolved.
Show resolved Hide resolved
NPOINT_PDE, NTIME_PDE = 99**2, NTIME_ALL - 1
Expand All @@ -235,8 +242,6 @@ def evaluate(cfg: DictConfig):
NPOINT_RIGHT, NTIME_RIGHT = 99, NTIME_ALL - 1
NPOINT_IC, NTIME_IC = 99**2, 1



# set validator
NPOINT_EVAL = NPOINT_PDE * NTIME_ALL
residual_validator = ppsci.validate.GeometryValidator(
Expand All @@ -256,6 +261,7 @@ def evaluate(cfg: DictConfig):
name="Residual",
)
validator = {residual_validator.name: residual_validator}

# set visualizer(optional)
NPOINT_BC = NPOINT_TOP + NPOINT_DOWN + NPOINT_LEFT + NPOINT_RIGHT
vis_initial_points = geom["time_rect"].sample_initial_interior(
Expand Down Expand Up @@ -288,16 +294,6 @@ def evaluate(cfg: DictConfig):
prefix="result_u_v",
)
}
# set visualizer(optional)
NPOINT_BC = NPOINT_TOP + NPOINT_DOWN + NPOINT_LEFT + NPOINT_RIGHT
vis_initial_points = geom["time_rect"].sample_initial_interior(
(NPOINT_IC + NPOINT_BC), evenly=True
)
vis_pde_points = geom["time_rect"].sample_interior(
(NPOINT_PDE + NPOINT_BC) * NTIME_PDE, evenly=True
)
vis_points = vis_initial_points


# directly evaluate pretrained model(optional)
solver = ppsci.solver.Solver(
Expand All @@ -323,4 +319,4 @@ def main(cfg: DictConfig):


if __name__ == "__main__":
main()
main()