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

pyiron / executorlib / 12425282605

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

Pull #528

github

web-flow
Merge 79b588cac 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

3
from executorlib.standalone.interactive.spawner import SubprocessSpawner
1✔
4

5
SLURM_COMMAND = "srun"
1✔
6

7

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

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

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

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

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

60

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

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

80
    Returns:
81
        list[str]: The generated command list.
82
    """
83
    command_prepend_lst = [SLURM_COMMAND, "-n", str(cores)]
1✔
84
    if cwd is not None:
1✔
85
        command_prepend_lst += ["-D", cwd]
1✔
86
    if threads_per_core > 1:
1✔
NEW
87
        command_prepend_lst += ["--cpus-per-task" + str(threads_per_core)]
×
88
    if gpus_per_core > 0:
1✔
89
        command_prepend_lst += ["--gpus-per-task=" + str(gpus_per_core)]
1✔
90
    if openmpi_oversubscribe:
1✔
91
        command_prepend_lst += ["--oversubscribe"]
1✔
92
    if len(slurm_cmd_args) > 0:
1✔
93
        command_prepend_lst += slurm_cmd_args
1✔
94
    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