|
| 1 | +"""Placeholder forward run script for PEST++ workers. |
| 2 | +
|
| 3 | +PestBuilder auto-generates the actual custom_forward_run.py in the pest/ |
| 4 | +directory during calibration. This file exists only as a fallback template. |
| 5 | +""" |
| 6 | + |
1 | 7 | import os |
2 | 8 | import warnings |
3 | 9 |
|
4 | 10 | warnings.filterwarnings("ignore", category=FutureWarning) |
5 | 11 |
|
6 | 12 |
|
7 | 13 | def run(): |
8 | | - """Custom forward runner for PEST++ workers. |
9 | | -
|
10 | | - This imports the packaged optimize_fields function and executes it with the |
11 | | - configuration from the 3_Crane project. It expects to be run in the worker |
12 | | - directory; PEST++ will create a 'mult' subfolder containing parameter files. |
13 | | - """ |
14 | | - from swimrs.calibrate.run_mp import optimize_fields |
15 | | - from swimrs.swim.config import ProjectConfig |
16 | | - |
17 | | - here = os.path.dirname(os.path.abspath(__file__)) |
18 | | - conf_file = os.path.join(here, "3_Crane.toml") |
19 | | - if not os.path.exists(conf_file): |
20 | | - conf_file = os.path.join(here, "config.toml") |
21 | | - if not os.path.exists(conf_file): |
22 | | - raise FileNotFoundError(f"Expected config at {conf_file}") |
23 | | - |
24 | | - # Resolve input_data path from config |
25 | | - cfg = ProjectConfig() |
26 | | - cfg.read_config(conf_file) |
27 | | - input_data_path = cfg.input_data |
28 | | - |
29 | | - # PEST++ worker CWD |
| 14 | + """Forward runner for PEST++ workers using the process package.""" |
| 15 | + from swimrs.process.input import SwimInput |
| 16 | + from swimrs.process.loop_fast import run_daily_loop_fast |
| 17 | + from swimrs.process.state import CalibrationParameters, load_pest_mult_properties |
| 18 | + |
30 | 19 | cwd = os.getcwd() |
31 | | - calibration_dir = os.path.join(cwd, "mult") |
| 20 | + h5_path = os.path.join(cwd, "swim_input.h5") |
| 21 | + mult_dir = os.path.join(cwd, "mult") |
| 22 | + pred_dir = os.path.join(cwd, "pred") |
| 23 | + os.makedirs(pred_dir, exist_ok=True) |
| 24 | + |
| 25 | + swim_input = SwimInput(h5_path=h5_path) |
| 26 | + |
| 27 | + params = CalibrationParameters.from_pest_mult( |
| 28 | + mult_dir=mult_dir, fids=swim_input.fids, base=swim_input.parameters |
| 29 | + ) |
| 30 | + props = load_pest_mult_properties( |
| 31 | + mult_dir=mult_dir, fids=swim_input.fids, base_props=swim_input.properties |
| 32 | + ) |
| 33 | + |
| 34 | + output, _ = run_daily_loop_fast(swim_input=swim_input, parameters=params, properties=props) |
| 35 | + |
| 36 | + # Write prediction files for PEST++ |
| 37 | + import numpy as np |
32 | 38 |
|
33 | | - optimize_fields(conf_file, input_data_path, cwd, calibration_dir) |
| 39 | + for i, fid in enumerate(swim_input.fids): |
| 40 | + pred_file = os.path.join(pred_dir, f"{fid}.csv") |
| 41 | + np.savetxt(pred_file, output.etf[:, i], fmt="%.6f") |
34 | 42 |
|
35 | 43 |
|
36 | 44 | if __name__ == "__main__": |
|
0 commit comments