|
28 | 28 | from haddock.gear.parameters import config_mandatory_general_parameters |
29 | 29 | from haddock.gear.yaml2cfg import read_from_yaml_config, find_incompatible_parameters |
30 | 30 | from haddock.libs.libhpc import HPCScheduler |
31 | | -from haddock.libs.libgrid import GRIDScheduler |
| 31 | +from haddock.libs.libgrid import GRIDScheduler, ping_dirac |
32 | 32 | from haddock.libs.libio import folder_exists, working_directory |
33 | 33 | from haddock.libs.libmpi import MPIScheduler |
34 | 34 | from haddock.libs.libontology import ModuleIO, PDBFile |
|
65 | 65 | # modules will use these parameters. It is the responsibility of the module to |
66 | 66 | # extract the parameters it needs. |
67 | 67 | # the config file is in modules/defaults.cfg |
68 | | -non_mandatory_general_parameters_defaults = read_from_yaml_config( |
69 | | - modules_defaults_path |
70 | | -) # noqa : E501 |
| 68 | +non_mandatory_general_parameters_defaults = read_from_yaml_config(modules_defaults_path) # noqa : E501 |
71 | 69 |
|
72 | 70 | incompatible_defaults_params = find_incompatible_parameters(modules_defaults_path) |
73 | 71 |
|
@@ -187,9 +185,7 @@ def update_params( |
187 | 185 | >>> m.update_params(...) |
188 | 186 | """ |
189 | 187 | if update_from_cfg_file and params: |
190 | | - _msg = ( |
191 | | - "You can not provide both `update_from_cfg_file` " "and key arguments." |
192 | | - ) |
| 188 | + _msg = "You can not provide both `update_from_cfg_file` and key arguments." |
193 | 189 | raise TypeError(_msg) |
194 | 190 |
|
195 | 191 | if update_from_cfg_file: |
@@ -305,7 +301,7 @@ def export_io_models(self, faulty_tolerance: float = 0.0) -> None: |
305 | 301 | if detected_errors := find_all_cns_errors(self.path): |
306 | 302 | _msg += linesep |
307 | 303 | for error in detected_errors.values(): |
308 | | - _msg += f'{str(error["error"])}{linesep}' |
| 304 | + _msg += f"{str(error['error'])}{linesep}" |
309 | 305 | # Show final error message |
310 | 306 | self.finish_with_error(_msg) |
311 | 307 |
|
@@ -399,7 +395,7 @@ def _fill_emptypaths(self) -> None: |
399 | 395 | def get_engine( |
400 | 396 | mode: str, |
401 | 397 | params: dict[Any, Any], |
402 | | -) -> partial[Union[HPCScheduler, Scheduler, MPIScheduler]]: |
| 398 | +) -> partial[Union[HPCScheduler, Scheduler, MPIScheduler, GRIDScheduler]]: |
403 | 399 | """ |
404 | 400 | Create an engine to run the jobs. |
405 | 401 |
|
@@ -433,10 +429,22 @@ def get_engine( |
433 | 429 | return partial(MPIScheduler, ncores=params["ncores"]) # type: ignore |
434 | 430 |
|
435 | 431 | elif mode == "grid": |
436 | | - return partial(GRIDScheduler, params=params) # type: ignore |
| 432 | + # `grid` mode should only be used IF the grid is reachable, |
| 433 | + # if not it should fallback to `local` |
| 434 | + grid_available = ping_dirac() |
| 435 | + |
| 436 | + if grid_available: |
| 437 | + return partial(GRIDScheduler, params=params) # type: ignore |
| 438 | + else: |
| 439 | + log.warning("GRID is not available, activating fallback using `mode=local`") |
| 440 | + return partial( # type: ignore |
| 441 | + Scheduler, |
| 442 | + ncores=params["ncores"], |
| 443 | + max_cpus=params["max_cpus"], |
| 444 | + ) |
437 | 445 |
|
438 | 446 | else: |
439 | | - available_engines = ("batch", "local", "mpi") |
| 447 | + available_engines = ("batch", "local", "mpi", "grid") |
440 | 448 | raise ValueError( |
441 | 449 | f"Scheduler `mode` {mode!r} not recognized. " |
442 | 450 | f"Available options are {', '.join(available_engines)}" |
|
0 commit comments