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

pyiron / executorlib / 11576479865

29 Oct 2024 02:52PM UTC coverage: 94.618% (-0.6%) from 95.228%
11576479865

Pull #465

github

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

3 of 9 new or added lines in 1 file covered. (33.33%)

1 existing line in 1 file now uncovered.

879 of 929 relevant lines covered (94.62%)

0.95 hits per line

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

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

4
from pysqa import QueueAdapter
1✔
5

6

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

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

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

55

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

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

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