Skip to content

Commit d0445e1

Browse files
authored
Merge pull request #133 from GeoOcean/132-error-when-saving-wrapper
[JTH] modifications in base_wrappers
2 parents ef5e0b4 + 08f365d commit d0445e1

2 files changed

Lines changed: 39 additions & 16 deletions

File tree

bluemath_tk/wrappers/_base_wrappers.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class BaseModelWrapper(BlueMathModel, ABC):
5454

5555
sbatch_file_example = sbatch_file_example
5656

57+
available_launchers = {}
58+
5759
def __new__(cls, *args, **kwargs):
5860
if cls is BaseModelWrapper:
5961
raise TypeError(
@@ -77,9 +79,8 @@ def __init__(
7779
Parameters
7880
----------
7981
templates_dir : str
80-
The directory where the templates are searched.
81-
Both binary and text files are supported, for the case where the user
82-
needs to have a fixed binary file in all cases directories.
82+
The directory where the templates are searched. If None, no templates will be used.
83+
Both binary and text files are supported as templates.
8384
metamodel_parameters : dict
8485
The parameters to be used for the different cases.
8586
fixed_parameters : dict
@@ -109,15 +110,24 @@ def __init__(
109110
self.metamodel_parameters = metamodel_parameters
110111
self.fixed_parameters = fixed_parameters
111112
self.output_dir = output_dir
112-
self._env = Environment(loader=FileSystemLoader(self.templates_dir))
113-
if templates_name == "all":
114-
self.logger.info(
115-
f"Templates name is 'all', so all templates in {self.templates_dir} will be used."
116-
)
117-
self.templates_name = self.env.list_templates()
118-
self.logger.info(f"Templates names: {self.templates_name}")
113+
114+
if self.templates_dir is not None:
115+
self._env = Environment(loader=FileSystemLoader(self.templates_dir))
116+
if templates_name == "all":
117+
self.logger.info(
118+
f"Templates name is 'all', so all templates in {self.templates_dir} will be used."
119+
)
120+
self.templates_name = self.env.list_templates()
121+
self.logger.info(f"Templates names: {self.templates_name}")
122+
else:
123+
self.templates_name = templates_name
119124
else:
120-
self.templates_name = templates_name
125+
self.logger.warning(
126+
"No templates directory provided, so no templates will be used."
127+
)
128+
self._env = None
129+
self.templates_name = []
130+
121131
self.cases_context: List[dict] = None
122132
self.cases_dirs: List[str] = None
123133
self.thread: threading.Thread = None
@@ -704,18 +714,34 @@ def get_thread_status(self) -> str:
704714
def run_cases_bulk(
705715
self,
706716
launcher: str,
717+
path_to_execute: str = None,
707718
) -> None:
708719
"""
709720
Run the cases based on the launcher specified.
721+
This is thought to be used in a cluster environment, as it is a bulk execution of the cases.
722+
By default, the command is executed in the output directory, where the cases are saved,
723+
and where the example sbatch file is saved.
710724
711725
Parameters
712726
----------
713727
launcher : str
714728
The launcher to run the cases.
729+
path_to_execute : str, optional
730+
The path to execute the command. Default is None.
731+
732+
Examples
733+
--------
734+
# This will execute the specified launcher in the output directory.
735+
>>> wrapper.run_cases_bulk(launcher="sbatch sbatch_example.sh")
736+
# This will execute the specified launcher in the specified path.
737+
>>> wrapper.run_cases_bulk(launcher="my_launcher.sh", path_to_execute="/my/path/to/execute")
715738
"""
716739

717-
self.logger.info(f"Running cases with launcher={launcher}.")
718-
self._exec_bash_commands(str_cmd=launcher, cwd=self.output_dir)
740+
if path_to_execute is None:
741+
path_to_execute = self.output_dir
742+
743+
self.logger.info(f"Running cases with launcher={launcher} in {path_to_execute}")
744+
self._exec_bash_commands(str_cmd=launcher, cwd=path_to_execute)
719745

720746
def monitor_cases(
721747
self, cases_status: dict, value_counts: str

bluemath_tk/wrappers/delft3d/delft3d_wrapper.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ def monitor_cases(
167167
)
168168

169169

170-
import matplotlib.pyplot as plt
171-
172-
173170
def format_matrix(mat):
174171
return "\n".join(
175172
" ".join(f"{x:.1f}" if abs(x) > 0.01 else "0" for x in line) for line in mat

0 commit comments

Comments
 (0)