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

pyiron / executorlib / 11576835345

29 Oct 2024 03:10PM UTC coverage: 95.054% (-0.2%) from 95.228%
11576835345

Pull #465

github

web-flow
Merge 426f974c8 into b41acbaad
Pull Request #465: Add pysqa command which raises an exception

8 of 10 new or added lines in 1 file covered. (80.0%)

884 of 930 relevant lines covered (95.05%)

0.95 hits per line

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

86.96
/executorlib/standalone/cache/queue.py
1
import os
1✔
2
import subprocess
1✔
3
from typing import List, Optional, Union
1✔
4

5
from pysqa import QueueAdapter
1✔
6

7

8
def execute_with_pysqa(
1✔
9
    command: str,
10
    resource_dict: dict,
11
    task_dependent_lst: List[int] = [],
12
    config_directory: Optional[str] = None,
13
    backend: Optional[str] = None,
14
) -> int:
15
    """
16
    Execute a command by submitting it to the queuing system
17

18
    Args:
19
        command (list): The command to be executed.
20
        task_dependent_lst (list): A list of subprocesses that the current subprocess depends on. Defaults to [].
21
        resource_dict (dict): resource dictionary, which defines the resources used for the execution of the function.
22
                              Example resource dictionary: {
23
                                  cwd: None,
24
                              }
25
        config_directory (str, optional): path to the config directory.
26
        backend (str, optional): name of the backend used to spawn tasks.
27

28
    Returns:
29
        int: queuing system ID
30
    """
31
    if resource_dict is None:
1✔
32
        resource_dict = {"cwd": "."}
×
33
    qa = QueueAdapter(
1✔
34
        directory=config_directory,
35
        queue_type=backend,
36
        execute_command=_pysqa_execute_command,
37
    )
38
    submit_kwargs = {
1✔
39
        "command": " ".join(command),
40
        "dependency_list": [str(qid) for qid in task_dependent_lst],
41
        "working_directory": os.path.abspath(resource_dict["cwd"]),
42
    }
43
    del resource_dict["cwd"]
1✔
44
    unsupported_keys = [
1✔
45
        "threads_per_core",
46
        "gpus_per_core",
47
        "openmpi_oversubscribe",
48
        "slurm_cmd_args",
49
    ]
50
    for k in unsupported_keys:
1✔
51
        if k in resource_dict:
1✔
52
            del resource_dict[k]
1✔
53
    submit_kwargs.update(resource_dict)
1✔
54
    return qa.submit_job(**submit_kwargs)
1✔
55

56

57
def _pysqa_execute_command(
1✔
58
    commands: str,
59
    working_directory: Optional[str] = None,
60
    split_output: bool = True,
61
    shell: bool = False,
62
    error_filename: str = "pysqa.err",
63
) -> Union[str, List[str]]:
64
    """
65
    A wrapper around the subprocess.check_output function. Modified from pysqa to raise an exception if the subprocess
66
    fails to submit the job to the queue.
67

68
    Args:
69
        commands (str): The command(s) to be executed on the command line
70
        working_directory (str, optional): The directory where the command is executed. Defaults to None.
71
        split_output (bool, optional): Boolean flag to split newlines in the output. Defaults to True.
72
        shell (bool, optional): Additional switch to convert commands to a single string. Defaults to False.
73
        error_filename (str, optional): In case the execution fails, the output is written to this file. Defaults to "pysqa.err".
74

75
    Returns:
76
        Union[str, List[str]]: Output of the shell command either as a string or as a list of strings
77
    """
78
    if shell and isinstance(commands, list):
1✔
NEW
79
        commands = " ".join(commands)
×
80
    out = subprocess.check_output(
1✔
81
        commands,
82
        cwd=working_directory,
83
        stderr=subprocess.STDOUT,
84
        universal_newlines=True,
85
        shell=not isinstance(commands, list),
86
    )
87
    if out is not None and split_output:
1✔
88
        return out.split("\n")
1✔
89
    else:
NEW
90
        return out
×
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

© 2025 Coveralls, Inc