euler-slurm 0.4.0__tar.gz

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.
Files changed (53) hide show
  1. euler_slurm-0.4.0/.gitignore +8 -0
  2. euler_slurm-0.4.0/CHANGELOG.md +97 -0
  3. euler_slurm-0.4.0/LICENSE +21 -0
  4. euler_slurm-0.4.0/PKG-INFO +293 -0
  5. euler_slurm-0.4.0/README.md +257 -0
  6. euler_slurm-0.4.0/euler_slurm/__init__.py +80 -0
  7. euler_slurm-0.4.0/euler_slurm/__main__.py +7 -0
  8. euler_slurm-0.4.0/euler_slurm/_parse.py +634 -0
  9. euler_slurm-0.4.0/euler_slurm/cli.py +463 -0
  10. euler_slurm-0.4.0/euler_slurm/diagnose.py +773 -0
  11. euler_slurm-0.4.0/euler_slurm/explain.py +1393 -0
  12. euler_slurm-0.4.0/euler_slurm/jobs.py +1120 -0
  13. euler_slurm-0.4.0/euler_slurm/py.typed +0 -0
  14. euler_slurm-0.4.0/euler_slurm/report.py +448 -0
  15. euler_slurm-0.4.0/euler_slurm/runner.py +162 -0
  16. euler_slurm-0.4.0/pyproject.toml +89 -0
  17. euler_slurm-0.4.0/tests/__init__.py +0 -0
  18. euler_slurm-0.4.0/tests/conftest.py +122 -0
  19. euler_slurm-0.4.0/tests/fixtures/logs/cancelled.log +2 -0
  20. euler_slurm-0.4.0/tests/fixtures/logs/clean.log +1 -0
  21. euler_slurm-0.4.0/tests/fixtures/logs/cuda_oom.log +8 -0
  22. euler_slurm-0.4.0/tests/fixtures/logs/cuda_oom_tqdm.log +9 -0
  23. euler_slurm-0.4.0/tests/fixtures/logs/disk_quota.log +5 -0
  24. euler_slurm-0.4.0/tests/fixtures/logs/host_oom.log +3 -0
  25. euler_slurm-0.4.0/tests/fixtures/logs/import_error.log +6 -0
  26. euler_slurm-0.4.0/tests/fixtures/logs/killed.log +2 -0
  27. euler_slurm-0.4.0/tests/fixtures/logs/nccl_timeout.log +4 -0
  28. euler_slurm-0.4.0/tests/fixtures/logs/node_failure.log +3 -0
  29. euler_slurm-0.4.0/tests/fixtures/logs/preempted.log +2 -0
  30. euler_slurm-0.4.0/tests/fixtures/logs/python_error.log +7 -0
  31. euler_slurm-0.4.0/tests/fixtures/logs/time_limit.log +2 -0
  32. euler_slurm-0.4.0/tests/fixtures/sacct_parsable2.txt +12 -0
  33. euler_slurm-0.4.0/tests/fixtures/sacct_v0040.json +1625 -0
  34. euler_slurm-0.4.0/tests/fixtures/scontrol_array.txt +2 -0
  35. euler_slurm-0.4.0/tests/fixtures/scontrol_failed.txt +1 -0
  36. euler_slurm-0.4.0/tests/fixtures/scontrol_multiline.txt +25 -0
  37. euler_slurm-0.4.0/tests/fixtures/scontrol_pending.txt +1 -0
  38. euler_slurm-0.4.0/tests/fixtures/scontrol_running.txt +1 -0
  39. euler_slurm-0.4.0/tests/fixtures/scontrol_v0040.json +145 -0
  40. euler_slurm-0.4.0/tests/fixtures/sinfo_partitions.txt +7 -0
  41. euler_slurm-0.4.0/tests/fixtures/sinfo_version.txt +1 -0
  42. euler_slurm-0.4.0/tests/fixtures/squeue_format.txt +8 -0
  43. euler_slurm-0.4.0/tests/fixtures/squeue_help.txt +10 -0
  44. euler_slurm-0.4.0/tests/fixtures/squeue_tres.txt +8 -0
  45. euler_slurm-0.4.0/tests/fixtures/squeue_v0037.json +106 -0
  46. euler_slurm-0.4.0/tests/fixtures/squeue_v0040.json +1054 -0
  47. euler_slurm-0.4.0/tests/test_cli.py +268 -0
  48. euler_slurm-0.4.0/tests/test_diagnose.py +485 -0
  49. euler_slurm-0.4.0/tests/test_explain.py +488 -0
  50. euler_slurm-0.4.0/tests/test_jobs.py +534 -0
  51. euler_slurm-0.4.0/tests/test_parse.py +253 -0
  52. euler_slurm-0.4.0/tests/test_report.py +278 -0
  53. euler_slurm-0.4.0/tests/test_runner.py +115 -0
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ .coverage
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .venv/
7
+ build/
8
+ dist/
@@ -0,0 +1,97 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ Explanations as data for tools, and a verdict on every diagnosis. All JSON
6
+ changes are additive (minor versions).
7
+
8
+ - **Categories.** Every explanation has a `category` from a closed set per
9
+ kind, exported as `REASON_CATEGORIES`, `STATE_CATEGORIES` and
10
+ `EXIT_CATEGORIES` (code → a few plain words). Pending reasons: `queue`,
11
+ `dependency`, `schedule`, `hold`, `limit` (clears by itself), `request`
12
+ (never starts as it is), `budget`, `nodes`, `startup`, `requeued`, `other`.
13
+ States: `waiting`, `held`, `running`, `paused`, `succeeded`, `failed`,
14
+ `interrupted`, `cancelled`. Exit codes: `success`, `error`, `environment`,
15
+ `signal`, `memory` (SLURM's `0:125`). Unknown codes are `unknown`, other
16
+ 128 + n exits `signal`, other exit codes `error`. `Explanation.to_dict()`
17
+ carries `category`.
18
+ - **The catalog.** `catalog()` (exported from the package) returns every
19
+ explanation as JSON-ready data: `pending_reasons` (sorted by code, with
20
+ `blocked`), `states` (with the squeue short code, `terminal`, `pending`),
21
+ `exit_codes` (`"0"` … `"255"`, then `"0:125"`), `signals` and `categories`.
22
+ Texts keep the `<job_id>` placeholder.
23
+ - `slurm_capability_report` **1.1** carries the `catalog`, also when SLURM is
24
+ not available here.
25
+ - New envelope `slurm_explanations` **1.0**: `euler-slurm explain --all --json`
26
+ prints the catalog, `euler-slurm explain CODE... --json` the explanation of
27
+ the code (`explanations: [...]`). `euler-slurm explain --all` lists every code
28
+ with its label, by kind. The capability report's `commands` name the
29
+ envelope.
30
+ - `euler-slurm diagnose JOB_ID --log PATH` (repeatable; Python:
31
+ `diagnose(..., logs=[...])`, `diagnose_job(job, lines, logs)`): further log
32
+ files, read and scanned like the job's stdout/stderr (stream `log`); a file
33
+ named twice is read once.
34
+ - **Logs-only diagnosis.** When SLURM no longer knows the job (aged out of
35
+ `scontrol`, no accounting record) and `--log` files are given, `diagnose`
36
+ reads only them (`diagnose_logs(job_id, logs, lines)`) instead of failing:
37
+ `job` is `null` and the first finding is `job.not_found`. Without `--log` it
38
+ stays the `job_not_found` error.
39
+ - **The verdict.** `slurm_diagnosis` **1.1** adds `verdict: {summary, cause,
40
+ fix, code, severity, evidence}` (`Diagnosis.verdict`, a `Verdict`), the one
41
+ thing to tell a newcomer: the job in a few words (its explanation's label, or
42
+ "No SLURM record"), and the cause and fix of the most specific finding: the
43
+ first log finding of severity error, then warning, in the order of the log
44
+ rules (a bare Python exception after the specific ones), else the state or
45
+ pending reason. When SLURM itself ended the job (TIMEOUT, PREEMPTED,
46
+ NODE_FAIL, BOOT_FAIL, DEADLINE, CANCELLED, OUT_OF_MEMORY), a Python exception
47
+ or `Killed` line does not count: the state is the cause. `euler-slurm
48
+ diagnose` prints the verdict first (Summary, Cause, Fix), then the other
49
+ findings.
50
+ - Log rules now also yield across files (a `Killed` line in stdout gives way
51
+ to the oom-kill in stderr), and named logs are not checked for SLURM's `%`
52
+ path patterns.
53
+
54
+ ## 0.1.0
55
+
56
+ First release: SLURM's `squeue`/`sacct`/`scontrol`/`sinfo` as one typed,
57
+ versioned JSON CLI, with plain-language explanations (roadmap item SL1 of the
58
+ Euler suite's north star).
59
+
60
+ - `euler_slurm.runner`: one injectable `Runner` protocol
61
+ (`run(args, timeout) -> (rc, stdout, stderr)`) and `SubprocessRunner` (no
62
+ shell). A missing command is a typed `SlurmUnavailable`; a slow one
63
+ `SlurmTimeout`. Commands run with `SLURM_TIME_FORMAT=standard` and without
64
+ `SQUEUE_*`/`SACCT_*`/`SINFO_*`/`SCONTROL_*` variables, so personal settings
65
+ cannot change the output format.
66
+ - `euler_slurm.jobs`: `list_jobs(user=None, job_ids=None)` (active jobs from
67
+ squeue, recently ended ones from sacct, with `sources` and `problems`) and
68
+ `get_job(job_id)` (scontrol while SLURM remembers the job, then sacct),
69
+ returning `Job` dataclasses. `--json` is tried first (Slurm 21.08+; data_parser
70
+ v0.0.37 to v0.0.41 number forms), with a fallback to `--format` / `--parsable2` /
71
+ `--oneliner` text. Both paths give the same record, and the tests check that.
72
+ Handles short and long states, JSON state flags, `CANCELLED by <uid>`, `+`
73
+ suffixes, array ids (`123_4`, `123_[1-3%2]`), heterogeneous ids, `UNLIMITED`,
74
+ `D-HH:MM:SS`, `ExitCode=a:b` and the JSON exit forms, GPUs from TRES/GRES (whole
75
+ job), output path patterns (`%A_%a`, `%x-%j`), and names containing the
76
+ delimiter. Filters are applied again to JSON (Slurm before 23.02 ignored them).
77
+ - `euler_slurm.explain`: plain-language meaning and fix for 86 pending
78
+ reasons, every job state and the common exit codes (incl. 137/139/143 and
79
+ SLURM's `0:125` out-of-memory marker). Unknown codes get an honest generic
80
+ explanation (`known: false`), never a guess.
81
+ - `euler_slurm.diagnose`: `diagnose(job_id, log_tail_lines=200)` combines the
82
+ job record with the end of its stdout/stderr into findings
83
+ `{code, severity, subject, message, hint, evidence}` (the `euler-suite`
84
+ finding shape). Covers CUDA out of memory, host OOM, NCCL/distributed
85
+ timeouts, `ModuleNotFoundError`/`ImportError` (hint: `euler-suite doctor` in
86
+ the job's environment), disk quota / no space, time limit, preemption, node
87
+ failure, cancellation, bare `Killed`, the last Python exception, and jobs near
88
+ their time limit. Reads tqdm `\r` lines and huge logs safely.
89
+ - `euler_slurm.report`: envelopes `slurm_jobs`, `slurm_job`, `slurm_diagnosis`
90
+ and `slurm_capability_report` (all 1.0) with `contract: {kind, version}` and
91
+ `package`; errors as the same kind with `error: {code, message}`.
92
+ `capability_report()` (never raises) is registered as the `euler-slurm`
93
+ entry of `euler.capabilities`: availability and reason, SLURM version,
94
+ `--json` support, partitions with time limits and GPUs from `sinfo`, the
95
+ commands, envelopes and explained codes.
96
+ - CLI `euler-slurm jobs|job|diagnose|explain|capabilities` (`--json` on the first
97
+ three), also `python -m euler_slurm`.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Rothenpieler <rothenpielerdaniel@gmail.com>
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,293 @@
1
+ Metadata-Version: 2.5
2
+ Name: euler-slurm
3
+ Version: 0.4.0
4
+ Summary: SLURM jobs as typed, versioned JSON, with plain-language explanations of pending reasons, states and failures
5
+ Project-URL: Homepage, https://github.com/d-rothen/euler-slurm
6
+ Project-URL: Repository, https://github.com/d-rothen/euler-slurm
7
+ Project-URL: Issues, https://github.com/d-rothen/euler-slurm/issues
8
+ Project-URL: Documentation, https://github.com/d-rothen/euler-slurm#readme
9
+ Project-URL: Changelog, https://github.com/d-rothen/euler-slurm/blob/main/CHANGELOG.md
10
+ Author-email: Daniel Rothenpieler <rothenpielerdaniel@gmail.com>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: euler-view,hpc,machine-learning,sacct,slurm,squeue
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Environment :: Console
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Science/Research
18
+ Classifier: Operating System :: POSIX
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: 3.14
26
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
27
+ Classifier: Topic :: System :: Distributed Computing
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.9
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.4; extra == 'dev'
32
+ Requires-Dist: ruff>=0.12; extra == 'dev'
33
+ Provides-Extra: testing
34
+ Requires-Dist: pytest>=7.4; extra == 'testing'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # euler-slurm
38
+
39
+ SLURM jobs as typed, versioned JSON, and SLURM explained in plain words.
40
+
41
+ `squeue`, `sacct` and `scontrol` print terse codes (`PD`, `QOSMaxGRESPerUser`,
42
+ `ExitCode=0:9`) in formats that change between SLURM versions. euler-slurm reads
43
+ them on the cluster (JSON where SLURM offers it, text otherwise) and gives you:
44
+
45
+ - **one typed job record** (`Job`) whatever the SLURM version;
46
+ - **plain-language explanations with a fix** for every pending reason, job
47
+ state and exit code it knows, and an honest "I don't know this one" for the
48
+ rest;
49
+ - **a diagnosis** of a failed job from its record *and* the end of its logs
50
+ (CUDA out of memory, NCCL timeouts, missing packages, full disks, time limits…),
51
+ led by one verdict: summary, cause, fix;
52
+ - **versioned JSON envelopes** (`--json`) for tools such as euler-view.
53
+
54
+ Part of the Euler suite. Zero runtime dependencies, Python 3.9+.
55
+
56
+ ```sh
57
+ pip install euler-slurm
58
+ ```
59
+
60
+ ## Commands
61
+
62
+ ```console
63
+ $ euler-slurm jobs
64
+ JOB ID NAME STATE TIME/LIMIT GPUS WHERE / WHY
65
+ 91000003 ev-rtx-1120-1430 RUNNING 1:19:50/4:00:00 1x rtx_4090 eu-g6-023
66
+ 91000009 metric_train-1120-1243 PENDING 0:00/2-00:00:00 1 GPU Waiting for its turn (Priority)
67
+ 91000020_[2-4%2] sweep PENDING 0:00/4:00:00 1 GPU Array runs its maximum at once (JobArrayTaskLimit)
68
+ 91000014 multinode PENDING 0:00/1-00:00:00 8x rtx_4090 Nodes it needs are unavailable (ReqNodeNotAvail, UnavailableNodes:eu-g1-[001-004])
69
+ 91000015 held-eval PENDING 0:00/4:00:00 1 GPU Held by you (JobHeldUser)
70
+ 90999002 big-data OUT_OF_MEMORY 10:00/4:00:00 1x rtx_4090 Ran out of memory
71
+ 90999001 train FAILED 42:00/4:00:00 1x rtx_4090 Failed (exit code 1)
72
+
73
+ $ euler-slurm explain QOSMaxGRESPerUser
74
+ QOSMaxGRESPerUser: At your GPU limit (pending reason)
75
+ Meaning: Your running jobs already use as many GPUs as your QOS allows per user (or
76
+ per account). It starts by itself when some of your GPUs are released.
77
+ What to do: Wait, or cancel or shrink other GPU jobs of yours. `sacctmgr show qos
78
+ format=Name,MaxTRESPerUser%40,MaxTRESPerAccount%40` shows the limit.
79
+
80
+ $ euler-slurm diagnose 90999001
81
+ Job 90999001 (train) - FAILED, exit code 1
82
+
83
+ Summary: Failed (exit code 1)
84
+ Cause: Python could not import `euler_loading`: the job's environment is missing
85
+ it, or has a version that does not fit.
86
+ Fix: Run `euler-suite doctor` in the job's environment (the same `module load`
87
+ / `conda activate` / `source .venv/bin/activate` lines the job script
88
+ runs) to see which packages are missing or disagree, then install them
89
+ there.
90
+ Log line: ModuleNotFoundError: No module named 'euler_loading'
91
+ In: /cluster/home/alice/proj/train-90999001.err
92
+
93
+ Also found:
94
+
95
+ [error] Failed (exit code 1): Its batch script exited with a non-zero exit code.
96
+ Exit code 1: The program reported an error and exited with 1. For Python
97
+ this usually means an exception that nothing caught.
98
+ Fix: The last traceback near the end of the error log names it (`euler-slurm
99
+ diagnose 90999001`).
100
+ ```
101
+
102
+ | Command | What it does | `--json` envelope |
103
+ |---|---|---|
104
+ | `euler-slurm jobs [--user U] [--since-hours N] [--active]` | your active jobs (squeue) and the ones that ended in the last N hours (sacct) | `slurm_jobs` 1.0 |
105
+ | `euler-slurm job <id>` | one job in detail: state or pending reason explained, resources, times, log paths | `slurm_job` 1.0 |
106
+ | `euler-slurm diagnose <id> [--log PATH]... [--lines N]` | why it failed or waits: the verdict (summary, cause, fix), then every finding from the record and the end of its stdout/stderr and of each `--log` file. When SLURM no longer knows the job, `--log` files alone are enough | `slurm_diagnosis` 1.1 |
107
+ | `euler-slurm explain <REASON\|STATE\|EXIT_CODE>` | `Priority`, `PD`, `TIMEOUT`, `137`, `0:9`, `launch failed requeued held` … | `slurm_explanations` 1.0 (`explanations`) |
108
+ | `euler-slurm explain --all` | every code it can explain, by kind (`--json`: the whole catalog) | `slurm_explanations` 1.0 (`catalog`) |
109
+ | `euler-slurm capabilities` | what SLURM offers here: version, `--json` support, partitions with time limits and GPUs | `slurm_capability_report` 1.1 (always JSON) |
110
+
111
+ Job ids are `123`, `123_4` (an array task), `123_[1-3]` (array tasks still
112
+ pending) or `123+1` (a heterogeneous job component). Exit status: 0 success,
113
+ 1 the command failed (unknown job, SLURM error), 2 wrong usage, 3 SLURM is not
114
+ installed here. Global options: `--no-slurm-json` (read SLURM's text output
115
+ only) and `--timeout SECONDS`.
116
+
117
+ ## What does my pending reason mean?
118
+
119
+ `squeue` shows why a job has not started in its `NODELIST(REASON)` column. The
120
+ common ones, in short (`euler-slurm explain <reason>` gives the full text and
121
+ the fix for your job):
122
+
123
+ | Reason | What it means | What to do |
124
+ |---|---|---|
125
+ | `Priority` | Other jobs are ahead of yours in the queue. Normal. | Wait. `squeue --start -j <id>` shows SLURM's estimate. Smaller jobs (fewer GPUs, shorter `--time`) start sooner. |
126
+ | `Resources` | Yours is next, but the GPUs/CPUs/memory it asks for are busy. Normal. | Wait, or ask for less / another GPU type (`sinfo -o '%P %G %D %T'`). |
127
+ | `Dependency` | It waits for the job named in `--dependency`. | Nothing to do. |
128
+ | `DependencyNeverSatisfied` | The job it waited for failed, so this one **never** starts. | `scancel <id>`, fix the first job, resubmit. |
129
+ | `BeginTime` | It was submitted with `--begin` in the future. | Wait, or `scontrol update JobId=<id> StartTime=now`. |
130
+ | `JobHeldUser` | It is on hold (`scontrol hold` / `sbatch --hold`). | `scontrol release <id>`. |
131
+ | `JobHeldAdmin` | An administrator put it on hold. | Ask cluster support. |
132
+ | `QOSMaxJobsPerUserLimit` | You already run as many jobs as your QOS allows. | Wait for one to end, or cancel one. |
133
+ | `AssocMaxJobsLimit` | Same, a limit of your account (association). | Wait, or cancel a job. |
134
+ | `QOSMaxGRESPerUser` | Your jobs already use your GPU limit. | Wait, or shrink/cancel other GPU jobs. |
135
+ | `AssocGrpGRES` | Your **group** uses all its GPUs (colleagues' jobs count too). | Wait; fewer GPUs per job start sooner. |
136
+ | `ReqNodeNotAvail` | A node it needs is down, drained or reserved (often maintenance). | Drop `--nodelist`; before a maintenance, a shorter `--time` lets it start now. |
137
+ | `PartitionTimeLimit` | `--time` is longer than the partition allows: it **never** starts. | `scontrol update JobId=<id> TimeLimit=HH:MM:SS`, or another partition. |
138
+ | `PartitionNodeLimit` | More (or fewer) nodes than the partition allows. | Resubmit with a fitting `--nodes`. |
139
+ | `InvalidAccount` | Submitted under an account you may not use: **never** starts. | Resubmit with `--account=…` (`sacctmgr show assoc user=$USER`). |
140
+ | `InvalidQOS` | Submitted with a QOS you may not use: **never** starts. | Resubmit with `--qos=…`. |
141
+ | `launch failed requeued held` | SLURM could not start it on the node and held it. | Check the work dir and output paths exist, then `scontrol release <id>`. |
142
+ | `JobArrayTaskLimit` | The array already runs its maximum number of tasks at once. | Nothing to do. |
143
+
144
+ euler-slurm knows 86 reason codes (`euler-slurm explain --all` lists them). Codes it does not know are reported as
145
+ unknown, with a pointer to `man squeue` (JOB REASON CODES). It does not guess
146
+ from the code's name.
147
+
148
+ ### And when a job has ended?
149
+
150
+ | State / exit | Plain words | Usual fix |
151
+ |---|---|---|
152
+ | `TIMEOUT` | It reached `--time` and was stopped. | More `--time`, or checkpoint and resume (`--signal=B:USR1@300`). |
153
+ | `OUT_OF_MEMORY`, exit `0:125` | It used more RAM than `--mem`. (GPU memory shows as `CUDA out of memory` in the log.) | More `--mem`, fewer DataLoader workers; `sacct -j <id> -o ReqMem,MaxRSS`. |
154
+ | `NODE_FAIL` | A node broke. Not your code. | Resubmit, `--exclude=<node>`. |
155
+ | `PREEMPTED` | A higher-priority job took the resources. | Resubmit; `--requeue` and frequent checkpoints. |
156
+ | `CANCELLED` | `scancel` (by you, an admin or a tool). | `sacct -j <id> -o State%30` shows who. |
157
+ | `FAILED`, exit 1 | Your program raised an error. | The last traceback in the log (`euler-slurm diagnose <id>`). |
158
+ | exit 137 (`0:9`) | Killed with SIGKILL: usually out of memory, or stopped after a cancel/time limit. | `sacct -j <id> -o State,ReqMem,MaxRSS`. |
159
+ | exit 139 (`0:11`) | Segmentation fault in native code: often mismatched CUDA/PyTorch builds. | Rebuild extensions; `euler-suite doctor`. |
160
+ | exit 143 (`0:15`) | SIGTERM: cancelled, time limit or preemption. | `sacct -j <id> -o State` says which. |
161
+
162
+ ## Python API
163
+
164
+ ```python
165
+ from euler_slurm import list_jobs, get_job, diagnose, explain, capability_report
166
+
167
+ listing = list_jobs() # your jobs; list_jobs(job_ids=["123_4"])
168
+ for job in listing: # Job dataclasses
169
+ print(job.job_id, job.state, job.state_reason, job.gpus, job.time_used_s)
170
+ print(listing.sources, listing.problems) # how it was read, what is missing
171
+
172
+ job = get_job("123") # scontrol while SLURM remembers it, then sacct
173
+ print(explain(job.state_reason or job.state).fix)
174
+
175
+ report = diagnose("123", log_tail_lines=200, logs=["/scratch/alice/run.log"])
176
+ print(report.verdict.summary, report.verdict.cause, report.verdict.fix)
177
+ for finding in report.findings: # {code, severity, subject, message, hint}
178
+ print(finding.severity, finding.message, finding.hint)
179
+
180
+ from euler_slurm import catalog
181
+
182
+ catalog()["pending_reasons"][0] # {code, kind, label, meaning, fix, …, category}
183
+ ```
184
+
185
+ Everything goes through a `Runner` (`run(args, timeout) -> (rc, stdout, stderr)`),
186
+ so tests and remote tools can pass their own: `list_jobs(runner=my_runner)`.
187
+ The default runs the commands on this machine without a shell; a missing
188
+ command raises `SlurmUnavailable`, never a crash.
189
+
190
+ `Job` fields: `job_id`, `raw_job_id`, `array_job_id`, `array_task_id`,
191
+ `array_task_range`, `name`, `user`, `state` (normalized long name),
192
+ `state_flags`, `state_reason`, `cancelled_by`, `partition`, `nodes`,
193
+ `node_count`, `cpus`, `gpus` (`{count, type}` for the whole job, from TRES or
194
+ GRES), `time_used_s`, `time_limit_s`, `time_limit_unlimited`, `submit_time`,
195
+ `start_time`, `end_time` (ISO 8601 with offset; estimates while the job has not
196
+ ended), `exit_code`, `signal`, `shell_exit_code`, `work_dir`, `stdout_path`,
197
+ `stderr_path`, `source`.
198
+
199
+ ## How it reads SLURM
200
+
201
+ | Facts | Command | JSON (Slurm ≥ 21.08) | Fallback |
202
+ |---|---|---|---|
203
+ | active jobs | `squeue` | `squeue --json` | `squeue --noheader --format '%i\|%A\|…\|%j'`, plus `--Format JobID,tres-alloc` for `--gpus` jobs |
204
+ | ended jobs | `sacct --allocations` | `sacct --json` | `sacct --noheader --parsable2 --format=JobID,…,JobName` |
205
+ | one job | `scontrol show job` | `scontrol --json show job` | `scontrol --oneliner show job` |
206
+ | partitions | `sinfo` | – | `sinfo --noheader --format '%P\|%a\|%l\|%D\|%c\|%m\|%G'` |
207
+
208
+ - JSON is tried first; when it is not available the text form is read, and
209
+ both produce the same `Job` (the tests check that they agree). Which one
210
+ answered is in `sources` / `Job.source`.
211
+ - User and job-id filters are applied again to JSON, because Slurm before
212
+ 23.02 ignored them with `--json`.
213
+ - Commands run with `SLURM_TIME_FORMAT=standard` and without `SQUEUE_*`,
214
+ `SACCT_*`, `SINFO_*`, `SCONTROL_*` variables, so personal settings cannot
215
+ change the output format.
216
+ - Handled forms: short and long states, `CANCELLED by <uid>`, `+` suffixes,
217
+ JSON state flag lists (`["COMPLETED", "COMPLETING"]` is shown as
218
+ `COMPLETING`, like squeue does), array ids `123_4` and `123_[1-3%2]`,
219
+ `UNLIMITED`/`infinite`, `1-02:03:04` durations, both JSON number forms
220
+ (plain and `{set, infinite, number}`), `ExitCode=0:125` (SLURM's out-of-memory
221
+ marker), names containing the delimiter.
222
+ - No accounting database (`sacct` fails)? Active jobs are still listed and the
223
+ listing says that finished jobs are missing (`problems`).
224
+
225
+ ## For tools: envelopes and the capability report
226
+
227
+ Every JSON document has `contract: {kind, version}` and `package: {name,
228
+ version}`. Readers should check the kind and the major version and ignore
229
+ fields they do not know. A failed command prints the same kind with
230
+ `error: {code, message}` (`slurm_unavailable`, `job_not_found`,
231
+ `slurm_command_failed`, `invalid_argument`).
232
+
233
+ | Envelope | Version | Printed by |
234
+ |---|---|---|
235
+ | `slurm_jobs` | 1.0 | `euler-slurm jobs --json` |
236
+ | `slurm_job` | 1.0 | `euler-slurm job <id> --json` |
237
+ | `slurm_diagnosis` | 1.1 | `euler-slurm diagnose <id> --json`: `job` (`null` when only logs were read), `summary`, `verdict`, `findings`, `logs` |
238
+ | `slurm_explanations` | 1.0 | `euler-slurm explain --all --json` (`catalog`), `euler-slurm explain <code> --json` (`explanations`) |
239
+ | `slurm_capability_report` | 1.1 | `euler-slurm capabilities`, the `euler.capabilities` entry point |
240
+
241
+ `euler-slurm` registers `capability_report` in the suite's
242
+ `euler.capabilities` entry-point group, so `euler-suite report`
243
+ (euler-dataset-contract) includes a `slurm_capability_report` 1.1: whether SLURM
244
+ is available here (and why not), its version, whether `--json` is supported,
245
+ the partitions with their time limits, node counts and GPUs (`{type,
246
+ per_node, nodes, total}`), the commands and envelopes this package offers, the
247
+ codes it can explain and the whole explanation `catalog`. The report never
248
+ raises; on a laptop it says `available: false` and still carries the catalog.
249
+
250
+ **The catalog** (`catalog()`, `explain --all --json`, and `catalog` in the
251
+ capability report) is every explanation as data, so a tool can show SLURM's
252
+ codes in plain words without asking euler-slurm each time: `pending_reasons`
253
+ (`{code, kind, label, meaning, fix, severity, blocked, category}`, sorted by
254
+ code), `states` (also `short`, e.g. `PD`, and `terminal`/`pending`),
255
+ `exit_codes` (`"0"` … `"255"`, then SLURM's out-of-memory marker `"0:125"`),
256
+ `signals` (`{number, name}`: exit code 128 + number) and `categories` (each
257
+ kind's closed set, code → a few words). Categories group codes by what they
258
+ mean for the user: pending reasons are `queue`, `dependency`, `schedule`,
259
+ `hold`, `limit` (clears by itself), `request` (never starts as it is), `budget`,
260
+ `nodes`, `startup`, `requeued` or `other`; states `waiting`, `held`, `running`,
261
+ `paused`, `succeeded`, `failed`, `interrupted` or `cancelled`; exit codes
262
+ `success`, `error`, `environment`, `signal` or `memory`. A code euler-slurm
263
+ does not know has category `unknown`. Texts keep the `<job_id>` placeholder.
264
+
265
+ **The verdict** of `slurm_diagnosis` is the one thing to tell a newcomer, chosen
266
+ by euler-slurm, so tools show it instead of ranking findings themselves:
267
+ `{summary, cause, fix, code, severity, evidence}`. `summary` is the job in a few
268
+ words ("Failed (exit code 1)", "Waiting for its turn", "No SLURM record");
269
+ `cause` and `fix` come from the most specific finding: a cause found in the
270
+ logs (CUDA out of memory beats a bare Python traceback), else the state or
271
+ pending reason. When SLURM itself stopped the job (time limit, preemption,
272
+ node failure, cancellation, out of memory), a traceback or `Killed` line is
273
+ taken as its consequence and the state stays the cause. `evidence` is the log
274
+ line it rests on (`{path, line}`) or `null`. Tools that know more log files
275
+ than SLURM pass them with `--log PATH` (repeatable); when SLURM has forgotten
276
+ the job, `diagnose --log` still answers from the logs, with `job: null` and a
277
+ first finding `job.not_found`.
278
+
279
+ ## Development
280
+
281
+ ```sh
282
+ uv venv && uv pip install -e '.[dev]'
283
+ pytest
284
+ ruff check .
285
+ ```
286
+
287
+ The tests run against recorded outputs in `tests/fixtures/` (Slurm 23.11 and
288
+ 21.08 JSON, `--format`/`--parsable2` text, `scontrol -o`, `sinfo`) through a fake
289
+ runner; no SLURM is needed.
290
+
291
+ ## License
292
+
293
+ MIT