resubmit 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- resubmit/__init__.py +7 -0
- resubmit/debug.py +26 -0
- resubmit/slurm.py +10 -0
- resubmit/submit.py +77 -0
- resubmit-0.0.2.dist-info/METADATA +36 -0
- resubmit-0.0.2.dist-info/RECORD +9 -0
- resubmit-0.0.2.dist-info/WHEEL +5 -0
- resubmit-0.0.2.dist-info/licenses/LICENSE +21 -0
- resubmit-0.0.2.dist-info/top_level.txt +1 -0
resubmit/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""resubmit: small helpers around submitit for reproducible cluster submissions."""
|
|
2
|
+
|
|
3
|
+
from .submit import submit_jobs
|
|
4
|
+
from .debug import maybe_attach_debugger
|
|
5
|
+
from .slurm import make_default_slurm_params
|
|
6
|
+
|
|
7
|
+
__all__ = ["submit_jobs", "maybe_attach_debugger", "make_default_slurm_params"]
|
resubmit/debug.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Debug helpers (attach remote debugger when running via Submitit)."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
def maybe_attach_debugger(port: Optional[int]) -> None:
|
|
7
|
+
"""Attach debugpy to the current job when `port` is provided (> 0).
|
|
8
|
+
|
|
9
|
+
Safe no-op if `port` is None or <= 0. Raises informative errors if debugpy is missing.
|
|
10
|
+
"""
|
|
11
|
+
if port is None or port <= 0:
|
|
12
|
+
return
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
import submitit
|
|
16
|
+
import debugpy
|
|
17
|
+
except Exception as exc: # pragma: no cover - environmental dependency
|
|
18
|
+
raise RuntimeError(
|
|
19
|
+
"debugging requires 'submitit' and 'debugpy' packages installed on the compute node"
|
|
20
|
+
) from exc
|
|
21
|
+
|
|
22
|
+
job_env = submitit.JobEnvironment()
|
|
23
|
+
print(f"Debugger is running on node {job_env.hostname} port {port}")
|
|
24
|
+
debugpy.listen((job_env.hostname, port))
|
|
25
|
+
print("Waiting for debugger attach")
|
|
26
|
+
debugpy.wait_for_client()
|
resubmit/slurm.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Small helpers for SLURM parameter construction."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
def make_default_slurm_params(gpus: int = 1, constraint: str = "thin", reservation: str = "safe", account: Optional[str] = None) -> dict:
|
|
7
|
+
params = {"constraint": constraint, "reservation": reservation, "gpus": gpus}
|
|
8
|
+
if account is not None:
|
|
9
|
+
params["account"] = account
|
|
10
|
+
return params
|
resubmit/submit.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Core submission utilities wrapping submitit."""
|
|
2
|
+
from typing import Any, Callable, Iterable, List, Optional, Dict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def submit_jobs(
|
|
6
|
+
jobs_args: Iterable[dict],
|
|
7
|
+
func: Callable[[List[dict]], Any],
|
|
8
|
+
*,
|
|
9
|
+
timeout_min: int,
|
|
10
|
+
cpus_per_task: int = 16,
|
|
11
|
+
mem_gb: int = 64,
|
|
12
|
+
num_gpus: int = 1,
|
|
13
|
+
account: Optional[str] = None,
|
|
14
|
+
folder: str = "logs/%j",
|
|
15
|
+
block: bool = False,
|
|
16
|
+
prompt: bool = True,
|
|
17
|
+
local_run: bool = False,
|
|
18
|
+
slurm_additional_parameters: Optional[Dict] = None,
|
|
19
|
+
):
|
|
20
|
+
"""Submit jobs described by `jobs_args` where each entry is a dict of kwargs for `func`.
|
|
21
|
+
|
|
22
|
+
- If `local_run` is True, the function is called directly: `func(jobs_args)`.
|
|
23
|
+
- Otherwise, submits via submitit.AutoExecutor and returns job objects or, if `block` is True, waits and returns results.
|
|
24
|
+
"""
|
|
25
|
+
jobs_list = list(jobs_args) if not isinstance(jobs_args, list) else jobs_args
|
|
26
|
+
|
|
27
|
+
if len(jobs_list) == 0:
|
|
28
|
+
print("No jobs to run exiting")
|
|
29
|
+
return
|
|
30
|
+
|
|
31
|
+
if local_run:
|
|
32
|
+
print("Running locally (local_run=True)")
|
|
33
|
+
return func(jobs_list)
|
|
34
|
+
|
|
35
|
+
if prompt:
|
|
36
|
+
print("Do you want to continue? [y/n]", flush=True)
|
|
37
|
+
if input() != "y":
|
|
38
|
+
print("Aborted")
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
import submitit
|
|
42
|
+
print("submitting jobs")
|
|
43
|
+
executor = submitit.AutoExecutor(folder=folder)
|
|
44
|
+
|
|
45
|
+
# default slurm params
|
|
46
|
+
if slurm_additional_parameters is None:
|
|
47
|
+
slurm_additional_parameters = {
|
|
48
|
+
"constraint": "thin",
|
|
49
|
+
"reservation": "safe",
|
|
50
|
+
"gpus": num_gpus,
|
|
51
|
+
}
|
|
52
|
+
else:
|
|
53
|
+
slurm_additional_parameters = dict(slurm_additional_parameters)
|
|
54
|
+
slurm_additional_parameters.setdefault("gpus", num_gpus)
|
|
55
|
+
|
|
56
|
+
if account is not None:
|
|
57
|
+
slurm_additional_parameters["account"] = account
|
|
58
|
+
|
|
59
|
+
print("Slurm additional parameters:", slurm_additional_parameters)
|
|
60
|
+
|
|
61
|
+
executor.update_parameters(
|
|
62
|
+
timeout_min=timeout_min,
|
|
63
|
+
cpus_per_task=cpus_per_task,
|
|
64
|
+
mem_gb=mem_gb,
|
|
65
|
+
slurm_additional_parameters=slurm_additional_parameters,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
jobs = executor.map_array(func, jobs_list)
|
|
69
|
+
print("Job submitted")
|
|
70
|
+
|
|
71
|
+
if block:
|
|
72
|
+
print("Waiting for job to finish")
|
|
73
|
+
results = [job.result() for job in jobs]
|
|
74
|
+
print("All jobs finished")
|
|
75
|
+
return results
|
|
76
|
+
|
|
77
|
+
return jobs
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: resubmit
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Small wrapper around submitit to simplify cluster submissions
|
|
5
|
+
Author: Amir Mehrpanah
|
|
6
|
+
License: MIT
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: submitit>=0.8
|
|
10
|
+
Provides-Extra: debug
|
|
11
|
+
Requires-Dist: debugpy; extra == "debug"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# resubmit
|
|
15
|
+
|
|
16
|
+
Small utility library to simplify job submission with Submitit on SLURM clusters.
|
|
17
|
+
|
|
18
|
+
Quick usage:
|
|
19
|
+
|
|
20
|
+
- Install locally for development:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install -e .[debug]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- Use in your project:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from resubmit import submit_jobs, maybe_attach_debugger
|
|
30
|
+
|
|
31
|
+
# attach remote debugger if requested
|
|
32
|
+
maybe_attach_debugger(args.get("port", None))
|
|
33
|
+
|
|
34
|
+
# submit jobs (list of dicts)
|
|
35
|
+
submit_jobs(jobs_list, my_entrypoint, timeout_min=60, block=True)
|
|
36
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
resubmit/__init__.py,sha256=nuOlPF_zmRDxn_bmCE_rseLYL-DNC8f4UC6vHicEcig,284
|
|
2
|
+
resubmit/debug.py,sha256=8RINyz7eSAiT47d018wR0R3B_u4PllQJCiLy0zTSQDE,887
|
|
3
|
+
resubmit/slurm.py,sha256=-mez8sQh0ADTL8xL3cV2ureGn1uvNaR-Uuu7K_qePAY,387
|
|
4
|
+
resubmit/submit.py,sha256=KBN4RDCjmn5Gg7wDogbtytEbTT66xMteTXGpHpHEYFo,2319
|
|
5
|
+
resubmit-0.0.2.dist-info/licenses/LICENSE,sha256=v2spsd7N1pKFFh2G8wGP_45iwe5S0DYiJzG4im8Rupc,1066
|
|
6
|
+
resubmit-0.0.2.dist-info/METADATA,sha256=V2YBAdAukURde6IKVC6TDUIsNMoV679OyUlGfvbC0iE,794
|
|
7
|
+
resubmit-0.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
8
|
+
resubmit-0.0.2.dist-info/top_level.txt,sha256=BfCexfX-VhUZuNi8sI88i0HF_e3ppausQ76hxPeXjYc,9
|
|
9
|
+
resubmit-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Your Name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
resubmit
|