Skip to content

Commit 9b4f6a7

Browse files
jan-janssenpyiron-runnerpre-commit-ci[bot]
authored
Refactoring: Definition of task spawner (#797)
* Refactoring: Definition of task spawner * Format black * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pyiron-runner <pyiron@mpie.de> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2110b7e commit 9b4f6a7

20 files changed

+66
-67
lines changed

executorlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def terminate_tasks_in_cache(
5555
config_directory (str, optional): path to the config directory.
5656
backend (str, optional): name of the backend used to spawn tasks ["slurm", "flux"].
5757
"""
58-
from executorlib.task_scheduler.file.queue_spawner import terminate_tasks_in_cache
58+
from executorlib.task_scheduler.file.spawner_pysqa import terminate_tasks_in_cache
5959

6060
return terminate_tasks_in_cache(
6161
cache_directory=cache_directory,

executorlib/executor/flux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def create_flux_executor(
458458
Returns:
459459
InteractiveStepExecutor/ InteractiveExecutor
460460
"""
461-
from executorlib.task_scheduler.interactive.fluxspawner import (
461+
from executorlib.task_scheduler.interactive.spawner_flux import (
462462
FluxPythonSpawner,
463463
validate_max_workers,
464464
)

executorlib/executor/single.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def __init__(
314314
{k: v for k, v in default_resource_dict.items() if k not in resource_dict}
315315
)
316316
if not plot_dependency_graph:
317-
from executorlib.task_scheduler.file.subprocess_spawner import (
317+
from executorlib.task_scheduler.file.spawner_subprocess import (
318318
execute_in_subprocess,
319319
)
320320
from executorlib.task_scheduler.file.task_scheduler import (

executorlib/executor/slurm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414
from executorlib.task_scheduler.interactive.dependency import DependencyTaskScheduler
1515
from executorlib.task_scheduler.interactive.onetoone import OneProcessTaskScheduler
16-
from executorlib.task_scheduler.interactive.slurmspawner import (
16+
from executorlib.task_scheduler.interactive.spawner_slurm import (
1717
SrunSpawner,
1818
validate_max_workers,
1919
)

executorlib/standalone/command.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import sys
44
from typing import Optional
55

6+
SLURM_COMMAND = "srun"
7+
68

79
def get_command_path(executable: str) -> str:
810
"""
@@ -112,3 +114,51 @@ def get_interactive_execute_command(
112114
else:
113115
command_lst += [get_command_path(executable="interactive_serial.py")]
114116
return command_lst
117+
118+
119+
def generate_slurm_command(
120+
cores: int,
121+
cwd: Optional[str],
122+
threads_per_core: int = 1,
123+
gpus_per_core: int = 0,
124+
num_nodes: Optional[int] = None,
125+
exclusive: bool = False,
126+
openmpi_oversubscribe: bool = False,
127+
slurm_cmd_args: Optional[list[str]] = None,
128+
pmi_mode: Optional[str] = None,
129+
) -> list[str]:
130+
"""
131+
Generate the command list for the SLURM interface.
132+
133+
Args:
134+
cores (int): The number of cores.
135+
cwd (str): The current working directory.
136+
threads_per_core (int, optional): The number of threads per core. Defaults to 1.
137+
gpus_per_core (int, optional): The number of GPUs per core. Defaults to 0.
138+
num_nodes (int, optional): The number of compute nodes to use for executing the task. Defaults to None.
139+
exclusive (bool): Whether to exclusively reserve the compute nodes, or allow sharing compute notes. Defaults to False.
140+
openmpi_oversubscribe (bool, optional): Whether to oversubscribe the cores. Defaults to False.
141+
slurm_cmd_args (list[str], optional): Additional command line arguments. Defaults to [].
142+
pmi_mode (str): PMI interface to use (OpenMPI v5 requires pmix) default is None
143+
144+
Returns:
145+
list[str]: The generated command list.
146+
"""
147+
command_prepend_lst = [SLURM_COMMAND, "-n", str(cores)]
148+
if cwd is not None:
149+
command_prepend_lst += ["-D", cwd]
150+
if pmi_mode is not None:
151+
command_prepend_lst += ["--mpi=" + pmi_mode]
152+
if num_nodes is not None:
153+
command_prepend_lst += ["-N", str(num_nodes)]
154+
if threads_per_core > 1:
155+
command_prepend_lst += ["--cpus-per-task=" + str(threads_per_core)]
156+
if gpus_per_core > 0:
157+
command_prepend_lst += ["--gpus-per-task=" + str(gpus_per_core)]
158+
if exclusive:
159+
command_prepend_lst += ["--exact"]
160+
if openmpi_oversubscribe:
161+
command_prepend_lst += ["--oversubscribe"]
162+
if slurm_cmd_args is not None and len(slurm_cmd_args) > 0:
163+
command_prepend_lst += slurm_cmd_args
164+
return command_prepend_lst

executorlib/standalone/slurm_command.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

executorlib/task_scheduler/file/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from executorlib.standalone.command import get_cache_execute_command
88
from executorlib.standalone.hdf import get_cache_files, get_output
99
from executorlib.standalone.serialize import serialize_funct
10-
from executorlib.task_scheduler.file.subprocess_spawner import terminate_subprocess
10+
from executorlib.task_scheduler.file.spawner_subprocess import terminate_subprocess
1111

1212

1313
class FutureItem:

executorlib/task_scheduler/file/task_scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
)
1212
from executorlib.task_scheduler.base import TaskSchedulerBase
1313
from executorlib.task_scheduler.file.shared import execute_tasks_h5
14-
from executorlib.task_scheduler.file.subprocess_spawner import (
14+
from executorlib.task_scheduler.file.spawner_subprocess import (
1515
execute_in_subprocess,
1616
terminate_subprocess,
1717
)
1818

1919
try:
2020
from executorlib.standalone.scheduler import terminate_with_pysqa
21-
from executorlib.task_scheduler.file.queue_spawner import execute_with_pysqa
21+
from executorlib.task_scheduler.file.spawner_pysqa import execute_with_pysqa
2222
except ImportError:
2323
# If pysqa is not available fall back to executing tasks in a subprocess
2424
execute_with_pysqa = execute_in_subprocess # type: ignore

0 commit comments

Comments
 (0)