hpcagent-agent 1.0.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 (50) hide show
  1. hpcagent_agent-1.0.0/PKG-INFO +120 -0
  2. hpcagent_agent-1.0.0/README.md +108 -0
  3. hpcagent_agent-1.0.0/hpcagent_agent/__init__.py +10 -0
  4. hpcagent_agent-1.0.0/hpcagent_agent/coded.py +78 -0
  5. hpcagent_agent-1.0.0/hpcagent_agent/driver/__init__.py +2 -0
  6. hpcagent_agent-1.0.0/hpcagent_agent/driver/agent_driver.py +3909 -0
  7. hpcagent_agent-1.0.0/hpcagent_agent/driver/effort.py +74 -0
  8. hpcagent_agent-1.0.0/hpcagent_agent/driver/harnesses.py +659 -0
  9. hpcagent_agent-1.0.0/hpcagent_agent/driver/net_relay.py +321 -0
  10. hpcagent_agent-1.0.0/hpcagent_agent/driver/promote_unsubmitted.py +570 -0
  11. hpcagent_agent-1.0.0/hpcagent_agent/driver/seal_worker.py +474 -0
  12. hpcagent_agent-1.0.0/hpcagent_agent/driver/stream_idle_timeout.py +73 -0
  13. hpcagent_agent-1.0.0/hpcagent_agent/driver/token_cost.py +1219 -0
  14. hpcagent_agent-1.0.0/hpcagent_agent/env_aliases.py +78 -0
  15. hpcagent_agent-1.0.0/hpcagent_agent/harness/__init__.py +2 -0
  16. hpcagent_agent-1.0.0/hpcagent_agent/harness/bash-norc +11 -0
  17. hpcagent_agent-1.0.0/hpcagent_agent/harness/miniswe.yaml +119 -0
  18. hpcagent_agent-1.0.0/hpcagent_agent/harness/openhands_stdio.py +54 -0
  19. hpcagent_agent-1.0.0/hpcagent_agent/harness/run_anthropic.py +306 -0
  20. hpcagent_agent-1.0.0/hpcagent_agent/harness/run_miniswe.py +140 -0
  21. hpcagent_agent-1.0.0/hpcagent_agent/harness/run_openai.py +279 -0
  22. hpcagent_agent-1.0.0/hpcagent_agent/harness/run_openhands.py +267 -0
  23. hpcagent_agent-1.0.0/hpcagent_agent/harness/runner_common.py +632 -0
  24. hpcagent_agent-1.0.0/hpcagent_agent/harness/subagents.py +122 -0
  25. hpcagent_agent-1.0.0/hpcagent_agent/knowledge.py +525 -0
  26. hpcagent_agent-1.0.0/hpcagent_agent/network_policy.py +157 -0
  27. hpcagent_agent-1.0.0/hpcagent_agent/plugins.py +698 -0
  28. hpcagent_agent-1.0.0/hpcagent_agent/prompt_blocks.py +244 -0
  29. hpcagent_agent-1.0.0/hpcagent_agent/submission_mode.py +92 -0
  30. hpcagent_agent-1.0.0/hpcagent_agent/templates/submission-blind.md +45 -0
  31. hpcagent_agent-1.0.0/hpcagent_agent/templates/submission-multi.md +36 -0
  32. hpcagent_agent-1.0.0/hpcagent_agent/templates/submission-single.md +36 -0
  33. hpcagent_agent-1.0.0/hpcagent_agent/tools/__init__.py +2 -0
  34. hpcagent_agent-1.0.0/hpcagent_agent/tools/canonical_parallel_form.py +207 -0
  35. hpcagent_agent-1.0.0/hpcagent_agent/tools/hpcagent_bench_tool.py +96 -0
  36. hpcagent_agent-1.0.0/hpcagent_agent/tools/http_json.py +741 -0
  37. hpcagent_agent-1.0.0/hpcagent_agent/tools/knowledge_read.py +63 -0
  38. hpcagent_agent-1.0.0/hpcagent_agent/tools/knowledge_search.py +77 -0
  39. hpcagent_agent-1.0.0/hpcagent_agent/tools/mcp_server.py +247 -0
  40. hpcagent_agent-1.0.0/hpcagent_agent/tools/next_phase.py +36 -0
  41. hpcagent_agent-1.0.0/hpcagent_agent/tools/profile_tool.py +231 -0
  42. hpcagent_agent-1.0.0/hpcagent_agent/tools/registry.py +334 -0
  43. hpcagent_agent-1.0.0/hpcagent_agent/tools/requests_check.py +47 -0
  44. hpcagent_agent-1.0.0/hpcagent_agent/tools/requests_schema.json +564 -0
  45. hpcagent_agent-1.0.0/hpcagent_agent/tools/score.py +72 -0
  46. hpcagent_agent-1.0.0/hpcagent_agent/tools/search.py +54 -0
  47. hpcagent_agent-1.0.0/hpcagent_agent/tools/submit.py +164 -0
  48. hpcagent_agent-1.0.0/hpcagent_agent/tools/syntax_check.py +178 -0
  49. hpcagent_agent-1.0.0/pyproject.toml +28 -0
  50. hpcagent_agent-1.0.0/pyproject.toml.orig +43 -0
@@ -0,0 +1,120 @@
1
+ Metadata-Version: 2.4
2
+ Name: hpcagent-agent
3
+ Version: 1.0.0
4
+ Summary: The agent-side runtime of HPCAgent-Bench: driver, MCP tools and harness runners.
5
+ Author: SPCL @ ETH Zurich
6
+ Author-email: SPCL @ ETH Zurich <yakupkoray.budanaz@inf.ethz.ch>
7
+ License-Expression: GPL-3.0-or-later
8
+ Requires-Dist: mcp>=2.3,<3
9
+ Requires-Dist: pydantic>=2.12
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Cluster Agent Runtime
14
+
15
+ The agent-side runtime. No image carries it: `hpcagent_bench/cluster/run_cluster.sh` binds the submitting checkout's copy
16
+ read-only at `/opt/hpcagent-bench-agent` when each agent step starts. `agent/hpcagent_agent/driver/agent_driver.py`
17
+ starts each agent and serves these benchmark tools through the MCP server `tools/mcp_server.py`:
18
+
19
+ - `score`: a preview on two inputs of its own (3 runs a side, rank-tested like `/submit`; protocol `mw2x3`), never recorded.
20
+ Repeatable; this is the iteration loop.
21
+ - `submit`: the grade itself (mw4x5) on held-out inputs `score` never runs, and the only route that
22
+ records a result. One per task in a single-submission setup, unbounded in an open one.
23
+ - `profile`: run a profiler over the submission and return its report.
24
+ - `canonical_parallel_form`: the kernel's canonical parallel form, already parallelized by DaCe
25
+ with basic heuristics applied (parallel loops proven, sequential loops sequential, only unknown
26
+ loops open); not a drop-in kernel.
27
+ - `search`: ask the remote benchmark service for web/research information.
28
+ - `syntax_check`: parse a source file with the LOCAL compiler. No judge, no link, no run; it works
29
+ whether or not the agent also has a shell.
30
+
31
+ Harnesses without MCP use the same tool modules:
32
+
33
+ - `hpcagent_agent/harness/run_miniswe.py`, `hpcagent_agent/harness/run_openhands.py`,
34
+ `hpcagent_agent/harness/run_anthropic.py`, `hpcagent_agent/harness/run_openai.py`, and
35
+ `plugins/optimas/run_optimas.py`, the runner of the harness the optimas plugin ships (shared code in
36
+ `hpcagent_agent/harness/runner_common.py`): one mini-SWE-agent, OpenHands, Anthropic Messages API, OpenAI Agents
37
+ SDK or Optimas episode each, started by the driver (`agent/hpcagent_agent/driver/harnesses.py`). The last three
38
+ are MCP clients of the same server, plus one shell tool (a packet may narrow it to a read tool,
39
+ `docs/extending/plugins.md`); Optimas runs the Agents SDK agent under its OPRO prompt search. OpenHands runs from its own launch venv
40
+ (`agent/harness/openhands`, its own project and lock: openhands-sdk needs mcp < 2 while this package
41
+ pins mcp >= 2.3), so the runner is only a client of the driver's server.
42
+ - `bin/hpcagent-bench-tool`: shell CLI over the same `run()` functions (`hpcagent-bench-tool <tool> '<json>'`,
43
+ `--list`, `--describe <tool>`).
44
+
45
+ Every tool but `syntax_check` only makes HTTP JSON calls. They send exactly what the judge's own
46
+ client sends and never repair a request: the `rank` is attached from `$JUDGE_RANK`, and a refusal is
47
+ returned with the judge's own message rather than retried in a different shape.
48
+
49
+ `profile_tool.py`, not `profile.py`: the tools directory is on `sys.path`, so a `profile.py` there
50
+ would shadow the stdlib module of that name. The MCP tool is still called `profile`.
51
+
52
+ ## Tool Payloads
53
+
54
+ All tools accept JSON and return the remote endpoint response as JSON.
55
+
56
+ `search` fields:
57
+
58
+ - `query` string, required: the search question.
59
+ - `context` string, optional: benchmark or optimization context.
60
+ - `limit` integer, optional: requested result count.
61
+
62
+ `score`, `submit` and `profile` share the submission body:
63
+
64
+ - `kernel` string: the assigned kernel. The driver sets it through `HPCAGENT_BENCH_KERNEL` and the model's
65
+ schema omits it; a hand-run call without that variable passes it.
66
+ - the code, delivered exactly ONE way:
67
+ - `source` string: the code inline; or
68
+ - `source_file` string: a path in the agent's folder. The basename must be `<kernel>.<ext>` -- the
69
+ kernel name plus the language's extension (`service.SOURCE_EXT`, or an alternate of
70
+ `service.SOURCE_EXT_ALIASES`: `.cc`/`.cxx`, `.F90`); a GPU language's host half takes a C++ one; or
71
+ - `library` string: a prebuilt `.so` in the shared folder, where the judge accepts one.
72
+ - `device_source` / `device_source_file`, optional: the device unit of a two-unit delivery (a HIP
73
+ host entry plus its device kernels); forwarded when present.
74
+ - `build` array of strings, optional: extra compiler flags.
75
+ - `workspace_bytes` string, optional: scratch request, as a symbolic expression.
76
+ - `compiler` string, optional: a toolchain family from the task's build-flags section (e.g. `gcc`).
77
+ - `language` string: a field only where the judge's input mode pins none (`any` / `library`);
78
+ otherwise the language comes from `$LANGUAGE`.
79
+
80
+ `rank` is NOT a field: it is attached from `$JUDGE_RANK` on every call.
81
+
82
+ `profile` additionally takes `tool` (which profiler), `min_percent`, `threads`, `reps`, `residency`,
83
+ `counters` with `counter_group` as a pair, and `per_thread` (`papi` only).
84
+
85
+ `syntax_check` fields:
86
+
87
+ - `source_file` string, required: path to the file to parse, in this container.
88
+
89
+ It answers `{"ok": <parsed>, "language", "command", "exit_code", "output"}`, where `output` is the
90
+ compiler's stdout plus stderr verbatim. The compiler comes from the file extension (`.c`, `.cpp`,
91
+ `.f90`, `.hip`, `.cu`, plus common alternates), falling back to `$LANGUAGE`. It runs
92
+ `-fsyntax-only -fopenmp -Wall -Wextra` plus the judge's dialect: `-std=c23` for C, `-std=c++20` for
93
+ C++, `-std=f2018 -ffree-form -ffree-line-length-none` for Fortran. A compiler that rejects that
94
+ `-std` is rerun at its default dialect and the answer carries a `note`. HIP and CUDA use `hipcc`,
95
+ else `clang++ --cuda-host-only`. `ok` true means the file parses, not that it is correct or fast.
96
+
97
+ A refusal comes back as `{"ok": false, "status": <code>, "error": "<judge's own
98
+ message>", "body": <the judge's JSON>}`. The common ones: `400` for a language the
99
+ track does not accept or a misnamed `source_file`, `421` for a rank this judge does
100
+ not serve (the body names both `judge_rank` and `requested_rank`).
101
+
102
+ ## Which prompt system is this?
103
+
104
+ There are two templates and one set of facts.
105
+
106
+ - **This directory** is the CLUSTER prompt: `prompt.md` is a run of `@@section` building blocks, and a setup's
107
+ prompt is that base with the overlays of `prompt_overlays/` it names (a track's `<track>-build.md`, a harness's
108
+ `tools-<harness>.md`, `repo-workflow.md`, the prompt-study variants), resolved by `hpcagent_bench.prompt_build`
109
+ and staged as the setup's resolved `prompt.md` by `materialize_shared.sh` ([docs/prompts.md](../docs/prompts.md)).
110
+ `agent/partials/` holds the text two addenda share, which a line `@@include <name>@@` pulls in.
111
+ `agent_driver.py` renders the staged blocks, fills their slots (`{{TOOLS}}`, `{{BUILD_COMMAND}}` from `build-<language>.md`,
112
+ `{{MODE:<section>}}` from `hpcagent_agent/templates/submission-<mode>.md`, `{{TASK}}`, ...) and hands the text to the agent.
113
+ - **`hpcagent_bench/harness/prompts/`** is the IN-PROCESS prompt (`task.j2`, rendered by
114
+ `harness/runner.py`) and the SERVICE prompt (`service_task.j2`, `hpcagent-bench prompt --service`).
115
+
116
+ The facts only the harness knows (the correctness band, the final grade's inputs, runs and baseline, the
117
+ timed sizes, the file names the judge reads) are rendered once, from `prompts/partials/*.j2`: the two
118
+ `.j2` prompts include them, and `make_problems.py` writes them into each problem's `prompt_facts`
119
+ (`prompts.cluster_facts`), whose keys fill the cluster prompt's remaining `{{<NAME>}}` slots.
120
+ `tests/test_cluster_prompt_sources.py` pins the separation.
@@ -0,0 +1,108 @@
1
+ # Cluster Agent Runtime
2
+
3
+ The agent-side runtime. No image carries it: `hpcagent_bench/cluster/run_cluster.sh` binds the submitting checkout's copy
4
+ read-only at `/opt/hpcagent-bench-agent` when each agent step starts. `agent/hpcagent_agent/driver/agent_driver.py`
5
+ starts each agent and serves these benchmark tools through the MCP server `tools/mcp_server.py`:
6
+
7
+ - `score`: a preview on two inputs of its own (3 runs a side, rank-tested like `/submit`; protocol `mw2x3`), never recorded.
8
+ Repeatable; this is the iteration loop.
9
+ - `submit`: the grade itself (mw4x5) on held-out inputs `score` never runs, and the only route that
10
+ records a result. One per task in a single-submission setup, unbounded in an open one.
11
+ - `profile`: run a profiler over the submission and return its report.
12
+ - `canonical_parallel_form`: the kernel's canonical parallel form, already parallelized by DaCe
13
+ with basic heuristics applied (parallel loops proven, sequential loops sequential, only unknown
14
+ loops open); not a drop-in kernel.
15
+ - `search`: ask the remote benchmark service for web/research information.
16
+ - `syntax_check`: parse a source file with the LOCAL compiler. No judge, no link, no run; it works
17
+ whether or not the agent also has a shell.
18
+
19
+ Harnesses without MCP use the same tool modules:
20
+
21
+ - `hpcagent_agent/harness/run_miniswe.py`, `hpcagent_agent/harness/run_openhands.py`,
22
+ `hpcagent_agent/harness/run_anthropic.py`, `hpcagent_agent/harness/run_openai.py`, and
23
+ `plugins/optimas/run_optimas.py`, the runner of the harness the optimas plugin ships (shared code in
24
+ `hpcagent_agent/harness/runner_common.py`): one mini-SWE-agent, OpenHands, Anthropic Messages API, OpenAI Agents
25
+ SDK or Optimas episode each, started by the driver (`agent/hpcagent_agent/driver/harnesses.py`). The last three
26
+ are MCP clients of the same server, plus one shell tool (a packet may narrow it to a read tool,
27
+ `docs/extending/plugins.md`); Optimas runs the Agents SDK agent under its OPRO prompt search. OpenHands runs from its own launch venv
28
+ (`agent/harness/openhands`, its own project and lock: openhands-sdk needs mcp < 2 while this package
29
+ pins mcp >= 2.3), so the runner is only a client of the driver's server.
30
+ - `bin/hpcagent-bench-tool`: shell CLI over the same `run()` functions (`hpcagent-bench-tool <tool> '<json>'`,
31
+ `--list`, `--describe <tool>`).
32
+
33
+ Every tool but `syntax_check` only makes HTTP JSON calls. They send exactly what the judge's own
34
+ client sends and never repair a request: the `rank` is attached from `$JUDGE_RANK`, and a refusal is
35
+ returned with the judge's own message rather than retried in a different shape.
36
+
37
+ `profile_tool.py`, not `profile.py`: the tools directory is on `sys.path`, so a `profile.py` there
38
+ would shadow the stdlib module of that name. The MCP tool is still called `profile`.
39
+
40
+ ## Tool Payloads
41
+
42
+ All tools accept JSON and return the remote endpoint response as JSON.
43
+
44
+ `search` fields:
45
+
46
+ - `query` string, required: the search question.
47
+ - `context` string, optional: benchmark or optimization context.
48
+ - `limit` integer, optional: requested result count.
49
+
50
+ `score`, `submit` and `profile` share the submission body:
51
+
52
+ - `kernel` string: the assigned kernel. The driver sets it through `HPCAGENT_BENCH_KERNEL` and the model's
53
+ schema omits it; a hand-run call without that variable passes it.
54
+ - the code, delivered exactly ONE way:
55
+ - `source` string: the code inline; or
56
+ - `source_file` string: a path in the agent's folder. The basename must be `<kernel>.<ext>` -- the
57
+ kernel name plus the language's extension (`service.SOURCE_EXT`, or an alternate of
58
+ `service.SOURCE_EXT_ALIASES`: `.cc`/`.cxx`, `.F90`); a GPU language's host half takes a C++ one; or
59
+ - `library` string: a prebuilt `.so` in the shared folder, where the judge accepts one.
60
+ - `device_source` / `device_source_file`, optional: the device unit of a two-unit delivery (a HIP
61
+ host entry plus its device kernels); forwarded when present.
62
+ - `build` array of strings, optional: extra compiler flags.
63
+ - `workspace_bytes` string, optional: scratch request, as a symbolic expression.
64
+ - `compiler` string, optional: a toolchain family from the task's build-flags section (e.g. `gcc`).
65
+ - `language` string: a field only where the judge's input mode pins none (`any` / `library`);
66
+ otherwise the language comes from `$LANGUAGE`.
67
+
68
+ `rank` is NOT a field: it is attached from `$JUDGE_RANK` on every call.
69
+
70
+ `profile` additionally takes `tool` (which profiler), `min_percent`, `threads`, `reps`, `residency`,
71
+ `counters` with `counter_group` as a pair, and `per_thread` (`papi` only).
72
+
73
+ `syntax_check` fields:
74
+
75
+ - `source_file` string, required: path to the file to parse, in this container.
76
+
77
+ It answers `{"ok": <parsed>, "language", "command", "exit_code", "output"}`, where `output` is the
78
+ compiler's stdout plus stderr verbatim. The compiler comes from the file extension (`.c`, `.cpp`,
79
+ `.f90`, `.hip`, `.cu`, plus common alternates), falling back to `$LANGUAGE`. It runs
80
+ `-fsyntax-only -fopenmp -Wall -Wextra` plus the judge's dialect: `-std=c23` for C, `-std=c++20` for
81
+ C++, `-std=f2018 -ffree-form -ffree-line-length-none` for Fortran. A compiler that rejects that
82
+ `-std` is rerun at its default dialect and the answer carries a `note`. HIP and CUDA use `hipcc`,
83
+ else `clang++ --cuda-host-only`. `ok` true means the file parses, not that it is correct or fast.
84
+
85
+ A refusal comes back as `{"ok": false, "status": <code>, "error": "<judge's own
86
+ message>", "body": <the judge's JSON>}`. The common ones: `400` for a language the
87
+ track does not accept or a misnamed `source_file`, `421` for a rank this judge does
88
+ not serve (the body names both `judge_rank` and `requested_rank`).
89
+
90
+ ## Which prompt system is this?
91
+
92
+ There are two templates and one set of facts.
93
+
94
+ - **This directory** is the CLUSTER prompt: `prompt.md` is a run of `@@section` building blocks, and a setup's
95
+ prompt is that base with the overlays of `prompt_overlays/` it names (a track's `<track>-build.md`, a harness's
96
+ `tools-<harness>.md`, `repo-workflow.md`, the prompt-study variants), resolved by `hpcagent_bench.prompt_build`
97
+ and staged as the setup's resolved `prompt.md` by `materialize_shared.sh` ([docs/prompts.md](../docs/prompts.md)).
98
+ `agent/partials/` holds the text two addenda share, which a line `@@include <name>@@` pulls in.
99
+ `agent_driver.py` renders the staged blocks, fills their slots (`{{TOOLS}}`, `{{BUILD_COMMAND}}` from `build-<language>.md`,
100
+ `{{MODE:<section>}}` from `hpcagent_agent/templates/submission-<mode>.md`, `{{TASK}}`, ...) and hands the text to the agent.
101
+ - **`hpcagent_bench/harness/prompts/`** is the IN-PROCESS prompt (`task.j2`, rendered by
102
+ `harness/runner.py`) and the SERVICE prompt (`service_task.j2`, `hpcagent-bench prompt --service`).
103
+
104
+ The facts only the harness knows (the correctness band, the final grade's inputs, runs and baseline, the
105
+ timed sizes, the file names the judge reads) are rendered once, from `prompts/partials/*.j2`: the two
106
+ `.j2` prompts include them, and `make_problems.py` writes them into each problem's `prompt_facts`
107
+ (`prompts.cluster_facts`), whose keys fill the cluster prompt's remaining `{{<NAME>}}` slots.
108
+ `tests/test_cluster_prompt_sources.py` pins the separation.
@@ -0,0 +1,10 @@
1
+ # Copyright 2026 ETH Zurich and the HPCAgent-Bench authors.
2
+ # SPDX-License-Identifier: GPL-3.0-or-later
3
+ """The agent-side runtime: everything that runs inside the agent container, and nothing from hpcagent_bench.
4
+ Dependencies are the MCP SDK and pydantic; the files the driver reads or writes are bare :mod:`json`."""
5
+
6
+ from hpcagent_agent import env_aliases
7
+
8
+ #: The deprecated short names of the configuration knobs reach their readers under the current names: translated
9
+ #: once, when the package is imported, before any of its modules reads one (env_aliases.translate).
10
+ env_aliases.translate()
@@ -0,0 +1,78 @@
1
+ # Copyright 2026 ETH Zurich and the HPCAgent-Bench authors.
2
+ # SPDX-License-Identifier: GPL-3.0-or-later
3
+ """Closed categories as ``enum.auto()`` enums, spelled as text only at a boundary via :attr:`Coded.text` /
4
+ :meth:`Coded.parse` (a member is never compared to a string). A spelling is the lower-case name joined by
5
+ ``SEPARATOR`` unless ``SPELLINGS`` overrides it; spellings of one class are distinct."""
6
+
7
+ import enum
8
+ import functools
9
+ from collections.abc import Mapping
10
+ from typing import Any, cast
11
+
12
+ from pydantic import GetCoreSchemaHandler, GetJsonSchemaHandler
13
+ from pydantic.json_schema import JsonSchemaValue
14
+ from pydantic_core import core_schema
15
+
16
+ __all__ = ["SEPARATOR", "Coded", "spellings"]
17
+
18
+ #: What joins the words of a member's name in its spelling when the class sets no ``SEPARATOR``.
19
+ SEPARATOR = "_"
20
+
21
+
22
+ @functools.lru_cache(maxsize=None, typed=True)
23
+ def spellings(cls: type["Coded"]) -> Mapping[str, "Coded"]:
24
+ """``cls``'s members by spelling; raises when two members share one."""
25
+ by_text: dict[str, Coded] = {}
26
+ for member in cls:
27
+ text = member.text
28
+ if text in by_text:
29
+ raise TypeError(f"{cls.__name__}.{member.name} and .{by_text[text].name} are both spelled {text!r}")
30
+ by_text[text] = member
31
+ return by_text
32
+
33
+
34
+ class Coded(enum.Enum):
35
+ """Base of a closed category; a subclass may set ``SEPARATOR`` and ``SPELLINGS``, both ``enum.nonmember``."""
36
+
37
+ @property
38
+ def text(self) -> str:
39
+ """This member's boundary spelling."""
40
+ own = type(self).__dict__
41
+ separator = cast("str", own.get("SEPARATOR", SEPARATOR))
42
+ overrides = cast("Mapping[str, str]", own.get("SPELLINGS", {}))
43
+ return overrides.get(self.name) or self.name.lower().replace("_", separator)
44
+
45
+ @classmethod
46
+ def parse[CodedT: Coded](cls: type[CodedT], text: str) -> CodedT:
47
+ """The member spelled ``text``; ValueError naming the spellings when none is."""
48
+ member = spellings(cls).get(text)
49
+ if member is None:
50
+ raise ValueError(f"{text!r} is not a {cls.__name__}; one of {', '.join(spellings(cls))}")
51
+ return cast("CodedT", member) # spellings(cls) holds cls's members only
52
+
53
+ @classmethod
54
+ def texts(cls) -> tuple[str, ...]:
55
+ """Every spelling, in definition order."""
56
+ return tuple(spellings(cls))
57
+
58
+ @classmethod
59
+ def validate[CodedT: Coded](cls: type[CodedT], value: object) -> CodedT:
60
+ """A member, or the member a spelling names: what a boundary model accepts."""
61
+ if isinstance(value, cls):
62
+ return value
63
+ if isinstance(value, str):
64
+ return cls.parse(value)
65
+ raise ValueError(f"{value!r} is not a {cls.__name__} spelling")
66
+
67
+ @classmethod
68
+ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaHandler) -> core_schema.CoreSchema:
69
+ return core_schema.no_info_plain_validator_function(
70
+ cls.validate,
71
+ serialization=core_schema.plain_serializer_function_ser_schema(lambda member: member.text),
72
+ )
73
+
74
+ @classmethod
75
+ def __get_pydantic_json_schema__(
76
+ cls, schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler
77
+ ) -> JsonSchemaValue:
78
+ return {"type": "string", "enum": list(cls.texts())}
@@ -0,0 +1,2 @@
1
+ # Copyright 2026 ETH Zurich and the HPCAgent-Bench authors.
2
+ # SPDX-License-Identifier: GPL-3.0-or-later