Skip to content

Commit

Permalink
Merge pull request #341 from pyiron/validate_backend
Browse files Browse the repository at this point in the history
Add validate backend fucntion
  • Loading branch information
jan-janssen committed May 29, 2024
2 parents 62fae9c + 5c05f5f commit 75613c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 6 additions & 4 deletions pympipool/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
check_threads_per_core,
check_oversubscribe,
check_executor,
check_backend,
check_init_function,
validate_backend,
validate_number_of_cores,
)
from pympipool.scheduler.slurm import (
Expand Down Expand Up @@ -87,8 +87,10 @@ def create_executor(
"""
max_cores = validate_number_of_cores(max_cores=max_cores, max_workers=max_workers)
check_init_function(block_allocation=block_allocation, init_function=init_function)
check_backend(backend=backend)
if backend == "flux" or (backend == "auto" and flux_installed):
backend = validate_backend(
backend=backend, flux_installed=flux_installed, slurm_installed=slurm_installed
)
if backend == "flux":
check_oversubscribe(oversubscribe=oversubscribe)
check_command_line_argument_lst(
command_line_argument_lst=command_line_argument_lst
Expand All @@ -114,7 +116,7 @@ def create_executor(
executor=executor,
hostname_localhost=hostname_localhost,
)
elif backend == "slurm" or (backend == "auto" and slurm_installed):
elif backend == "slurm":
check_executor(executor=executor)
if block_allocation:
return PySlurmExecutor(
Expand Down
10 changes: 9 additions & 1 deletion pympipool/shared/inputcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,22 @@ def check_refresh_rate(refresh_rate: float):
)


def check_backend(backend: str):
def validate_backend(
backend: str, flux_installed: bool = False, slurm_installed: bool = False
) -> str:
if backend not in ["auto", "mpi", "slurm", "flux"]:
raise ValueError(
'The currently implemented backends are ["flux", "mpi", "slurm"]. '
'Alternatively, you can select "auto", the default option, to automatically determine the backend. But '
+ backend
+ " is not a valid choice."
)
elif backend == "flux" or (backend == "auto" and flux_installed):
return "flux"
elif backend == "slurm" or (backend == "auto" and slurm_installed):
return "slurm"
else:
return "mpi"


def check_init_function(block_allocation: bool, init_function: callable):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_shared_input_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
check_threads_per_core,
check_oversubscribe,
check_executor,
check_backend,
check_init_function,
check_refresh_rate,
check_resource_dict,
check_resource_dict_is_empty,
validate_backend,
)


Expand All @@ -37,7 +37,9 @@ def test_check_executor(self):

def test_check_backend(self):
with self.assertRaises(ValueError):
check_backend(backend="test")
validate_backend(
backend="test", slurm_installed=False, flux_installed=False
)

def test_check_init_function(self):
with self.assertRaises(ValueError):
Expand Down

0 comments on commit 75613c1

Please sign in to comment.