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

pyiron / executorlib / 13116578816

03 Feb 2025 03:11PM UTC coverage: 96.536%. Remained the same
13116578816

Pull #555

github

web-flow
Merge 70bacefb9 into 5ec2a2015
Pull Request #555: Add linting

14 of 15 new or added lines in 7 files covered. (93.33%)

17 existing lines in 7 files now uncovered.

1059 of 1097 relevant lines covered (96.54%)

0.97 hits per line

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

98.59
/executorlib/standalone/inputcheck.py
1
import inspect
1✔
2
import multiprocessing
1✔
3
import os.path
1✔
4
from concurrent.futures import Executor
1✔
5
from typing import Callable, List, Optional
1✔
6

7

8
def check_oversubscribe(oversubscribe: bool) -> None:
1✔
9
    """
10
    Check if oversubscribe is True and raise a ValueError if it is.
11
    """
12
    if oversubscribe:
1✔
13
        raise ValueError(
1✔
14
            "Oversubscribing is not supported for the executorlib.flux.PyFLuxExecutor backend."
15
            "Please use oversubscribe=False instead of oversubscribe=True."
16
        )
17

18

19
def check_command_line_argument_lst(command_line_argument_lst: List[str]) -> None:
1✔
20
    """
21
    Check if command_line_argument_lst is not empty and raise a ValueError if it is.
22
    """
23
    if len(command_line_argument_lst) > 0:
1✔
24
        raise ValueError(
1✔
25
            "The command_line_argument_lst parameter is not supported for the SLURM backend."
26
        )
27

28

29
def check_gpus_per_worker(gpus_per_worker: int) -> None:
1✔
30
    """
31
    Check if gpus_per_worker is not 0 and raise a TypeError if it is.
32
    """
33
    if gpus_per_worker != 0:
1✔
34
        raise TypeError(
1✔
35
            "GPU assignment is not supported for the executorlib.mpi.PyMPIExecutor backend."
36
            "Please use gpus_per_worker=0 instead of gpus_per_worker="
37
            + str(gpus_per_worker)
38
            + "."
39
        )
40

41

42
def check_executor(executor: Executor) -> None:
1✔
43
    """
44
    Check if executor is not None and raise a ValueError if it is.
45
    """
46
    if executor is not None:
1✔
47
        raise ValueError(
1✔
48
            "The executor parameter is only supported for the flux framework backend."
49
        )
50

51

52
def check_nested_flux_executor(nested_flux_executor: bool) -> None:
1✔
53
    """
54
    Check if nested_flux_executor is True and raise a ValueError if it is.
55
    """
56
    if nested_flux_executor:
1✔
57
        raise ValueError(
1✔
58
            "The nested_flux_executor parameter is only supported for the flux framework backend."
59
        )
60

61

62
def check_resource_dict(function: Callable) -> None:
1✔
63
    """
64
    Check if the function has a parameter named 'resource_dict' and raise a ValueError if it does.
65
    """
66
    if "resource_dict" in inspect.signature(function).parameters.keys():
1✔
67
        raise ValueError(
1✔
68
            "The parameter resource_dict is used internally in executorlib, "
69
            "so it cannot be used as a parameter in the submitted functions."
70
        )
71

72

73
def check_resource_dict_is_empty(resource_dict: dict) -> None:
1✔
74
    """
75
    Check if resource_dict is not empty and raise a ValueError if it is.
76
    """
77
    if len(resource_dict) > 0:
1✔
78
        raise ValueError(
1✔
79
            "When block_allocation is enabled, the resource requirements have to be defined on the executor level."
80
        )
81

82

83
def check_refresh_rate(refresh_rate: float) -> None:
1✔
84
    """
85
    Check if refresh_rate is not 0.01 and raise a ValueError if it is.
86
    """
87
    if refresh_rate != 0.01:
1✔
88
        raise ValueError(
1✔
89
            "The sleep_interval parameter is only used when disable_dependencies=False."
90
        )
91

92

93
def check_plot_dependency_graph(plot_dependency_graph: bool) -> None:
1✔
94
    """
95
    Check if plot_dependency_graph is True and raise a ValueError if it is.
96
    """
97
    if plot_dependency_graph:
1✔
98
        raise ValueError(
1✔
99
            "The plot_dependency_graph parameter is only used when disable_dependencies=False."
100
        )
101

102

103
def check_pmi(backend: Optional[str], pmi: Optional[str]) -> None:
1✔
104
    """
105
    Check if pmi is valid for the selected backend and raise a ValueError if it is not.
106
    """
107
    if backend is not None:
1✔
108
        if backend != "flux_allocation" and pmi is not None:
1✔
109
            raise ValueError(
1✔
110
                "The pmi parameter is currently only implemented for flux."
111
            )
112
        elif backend == "flux_allocation" and pmi not in ["pmix", "pmi1", "pmi2", None]:
1✔
113
            raise ValueError(
1✔
114
                "The pmi parameter supports [pmix, pmi1, pmi2], but not: " + str(pmi)
115
            )
116

117

118
def check_init_function(
1✔
119
    block_allocation: bool, init_function: Optional[Callable]
120
) -> None:
121
    """
122
    Check if block_allocation is False and init_function is not None, and raise a ValueError if it is.
123
    """
124
    if not block_allocation and init_function is not None:
1✔
125
        raise ValueError("")
1✔
126

127

128
def check_max_workers_and_cores(
1✔
129
    max_workers: Optional[int], max_cores: Optional[int]
130
) -> None:
131
    if max_workers is not None:
1✔
132
        raise ValueError(
1✔
133
            "The number of workers cannot be controlled with the pysqa based backend."
134
        )
135
    if max_cores is not None:
1✔
136
        raise ValueError(
1✔
137
            "The number of cores cannot be controlled with the pysqa based backend."
138
        )
139

140

141
def check_hostname_localhost(hostname_localhost: Optional[bool]) -> None:
1✔
142
    if hostname_localhost is not None:
1✔
143
        raise ValueError(
1✔
144
            "The option to connect to hosts based on their hostname is not available with the pysqa based backend."
145
        )
146

147

148
def check_flux_executor_pmi_mode(flux_executor_pmi_mode: Optional[str]) -> None:
1✔
149
    if flux_executor_pmi_mode is not None:
1✔
150
        raise ValueError(
1✔
151
            "The option to specify the flux pmi mode is not available with the pysqa based backend."
152
        )
153

154

155
def check_flux_log_files(flux_log_files: Optional[bool]) -> None:
1✔
156
    """
157
    Check if flux_log_files is True and raise a ValueError if it is.
158
    """
159
    if flux_log_files:
1✔
160
        raise ValueError(
1✔
161
            "The flux_log_files parameter is only supported for the flux framework backend."
162
        )
163

164

165
def check_pysqa_config_directory(pysqa_config_directory: Optional[str]) -> None:
1✔
166
    """
167
    Check if pysqa_config_directory is None and raise a ValueError if it is not.
168
    """
169
    if pysqa_config_directory is not None:
1✔
170
        raise ValueError(
1✔
171
            "pysqa_config_directory parameter is only supported for pysqa backend."
172
        )
173

174

175
def validate_number_of_cores(
1✔
176
    max_cores: Optional[int] = None,
177
    max_workers: Optional[int] = None,
178
    cores_per_worker: Optional[int] = 1,
179
    set_local_cores: bool = False,
180
) -> int:
181
    """
182
    Validate the number of cores and return the appropriate value.
183
    """
184
    if max_cores is not None and max_workers is None and cores_per_worker is not None:
1✔
185
        return int(max_cores / cores_per_worker)
1✔
186
    elif max_workers is not None:
1✔
187
        return int(max_workers)
1✔
188
    elif max_cores is None and max_workers is None and not set_local_cores:
1✔
189
        raise ValueError(
1✔
190
            "Block allocation requires a fixed set of computational resources. Neither max_cores nor max_workers are defined."
191
        )
192
    else:
NEW
193
        return multiprocessing.cpu_count()
×
194

195

196
def check_file_exists(file_name: Optional[str]):
1✔
197
    if file_name is None:
1✔
198
        raise ValueError("file_name is not set.")
1✔
199
    if not os.path.exists(file_name):
1✔
200
        raise ValueError("file_name is not written to the file system.")
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

© 2025 Coveralls, Inc