• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pyiron / executorlib / 12425281064

20 Dec 2024 04:00AM UTC coverage: 94.253% (-1.5%) from 95.78%
12425281064

Pull #528

github

web-flow
Merge 0b9ee350a into 44214f755
Pull Request #528: Move SLURM to separate module

26 of 27 new or added lines in 3 files covered. (96.3%)

16 existing lines in 1 file now uncovered.

984 of 1044 relevant lines covered (94.25%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/executorlib/interactive/slurm.py
1
from typing import Optional
1✔
2
from executorlib.standalone.interactive.spawner import SubprocessSpawner
1✔
3

4
SLURM_COMMAND = "srun"
1✔
5

6

7
class SrunSpawner(SubprocessSpawner):
1✔
8
    def __init__(
1✔
9
        self,
10
        cwd: Optional[str] = None,
11
        cores: int = 1,
12
        threads_per_core: int = 1,
13
        gpus_per_core: int = 0,
14
        openmpi_oversubscribe: bool = False,
15
        slurm_cmd_args: list[str] = [],
16
    ):
17
        """
18
        Srun interface implementation.
19

20
        Args:
21
            cwd (str, optional): The current working directory. Defaults to None.
22
            cores (int, optional): The number of cores to use. Defaults to 1.
23
            threads_per_core (int, optional): The number of threads per core. Defaults to 1.
24
            gpus_per_core (int, optional): The number of GPUs per core. Defaults to 0.
25
            openmpi_oversubscribe (bool, optional): Whether to oversubscribe the cores. Defaults to False.
26
            slurm_cmd_args (list[str], optional): Additional command line arguments. Defaults to [].
27
        """
28
        super().__init__(
1✔
29
            cwd=cwd,
30
            cores=cores,
31
            openmpi_oversubscribe=openmpi_oversubscribe,
32
            threads_per_core=threads_per_core,
33
        )
34
        self._gpus_per_core = gpus_per_core
1✔
35
        self._slurm_cmd_args = slurm_cmd_args
1✔
36

37
    def generate_command(self, command_lst: list[str]) -> list[str]:
1✔
38
        """
39
        Generate the command list for the Srun interface.
40

41
        Args:
42
            command_lst (list[str]): The command list.
43

44
        Returns:
45
            list[str]: The generated command list.
46
        """
47
        command_prepend_lst = generate_slurm_command(
1✔
48
            cores=self._cores,
49
            cwd=self._cwd,
50
            threads_per_core=self._threads_per_core,
51
            gpus_per_core=self._gpus_per_core,
52
            openmpi_oversubscribe=self._openmpi_oversubscribe,
53
            slurm_cmd_args=self._slurm_cmd_args,
54
        )
55
        return super().generate_command(
1✔
56
            command_lst=command_prepend_lst + command_lst,
57
        )
58

59

60
def generate_slurm_command(
1✔
61
    cores: int,
62
    cwd: str,
63
    threads_per_core: int = 1,
64
    gpus_per_core: int = 0,
65
    openmpi_oversubscribe: bool = False,
66
    slurm_cmd_args: list[str] = [],
67
) -> list[str]:
68
    """
69
    Generate the command list for the SLURM interface.
70

71
    Args:
72
        cores (int): The number of cores.
73
        cwd (str): The current working directory.
74
        threads_per_core (int, optional): The number of threads per core. Defaults to 1.
75
        gpus_per_core (int, optional): The number of GPUs per core. Defaults to 0.
76
        openmpi_oversubscribe (bool, optional): Whether to oversubscribe the cores. Defaults to False.
77
        slurm_cmd_args (list[str], optional): Additional command line arguments. Defaults to [].
78

79
    Returns:
80
        list[str]: The generated command list.
81
    """
82
    command_prepend_lst = [SLURM_COMMAND, "-n", str(cores)]
1✔
83
    if cwd is not None:
1✔
84
        command_prepend_lst += ["-D", cwd]
1✔
85
    if threads_per_core > 1:
1✔
NEW
86
        command_prepend_lst += ["--cpus-per-task" + str(threads_per_core)]
×
87
    if gpus_per_core > 0:
1✔
88
        command_prepend_lst += ["--gpus-per-task=" + str(gpus_per_core)]
1✔
89
    if openmpi_oversubscribe:
1✔
90
        command_prepend_lst += ["--oversubscribe"]
1✔
91
    if len(slurm_cmd_args) > 0:
1✔
92
        command_prepend_lst += slurm_cmd_args
1✔
93
    return command_prepend_lst
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc