hpc-core 0.1.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 (83) hide show
  1. hpc_core-0.1.0/LICENSE +201 -0
  2. hpc_core-0.1.0/NOTICE +4 -0
  3. hpc_core-0.1.0/PKG-INFO +90 -0
  4. hpc_core-0.1.0/README.md +72 -0
  5. hpc_core-0.1.0/pyproject.toml +44 -0
  6. hpc_core-0.1.0/setup.cfg +4 -0
  7. hpc_core-0.1.0/src/hpc_core/__init__.py +1 -0
  8. hpc_core-0.1.0/src/hpc_core/contract/__init__.py +76 -0
  9. hpc_core-0.1.0/src/hpc_core/contract/fields.py +155 -0
  10. hpc_core-0.1.0/src/hpc_core/contract/identifiers.py +43 -0
  11. hpc_core-0.1.0/src/hpc_core/contract/metrics.py +92 -0
  12. hpc_core-0.1.0/src/hpc_core/contract/report.py +279 -0
  13. hpc_core-0.1.0/src/hpc_core/contract/resources.py +99 -0
  14. hpc_core-0.1.0/src/hpc_core/contract/sacct.py +122 -0
  15. hpc_core-0.1.0/src/hpc_core/contract/sinfo.py +44 -0
  16. hpc_core-0.1.0/src/hpc_core/contract/squeue.py +78 -0
  17. hpc_core-0.1.0/src/hpc_core/contract/sstat.py +46 -0
  18. hpc_core-0.1.0/src/hpc_core/contract/states.py +66 -0
  19. hpc_core-0.1.0/src/hpc_core/contract/times.py +85 -0
  20. hpc_core-0.1.0/src/hpc_core/py.typed +0 -0
  21. hpc_core-0.1.0/src/hpc_core/slurm/__init__.py +24 -0
  22. hpc_core-0.1.0/src/hpc_core/slurm/adapter.py +119 -0
  23. hpc_core-0.1.0/src/hpc_core/slurm/commands.py +84 -0
  24. hpc_core-0.1.0/src/hpc_core/testing/__init__.py +27 -0
  25. hpc_core-0.1.0/src/hpc_core/testing/contract.py +97 -0
  26. hpc_core-0.1.0/src/hpc_core/testing/fake_transport.py +51 -0
  27. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/bad_row.csv +4 -0
  28. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/bad_row.expected.json +54 -0
  29. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/cancelled_before_start.csv +2 -0
  30. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/cancelled_before_start.expected.json +30 -0
  31. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/finished_run.csv +4 -0
  32. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/finished_run.expected.json +78 -0
  33. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/one_gpu_run.csv +2 -0
  34. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/one_gpu_run.expected.json +30 -0
  35. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/unavailable_metrics.csv +2 -0
  36. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/unavailable_metrics.expected.json +30 -0
  37. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/unknown_schema_version.csv +2 -0
  38. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/unknown_schema_version.expected.json +4 -0
  39. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/zero_beside_blank.csv +2 -0
  40. hpc_core-0.1.0/src/hpc_core/testing/fixtures/reports/zero_beside_blank.expected.json +30 -0
  41. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sacct-console.expected.json +83 -0
  42. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sacct-console.txt +7 -0
  43. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sacct-empty.expected.json +6 -0
  44. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sacct-empty.txt +3 -0
  45. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sacct-operator-recorded.expected.json +159 -0
  46. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sacct-operator-recorded.txt +11 -0
  47. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sacct-operator.expected.json +83 -0
  48. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sacct-operator.txt +7 -0
  49. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sinfo-capacity.expected.json +31 -0
  50. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sinfo-capacity.txt +6 -0
  51. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sinfo-empty.expected.json +6 -0
  52. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sinfo-empty.txt +3 -0
  53. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/squeue-empty.expected.json +6 -0
  54. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/squeue-empty.txt +3 -0
  55. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/squeue-operator-recorded.expected.json +102 -0
  56. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/squeue-operator-recorded.txt +8 -0
  57. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/squeue-operator.expected.json +83 -0
  58. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/squeue-operator.txt +8 -0
  59. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sstat-empty.expected.json +6 -0
  60. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sstat-empty.txt +3 -0
  61. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sstat-no-steps-empty.expected.json +6 -0
  62. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sstat-no-steps-empty.txt +4 -0
  63. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sstat-running.expected.json +31 -0
  64. hpc_core-0.1.0/src/hpc_core/testing/fixtures/scheduler/sstat-running.txt +7 -0
  65. hpc_core-0.1.0/src/hpc_core/testing/fixtures.py +123 -0
  66. hpc_core-0.1.0/src/hpc_core/transport/__init__.py +8 -0
  67. hpc_core-0.1.0/src/hpc_core/transport/protocol.py +39 -0
  68. hpc_core-0.1.0/src/hpc_core.egg-info/PKG-INFO +90 -0
  69. hpc_core-0.1.0/src/hpc_core.egg-info/SOURCES.txt +81 -0
  70. hpc_core-0.1.0/src/hpc_core.egg-info/dependency_links.txt +1 -0
  71. hpc_core-0.1.0/src/hpc_core.egg-info/requires.txt +5 -0
  72. hpc_core-0.1.0/src/hpc_core.egg-info/top_level.txt +1 -0
  73. hpc_core-0.1.0/tests/test_contract_kit.py +67 -0
  74. hpc_core-0.1.0/tests/test_docs_examples.py +42 -0
  75. hpc_core-0.1.0/tests/test_hygiene.py +59 -0
  76. hpc_core-0.1.0/tests/test_layering.py +81 -0
  77. hpc_core-0.1.0/tests/test_public_api.py +68 -0
  78. hpc_core-0.1.0/tests/test_release_tag.py +45 -0
  79. hpc_core-0.1.0/tests/test_schema_snapshot.py +32 -0
  80. hpc_core-0.1.0/tests/test_scrub_fixture.py +98 -0
  81. hpc_core-0.1.0/tests/test_stdlib_only.py +46 -0
  82. hpc_core-0.1.0/tests/test_wheel_fixtures.py +80 -0
  83. hpc_core-0.1.0/tests/test_workflows.py +29 -0
hpc_core-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
hpc_core-0.1.0/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ hpc-core
2
+ Copyright 2026 NEU-DataSpark
3
+
4
+ This product includes software developed by NEU-DataSpark.
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: hpc-core
3
+ Version: 0.1.0
4
+ Summary: Dependency-free contract, transport interface and Slurm adapter for DataSpark HPC tools.
5
+ License-Expression: Apache-2.0
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Classifier: Typing :: Typed
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest>=8; extra == "dev"
15
+ Requires-Dist: ruff>=0.6; extra == "dev"
16
+ Requires-Dist: mypy>=1.11; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # hpc-core
20
+
21
+ Shared Python package for remote HPC operations. It holds the scheduler output parsers, the
22
+ run-report CSV contract and its metrics, a minimal transport interface and a fixed-command Slurm
23
+ adapter, so the DataSpark HPC tools parse and format the same data the same way.
24
+
25
+ It has no runtime dependency and needs Python 3.11 or newer.
26
+
27
+ ## Layers
28
+
29
+ The packages are split by layer, not by lifecycle stage (environment setup, submit, fetch,
30
+ monitor, metrics). A lifecycle split would make each package depend on the transport and the data
31
+ formats again, and duplicate them.
32
+
33
+ | Layer | Package | Responsibility | I/O |
34
+ | --- | --- | --- | --- |
35
+ | Contract | `hpc_core.contract` | Scheduler output parsing (`squeue`, `sacct`, `sinfo`, `sstat`), the run-report CSV schema and its `schema_version`, metric calculations | None. Standard library only |
36
+ | Transport | `hpc_core.transport` | A small interface to run a fixed command on the login node: argument tuple, timeout, output limit, exit status | Yes, one implementation per consumer |
37
+ | Scheduler adapter | `hpc_core.slurm` | Builds the fixed, read-only Slurm commands and passes their output to the contract layer | Through the transport interface |
38
+ | Test kit | `hpc_core.testing` | Anonymised scheduler fixtures, golden run-reports, reader and writer contract checks, a fake transport | None |
39
+
40
+ Consumers keep their own transport implementation: the operator skill uses the `ssh` command, and
41
+ the HPC Console uses `paramiko`. This package contains neither.
42
+
43
+ ## Install
44
+
45
+ Once a release has been published to PyPI, install a pinned version:
46
+
47
+ ```bash
48
+ python -m pip install "hpc-core==X.Y.Z"
49
+ ```
50
+
51
+ Alternatively, install a tagged release directly from Git:
52
+
53
+ ```bash
54
+ python -m pip install "hpc-core @ git+https://github.com/NEU-DataSpark/hpc-core.git@vX.Y.Z"
55
+ ```
56
+
57
+ See [`docs/versioning.md`](docs/versioning.md) for the release process.
58
+
59
+ ## Development
60
+
61
+ Run these from the repository root in a virtual environment:
62
+
63
+ ```bash
64
+ python -m pip install -e ".[dev]" # install with the development tools
65
+ python -m pytest # test suite, including layering, stdlib-only and hygiene guards
66
+ python -m ruff check . # lint
67
+ python -m mypy # strict type check
68
+ python tools/hygiene_scan.py # scan for paths, addresses, e-mail addresses and key headers
69
+ python -m pip wheel --no-deps -w dist . # build the wheel
70
+ ```
71
+
72
+ Documentation is in [`docs/`](docs/): parsing, the run-report contract, the adapter, the consumer
73
+ contract test, fixture recording, and versioning.
74
+
75
+ ## Rules
76
+
77
+ - Never commit credentials, host names, account names, key paths or cluster-specific paths. Pass
78
+ them in as arguments or settings.
79
+ - Every parser has tests with recorded, anonymised scheduler output as fixtures.
80
+ - A change to the run-report CSV format bumps `schema_version` and comes with a contract test that
81
+ both consumers run.
82
+
83
+ ## Consumers
84
+
85
+ - `DataSpark-Skills` (the `hpc-operator` skill): submits and tracks jobs and writes run reports.
86
+ - `hpc-console` (the web console): reads the cluster state and the run reports.
87
+
88
+ ## License
89
+
90
+ Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,72 @@
1
+ # hpc-core
2
+
3
+ Shared Python package for remote HPC operations. It holds the scheduler output parsers, the
4
+ run-report CSV contract and its metrics, a minimal transport interface and a fixed-command Slurm
5
+ adapter, so the DataSpark HPC tools parse and format the same data the same way.
6
+
7
+ It has no runtime dependency and needs Python 3.11 or newer.
8
+
9
+ ## Layers
10
+
11
+ The packages are split by layer, not by lifecycle stage (environment setup, submit, fetch,
12
+ monitor, metrics). A lifecycle split would make each package depend on the transport and the data
13
+ formats again, and duplicate them.
14
+
15
+ | Layer | Package | Responsibility | I/O |
16
+ | --- | --- | --- | --- |
17
+ | Contract | `hpc_core.contract` | Scheduler output parsing (`squeue`, `sacct`, `sinfo`, `sstat`), the run-report CSV schema and its `schema_version`, metric calculations | None. Standard library only |
18
+ | Transport | `hpc_core.transport` | A small interface to run a fixed command on the login node: argument tuple, timeout, output limit, exit status | Yes, one implementation per consumer |
19
+ | Scheduler adapter | `hpc_core.slurm` | Builds the fixed, read-only Slurm commands and passes their output to the contract layer | Through the transport interface |
20
+ | Test kit | `hpc_core.testing` | Anonymised scheduler fixtures, golden run-reports, reader and writer contract checks, a fake transport | None |
21
+
22
+ Consumers keep their own transport implementation: the operator skill uses the `ssh` command, and
23
+ the HPC Console uses `paramiko`. This package contains neither.
24
+
25
+ ## Install
26
+
27
+ Once a release has been published to PyPI, install a pinned version:
28
+
29
+ ```bash
30
+ python -m pip install "hpc-core==X.Y.Z"
31
+ ```
32
+
33
+ Alternatively, install a tagged release directly from Git:
34
+
35
+ ```bash
36
+ python -m pip install "hpc-core @ git+https://github.com/NEU-DataSpark/hpc-core.git@vX.Y.Z"
37
+ ```
38
+
39
+ See [`docs/versioning.md`](docs/versioning.md) for the release process.
40
+
41
+ ## Development
42
+
43
+ Run these from the repository root in a virtual environment:
44
+
45
+ ```bash
46
+ python -m pip install -e ".[dev]" # install with the development tools
47
+ python -m pytest # test suite, including layering, stdlib-only and hygiene guards
48
+ python -m ruff check . # lint
49
+ python -m mypy # strict type check
50
+ python tools/hygiene_scan.py # scan for paths, addresses, e-mail addresses and key headers
51
+ python -m pip wheel --no-deps -w dist . # build the wheel
52
+ ```
53
+
54
+ Documentation is in [`docs/`](docs/): parsing, the run-report contract, the adapter, the consumer
55
+ contract test, fixture recording, and versioning.
56
+
57
+ ## Rules
58
+
59
+ - Never commit credentials, host names, account names, key paths or cluster-specific paths. Pass
60
+ them in as arguments or settings.
61
+ - Every parser has tests with recorded, anonymised scheduler output as fixtures.
62
+ - A change to the run-report CSV format bumps `schema_version` and comes with a contract test that
63
+ both consumers run.
64
+
65
+ ## Consumers
66
+
67
+ - `DataSpark-Skills` (the `hpc-operator` skill): submits and tracks jobs and writes run reports.
68
+ - `hpc-console` (the web console): reads the cluster state and the run reports.
69
+
70
+ ## License
71
+
72
+ Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "hpc-core"
7
+ version = "0.1.0"
8
+ description = "Dependency-free contract, transport interface and Slurm adapter for DataSpark HPC tools."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE", "NOTICE"]
13
+ dependencies = []
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3 :: Only",
17
+ "Typing :: Typed",
18
+ ]
19
+
20
+ [project.optional-dependencies]
21
+ dev = ["pytest>=8", "ruff>=0.6", "mypy>=1.11"]
22
+
23
+ [tool.setuptools.packages.find]
24
+ where = ["src"]
25
+
26
+ [tool.setuptools.package-data]
27
+ hpc_core = ["py.typed"]
28
+ "hpc_core.testing" = ["fixtures/**/*"]
29
+
30
+ [tool.ruff]
31
+ line-length = 100
32
+ target-version = "py311"
33
+
34
+ [tool.ruff.lint]
35
+ select = ["E", "F", "I", "B", "UP"]
36
+
37
+ [tool.mypy]
38
+ python_version = "3.11"
39
+ strict = true
40
+ files = ["src/hpc_core", "tests", "tools"]
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+ pythonpath = ["tools"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ """Shared, dependency-free HPC scheduler contract, transport interface and Slurm adapter."""
@@ -0,0 +1,76 @@
1
+ """Contract layer: standard library only, no I/O.
2
+
3
+ Scheduler output parsing, identifiers, the run-report CSV schema and its reader, and metrics.
4
+ """
5
+
6
+ from .fields import (
7
+ Field,
8
+ FieldProfile,
9
+ JobRecord,
10
+ NodeRecord,
11
+ ParseResult,
12
+ ProfileError,
13
+ SstatRecord,
14
+ )
15
+ from .identifiers import ValidationError, is_job_id, is_step_id, validate_account, validate_job_id
16
+ from .metrics import (
17
+ cpu_hours,
18
+ cpu_seconds_used,
19
+ elapsed_seconds,
20
+ gpu_hours,
21
+ mean,
22
+ peak,
23
+ running_cpu_seconds,
24
+ wait_seconds,
25
+ )
26
+ from .report import (
27
+ COLUMNS,
28
+ SCHEMA_VERSION,
29
+ SUPPORTED_VERSIONS,
30
+ ReadResult,
31
+ ReportError,
32
+ ReportRow,
33
+ format_report,
34
+ format_row,
35
+ read_report,
36
+ )
37
+ from .states import classify_state, state_word
38
+ from .times import format_time, parse_duration, parse_report_time, parse_time
39
+
40
+ __all__ = [
41
+ "COLUMNS",
42
+ "SCHEMA_VERSION",
43
+ "SUPPORTED_VERSIONS",
44
+ "Field",
45
+ "FieldProfile",
46
+ "JobRecord",
47
+ "NodeRecord",
48
+ "ParseResult",
49
+ "ProfileError",
50
+ "ReadResult",
51
+ "ReportError",
52
+ "ReportRow",
53
+ "SstatRecord",
54
+ "ValidationError",
55
+ "classify_state",
56
+ "cpu_hours",
57
+ "cpu_seconds_used",
58
+ "elapsed_seconds",
59
+ "format_report",
60
+ "format_row",
61
+ "format_time",
62
+ "gpu_hours",
63
+ "is_job_id",
64
+ "is_step_id",
65
+ "mean",
66
+ "parse_duration",
67
+ "parse_report_time",
68
+ "parse_time",
69
+ "peak",
70
+ "read_report",
71
+ "running_cpu_seconds",
72
+ "state_word",
73
+ "validate_account",
74
+ "validate_job_id",
75
+ "wait_seconds",
76
+ ]
@@ -0,0 +1,155 @@
1
+ """Named field profiles, the records parsers return, and the row splitter.
2
+
3
+ A profile names the columns a command was asked for, in order. Cells are read by name, so a field
4
+ the profile does not name is unset on the record. A free-text field (a job name) may only be the
5
+ last field, so a separator inside it cannot shift the others.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from dataclasses import dataclass
11
+ from datetime import datetime
12
+ from typing import Generic, TypeVar
13
+
14
+ from .states import StateClass
15
+
16
+ SUPPORTED_COMMANDS: frozenset[str] = frozenset({"squeue", "sacct", "sinfo", "sstat"})
17
+
18
+
19
+ class ProfileError(ValueError):
20
+ """A field profile that breaks the rules. The message names the offending field."""
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class Field:
25
+ name: str
26
+ token: str
27
+ free_text: bool = False
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class FieldProfile:
32
+ name: str
33
+ command: str
34
+ fields: tuple[Field, ...]
35
+ separator: str = "|"
36
+
37
+ def __post_init__(self) -> None:
38
+ if self.command not in SUPPORTED_COMMANDS:
39
+ raise ProfileError(f"profile '{self.name}': unsupported command '{self.command}'")
40
+ if len(self.separator) != 1 or self.separator.isspace() or self.separator in ",%":
41
+ raise ProfileError(f"profile '{self.name}': separator must be one plain character")
42
+ if not self.fields:
43
+ raise ProfileError(f"profile '{self.name}': no fields")
44
+ names = [item.name for item in self.fields]
45
+ duplicates = sorted({name for name in names if names.count(name) > 1})
46
+ if duplicates:
47
+ raise ProfileError(f"profile '{self.name}': duplicate field '{duplicates[0]}'")
48
+ for item in self.fields:
49
+ if not item.token or any(ch in item.token for ch in ", \t\n"):
50
+ raise ProfileError(f"profile '{self.name}': bad token for field '{item.name}'")
51
+ for item in self.fields[:-1]:
52
+ if item.free_text:
53
+ raise ProfileError(
54
+ f"profile '{self.name}': free-text field '{item.name}' must be the last field"
55
+ )
56
+
57
+ @property
58
+ def names(self) -> tuple[str, ...]:
59
+ return tuple(item.name for item in self.fields)
60
+
61
+
62
+ T = TypeVar("T")
63
+
64
+
65
+ @dataclass(frozen=True)
66
+ class ParseResult(Generic[T]):
67
+ records: tuple[T, ...]
68
+ skipped: int
69
+
70
+
71
+ def check_known_names(profile: FieldProfile, known: frozenset[str]) -> None:
72
+ for name in profile.names:
73
+ if name not in known:
74
+ raise ProfileError(
75
+ f"profile '{profile.name}': field '{name}' is not read by {profile.command}"
76
+ )
77
+
78
+
79
+ def iter_rows(text: str, profile: FieldProfile) -> tuple[list[dict[str, str]], int]:
80
+ """Split command output into rows keyed by field name. Returns (good rows, skipped count).
81
+
82
+ Blank lines are not rows and are not counted. A row with too few cells is skipped; so is a row
83
+ with extra cells unless the last field is free text, which keeps any extra separators.
84
+ """
85
+ width = len(profile.fields)
86
+ last = profile.fields[-1]
87
+ good: list[dict[str, str]] = []
88
+ skipped = 0
89
+ for raw_line in text.splitlines():
90
+ line = raw_line.rstrip("\r")
91
+ if not line.strip():
92
+ continue
93
+ cells = line.split(profile.separator)
94
+ if last.free_text:
95
+ if len(cells) < width:
96
+ skipped += 1
97
+ continue
98
+ cells = cells[: width - 1] + [profile.separator.join(cells[width - 1 :])]
99
+ elif len(cells) != width:
100
+ skipped += 1
101
+ continue
102
+ row = {
103
+ item.name: (cell if item.free_text else cell.strip())
104
+ for item, cell in zip(profile.fields, cells, strict=True)
105
+ }
106
+ good.append(row)
107
+ return good, skipped
108
+
109
+
110
+ @dataclass(frozen=True)
111
+ class JobRecord:
112
+ """One job row from squeue or sacct. Every field is unset unless the profile named it and
113
+
114
+ the cell was readable.
115
+ """
116
+
117
+ job_id: str
118
+ job_name: str | None = None
119
+ partition: str | None = None
120
+ state: str | None = None
121
+ state_class: StateClass | None = None
122
+ reason: str | None = None
123
+ submit_time: datetime | None = None
124
+ start_time: datetime | None = None
125
+ end_time: datetime | None = None
126
+ cpus_requested: int | None = None
127
+ cpus_allocated: int | None = None
128
+ gpus_requested: int | None = None
129
+ gpus_allocated: int | None = None
130
+ gpu_type: str | None = None
131
+ total_cpu_seconds: float | None = None
132
+ max_rss_mib: float | None = None
133
+ time_limit_seconds: float | None = None
134
+
135
+
136
+ @dataclass(frozen=True)
137
+ class SstatRecord:
138
+ """One job step row from sstat."""
139
+
140
+ step_id: str
141
+ ave_cpu_seconds: float | None = None
142
+ ntasks: int | None = None
143
+ max_rss_mib: float | None = None
144
+
145
+
146
+ @dataclass(frozen=True)
147
+ class NodeRecord:
148
+ """One partition row from sinfo."""
149
+
150
+ partition: str | None = None
151
+ gres: str | None = None
152
+ state: str | None = None
153
+ node_count: int | None = None
154
+ gpus_per_node: int | None = None
155
+ gpu_type: str | None = None