From 844855600dbe5a57e0f825e81739d1c0e016330e Mon Sep 17 00:00:00 2001 From: veenstrajelmer <60435591+veenstrajelmer@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:35:16 +0200 Subject: [PATCH] 890 require hydrolib core 080 to extend mdu keyword support (#891) * updated minimal version for hydrolib-core * removed workaround for number of processes in dimr_config.xml --- dfm_tools/modelbuilder.py | 13 ------------- pyproject.toml | 4 ++-- tests/test_modelbuilder.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/dfm_tools/modelbuilder.py b/dfm_tools/modelbuilder.py index d0f275da2..a9d52f158 100644 --- a/dfm_tools/modelbuilder.py +++ b/dfm_tools/modelbuilder.py @@ -247,19 +247,6 @@ def create_model_exec_files(file_mdu, nproc=1, dimrset_folder=None, path_style=N print(f"writing {dimr_name}") dimr_model.save(file_dimr) - # TODO: hydrolib-core does not support multiple cores properly: https://github.com/Deltares/dfm_tools/issues/214 - # therefore we manually replace it in the file - print(f"re-writing {dimr_name}") - with open(file_dimr,'r') as f: - lines = f.readlines() - str_from = f"{nproc}" - nproc_range_str = " ".join([str(x) for x in range(nproc)]) - str_to = f"{nproc_range_str}" - lines_new = [line.replace(str_from,str_to) for line in lines] - with open(file_dimr,'w') as f: - for line in lines_new: - f.write(line) - if dimrset_folder is None: print("no dimrset_folder provided, cannot write bat/sh file") return diff --git a/pyproject.toml b/pyproject.toml index 84ba3f189..62d3385ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,8 +50,8 @@ dependencies = [ "rws-ddlpy>=0.4.0", #pooch<1.1.0 do not have attribute retrieve "pooch>=1.1.0", - #hydrolib-core 0.7.0 supports meshkernel>=4.1.0 - "hydrolib-core>=0.7.0", + #hydrolib-core 0.8.0 support for many more mdu keywords and correct dimr_config.xml for parallel runs + "hydrolib-core>=0.8.0", #meshkernel<4.2.0 support for more gridded_samples dtypes and workarounds for non-orthogonal grids "meshkernel>=4.2.0", ] diff --git a/tests/test_modelbuilder.py b/tests/test_modelbuilder.py index 3bbf45771..8ffcf5b7d 100644 --- a/tests/test_modelbuilder.py +++ b/tests/test_modelbuilder.py @@ -67,13 +67,19 @@ def test_create_model_exec_files_none(tmp_path): mdu_file = tmp_path / "temp_test.mdu" file_dimr = tmp_path / "dimr_config.xml" - nproc = 1 # number of processes + nproc = 4 # number of processes dimrset_folder = None mdu = hcdfm.FMModel() mdu.save(mdu_file) dfmt.create_model_exec_files(file_mdu=mdu_file, nproc=nproc, dimrset_folder=dimrset_folder) assert os.path.isfile(file_dimr) + + # check if the dimr_config.xml file had the correct amount of processes + # this failed before fixing https://github.com/Deltares/HYDROLIB-core/issues/562 + with open(file_dimr, 'r') as f: + data = f.readlines() + assert ' 0 1 2 3\n' in data @pytest.mark.unittest @@ -116,7 +122,7 @@ def test_make_paths_relative(tmp_path): forcingfile=ForcingModel_object) ext_new.boundary.append(boundary_object) ext_new.save(filepath=ext_file_new) - + # old ext ext_file_old = os.path.join(tmp_path, 'test_old.ext') ext_old = hcdfm.ExtOldModel()