cfdbender 0.4.2__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. cfdbender-0.4.2/LICENSE +21 -0
  2. cfdbender-0.4.2/PKG-INFO +57 -0
  3. cfdbender-0.4.2/README.md +31 -0
  4. cfdbender-0.4.2/pyproject.toml +60 -0
  5. cfdbender-0.4.2/setup.cfg +4 -0
  6. cfdbender-0.4.2/src/cfdbender/__init__.py +7 -0
  7. cfdbender-0.4.2/src/cfdbender/_pyfs.py +92 -0
  8. cfdbender-0.4.2/src/cfdbender/core/__init__.py +13 -0
  9. cfdbender-0.4.2/src/cfdbender/core/adapter.py +148 -0
  10. cfdbender-0.4.2/src/cfdbender/core/executables.py +157 -0
  11. cfdbender-0.4.2/src/cfdbender/core/flight.py +346 -0
  12. cfdbender-0.4.2/src/cfdbender/core/matrix.py +354 -0
  13. cfdbender-0.4.2/src/cfdbender/core/naming.py +172 -0
  14. cfdbender-0.4.2/src/cfdbender/core/plan.py +463 -0
  15. cfdbender-0.4.2/src/cfdbender/core/registry.py +735 -0
  16. cfdbender-0.4.2/src/cfdbender/core/results.py +117 -0
  17. cfdbender-0.4.2/src/cfdbender/core/run.py +150 -0
  18. cfdbender-0.4.2/src/cfdbender/core/settings.py +92 -0
  19. cfdbender-0.4.2/src/cfdbender/core/workspace.py +93 -0
  20. cfdbender-0.4.2/src/cfdbender/geometry/__init__.py +1 -0
  21. cfdbender-0.4.2/src/cfdbender/geometry/blade_slicing.py +355 -0
  22. cfdbender-0.4.2/src/cfdbender/hpc/__init__.py +21 -0
  23. cfdbender-0.4.2/src/cfdbender/hpc/_plan.py +266 -0
  24. cfdbender-0.4.2/src/cfdbender/hpc/_profiles.py +305 -0
  25. cfdbender-0.4.2/src/cfdbender/hpc/_render.py +271 -0
  26. cfdbender-0.4.2/src/cfdbender/hpc/_submit.py +96 -0
  27. cfdbender-0.4.2/src/cfdbender/hpc/_walltime.py +301 -0
  28. cfdbender-0.4.2/src/cfdbender/matrix/__init__.py +1 -0
  29. cfdbender-0.4.2/src/cfdbender/matrix/cli.py +228 -0
  30. cfdbender-0.4.2/src/cfdbender/matrix/collection.py +251 -0
  31. cfdbender-0.4.2/src/cfdbender/matrix/exports.py +122 -0
  32. cfdbender-0.4.2/src/cfdbender/matrix/rerun.py +126 -0
  33. cfdbender-0.4.2/src/cfdbender/matrix/selection.py +62 -0
  34. cfdbender-0.4.2/src/cfdbender/matrix/submission.py +272 -0
  35. cfdbender-0.4.2/src/cfdbender/solvers/__init__.py +47 -0
  36. cfdbender-0.4.2/src/cfdbender/solvers/_host/__init__.py +1 -0
  37. cfdbender-0.4.2/src/cfdbender/solvers/_host/_config.py +10 -0
  38. cfdbender-0.4.2/src/cfdbender/solvers/_host/_execute.py +52 -0
  39. cfdbender-0.4.2/src/cfdbender/solvers/_host/_mesh.py +62 -0
  40. cfdbender-0.4.2/src/cfdbender/solvers/_host/_ram.py +69 -0
  41. cfdbender-0.4.2/src/cfdbender/solvers/_host/_single.py +63 -0
  42. cfdbender-0.4.2/src/cfdbender/solvers/flightstream/__init__.py +114 -0
  43. cfdbender-0.4.2/src/cfdbender/solvers/flightstream/reader.py +191 -0
  44. cfdbender-0.4.2/src/cfdbender/solvers/mock/__init__.py +273 -0
  45. cfdbender-0.4.2/src/cfdbender/solvers/openfoam/__init__.py +201 -0
  46. cfdbender-0.4.2/src/cfdbender/solvers/openfoam/_config.py +410 -0
  47. cfdbender-0.4.2/src/cfdbender/solvers/openfoam/_execute.py +162 -0
  48. cfdbender-0.4.2/src/cfdbender/solvers/openfoam/_history.py +158 -0
  49. cfdbender-0.4.2/src/cfdbender/solvers/pyfr/__init__.py +118 -0
  50. cfdbender-0.4.2/src/cfdbender/solvers/pyfr/_config.py +196 -0
  51. cfdbender-0.4.2/src/cfdbender/solvers/pyfr/_execute.py +127 -0
  52. cfdbender-0.4.2/src/cfdbender/solvers/pyfr/_history.py +88 -0
  53. cfdbender-0.4.2/src/cfdbender/solvers/qprop/__init__.py +303 -0
  54. cfdbender-0.4.2/src/cfdbender/solvers/qprop/_config.py +259 -0
  55. cfdbender-0.4.2/src/cfdbender/solvers/qprop/_execute.py +269 -0
  56. cfdbender-0.4.2/src/cfdbender/solvers/qprop/_output.py +64 -0
  57. cfdbender-0.4.2/src/cfdbender/solvers/qprop/_polar.py +98 -0
  58. cfdbender-0.4.2/src/cfdbender/solvers/qprop/_prop.py +81 -0
  59. cfdbender-0.4.2/src/cfdbender/solvers/qprop/_sections.py +193 -0
  60. cfdbender-0.4.2/src/cfdbender/solvers/su2/__init__.py +210 -0
  61. cfdbender-0.4.2/src/cfdbender/solvers/su2/_config.py +290 -0
  62. cfdbender-0.4.2/src/cfdbender/solvers/su2/_execute.py +196 -0
  63. cfdbender-0.4.2/src/cfdbender/solvers/su2/_history.py +117 -0
  64. cfdbender-0.4.2/src/cfdbender/solvers/su2/_pysu2_worker.py +25 -0
  65. cfdbender-0.4.2/src/cfdbender/solvers/su2/_ram.py +13 -0
  66. cfdbender-0.4.2/src/cfdbender/solvers/su2/_reference.py +79 -0
  67. cfdbender-0.4.2/src/cfdbender/solvers/su2/_single.py +3 -0
  68. cfdbender-0.4.2/src/cfdbender/solvers/su2/routes.py +61 -0
  69. cfdbender-0.4.2/src/cfdbender/solvers/xfoil/__init__.py +171 -0
  70. cfdbender-0.4.2/src/cfdbender/solvers/xfoil/_config.py +144 -0
  71. cfdbender-0.4.2/src/cfdbender/solvers/xfoil/_execute.py +227 -0
  72. cfdbender-0.4.2/src/cfdbender/solvers/xfoil/_polar.py +88 -0
  73. cfdbender-0.4.2/src/cfdbender/testing/__init__.py +301 -0
  74. cfdbender-0.4.2/src/cfdbender/workspace/__init__.py +1 -0
  75. cfdbender-0.4.2/src/cfdbender/workspace/cli.py +99 -0
  76. cfdbender-0.4.2/src/cfdbender/workspace/planning.py +38 -0
  77. cfdbender-0.4.2/src/cfdbender.egg-info/PKG-INFO +57 -0
  78. cfdbender-0.4.2/src/cfdbender.egg-info/SOURCES.txt +81 -0
  79. cfdbender-0.4.2/src/cfdbender.egg-info/dependency_links.txt +1 -0
  80. cfdbender-0.4.2/src/cfdbender.egg-info/entry_points.txt +3 -0
  81. cfdbender-0.4.2/src/cfdbender.egg-info/requires.txt +19 -0
  82. cfdbender-0.4.2/src/cfdbender.egg-info/top_level.txt +1 -0
  83. cfdbender-0.4.2/tests/test_import.py +9 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Geovana Neves
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,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: cfdbender
3
+ Version: 0.4.2
4
+ Summary: Solver-agnostic Python workspace for CFD studies (SU2 first)
5
+ Author: Geovana Neves
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Provides-Extra: flightstream
11
+ Requires-Dist: pyflightstream<1,>=0.56; extra == "flightstream"
12
+ Provides-Extra: test
13
+ Requires-Dist: pytest>=8; extra == "test"
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=8; extra == "dev"
16
+ Requires-Dist: ruff>=0.11; extra == "dev"
17
+ Requires-Dist: mypy>=1.15; extra == "dev"
18
+ Requires-Dist: build>=1.2; extra == "dev"
19
+ Requires-Dist: setuptools>=68; extra == "dev"
20
+ Requires-Dist: gmsh==4.15.2; extra == "dev"
21
+ Provides-Extra: docs
22
+ Requires-Dist: properdocs<2,>=1.6; extra == "docs"
23
+ Requires-Dist: mkdocs-material<10,>=9; extra == "docs"
24
+ Requires-Dist: mkdocs-gen-files<1,>=0.5; extra == "docs"
25
+ Dynamic: license-file
26
+
27
+ # cfdbender
28
+
29
+ cfdbender is an early Python project for CFD workspaces. Version 0.4.2 provides
30
+ workspace initialization, named s/r/p matrices, read-only planning, local runs,
31
+ neutral result collection, mock and SU2 adapters (the SU2 executable route and
32
+ the pysu2 Python wrapper route, run in a child interpreter where the wrapper is
33
+ installed), FlightStream workspaces delegated to pyflightstream, ESI OpenFOAM,
34
+ XFOIL, PyFR, QPROP, and HPC profiles
35
+ with plan/run/collect and --hpc. It includes a draft SRS and documentation.
36
+ Grouped HPC jobs (--batch) for SU2 are not implemented.
37
+
38
+ ```console
39
+ cfd-workspace init --solver mock --workspace campaign
40
+ ```
41
+
42
+ ## FlightStream
43
+
44
+ Install the optional FlightStream support with `pip install cfdbender[flightstream]`.
45
+ See [FlightStream workspaces](docs/flightstream-workspaces.md) for initialization
46
+ and the delegated commands.
47
+
48
+ The design keeps the first level independent of any solver.
49
+ Each workspace declares one solver in its root `init.toml`.
50
+ Supported solvers are SU2, FlightStream, OpenFOAM (ESI), XFOIL, PyFR and QPROP. Fluent and
51
+ other solvers are on the roadmap. See the [OpenFOAM](docs/openfoam-workspaces.md),
52
+ [XFOIL](docs/xfoil-workspaces.md), [PyFR](docs/pyfr-workspaces.md) and
53
+ [QPROP](docs/qprop-workspaces.md) workspace guides.
54
+
55
+ See the [documentation site](https://nevesgeovana.github.io/cfdbender/) and
56
+ the [workspace files](docs/workspace-files.md). This project is licensed under
57
+ the MIT license.
@@ -0,0 +1,31 @@
1
+ # cfdbender
2
+
3
+ cfdbender is an early Python project for CFD workspaces. Version 0.4.2 provides
4
+ workspace initialization, named s/r/p matrices, read-only planning, local runs,
5
+ neutral result collection, mock and SU2 adapters (the SU2 executable route and
6
+ the pysu2 Python wrapper route, run in a child interpreter where the wrapper is
7
+ installed), FlightStream workspaces delegated to pyflightstream, ESI OpenFOAM,
8
+ XFOIL, PyFR, QPROP, and HPC profiles
9
+ with plan/run/collect and --hpc. It includes a draft SRS and documentation.
10
+ Grouped HPC jobs (--batch) for SU2 are not implemented.
11
+
12
+ ```console
13
+ cfd-workspace init --solver mock --workspace campaign
14
+ ```
15
+
16
+ ## FlightStream
17
+
18
+ Install the optional FlightStream support with `pip install cfdbender[flightstream]`.
19
+ See [FlightStream workspaces](docs/flightstream-workspaces.md) for initialization
20
+ and the delegated commands.
21
+
22
+ The design keeps the first level independent of any solver.
23
+ Each workspace declares one solver in its root `init.toml`.
24
+ Supported solvers are SU2, FlightStream, OpenFOAM (ESI), XFOIL, PyFR and QPROP. Fluent and
25
+ other solvers are on the roadmap. See the [OpenFOAM](docs/openfoam-workspaces.md),
26
+ [XFOIL](docs/xfoil-workspaces.md), [PyFR](docs/pyfr-workspaces.md) and
27
+ [QPROP](docs/qprop-workspaces.md) workspace guides.
28
+
29
+ See the [documentation site](https://nevesgeovana.github.io/cfdbender/) and
30
+ the [workspace files](docs/workspace-files.md). This project is licensed under
31
+ the MIT license.
@@ -0,0 +1,60 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cfdbender"
7
+ version = "0.4.2"
8
+ description = "Solver-agnostic Python workspace for CFD studies (SU2 first)"
9
+ readme = "README.md"
10
+ authors = [{name = "Geovana Neves"}]
11
+ requires-python = ">=3.12"
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ dependencies = []
15
+
16
+ [project.scripts]
17
+ cfd-workspace = "cfdbender.workspace.cli:main"
18
+ cfd-matrix = "cfdbender.matrix.cli:main"
19
+
20
+ [project.optional-dependencies]
21
+ flightstream = ["pyflightstream>=0.56,<1"]
22
+ test = ["pytest>=8"]
23
+ dev = ["pytest>=8", "ruff>=0.11", "mypy>=1.15", "build>=1.2", "setuptools>=68", "gmsh==4.15.2"]
24
+ docs = ["properdocs>=1.6,<2", "mkdocs-material>=9,<10", "mkdocs-gen-files>=0.5,<1"]
25
+
26
+ [tool.setuptools.packages.find]
27
+ where = ["src"]
28
+
29
+ [tool.pytest.ini_options]
30
+ testpaths = ["tests"]
31
+ pythonpath = ["src"]
32
+
33
+ [tool.mypy]
34
+ files = ["src/cfdbender"]
35
+ strict = true
36
+
37
+ [[tool.mypy.overrides]]
38
+ # The optional FlightStream support: pyflightstream ships no type information and
39
+ # is absent from environments without the extra (hosted CI), so its imports in
40
+ # cfdbender._pyfs are untyped either way.
41
+ module = ["pyflightstream", "pyflightstream.*"]
42
+ ignore_missing_imports = true
43
+
44
+ [tool.ruff]
45
+ line-length = 100
46
+ target-version = "py312"
47
+ src = ["src"]
48
+ extend-exclude = ["*.md"]
49
+ force-exclude = true
50
+
51
+ [tool.ruff.lint]
52
+ select = ["E", "F", "W", "I", "UP", "B", "N", "D"]
53
+ extend-select = ["D417"]
54
+ ignore = ["N803", "N806"]
55
+
56
+ [tool.ruff.lint.pydocstyle]
57
+ convention = "numpy"
58
+
59
+ [tool.ruff.lint.per-file-ignores]
60
+ "tests/**/*" = ["D"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,7 @@
1
+ """cfdbender: a solver-agnostic Python workspace for CFD studies.
2
+
3
+ Usage: ``import cfdbender as cb``.
4
+ """
5
+
6
+ __version__ = "0.4.2"
7
+ __all__ = ["__version__"]
@@ -0,0 +1,92 @@
1
+ """Lazy access to pyflightstream's public workspace and console entry points."""
2
+
3
+ from collections.abc import Callable
4
+ from pathlib import Path
5
+ from typing import Any, cast
6
+
7
+ from cfdbender.core.settings import WorkspaceError
8
+
9
+ _INSTALL = "install the FlightStream support: pip install cfdbender[flightstream]"
10
+
11
+
12
+ def _workspace_type() -> type[Any]:
13
+ try:
14
+ from pyflightstream.workspace import CampaignWorkspace
15
+ except ModuleNotFoundError as error:
16
+ if error.name not in {"pyflightstream", "pyflightstream.workspace"}:
17
+ raise
18
+ raise WorkspaceError(_INSTALL) from error
19
+ return cast(type[Any], CampaignWorkspace)
20
+
21
+
22
+ def require_support() -> None:
23
+ """Refuse with the install instruction when the optional engine is absent."""
24
+ _workspace_type()
25
+
26
+
27
+ def init_workspace(root: Path) -> None:
28
+ """Create the upstream workspace tree through its exported workspace class.
29
+
30
+ Parameters
31
+ ----------
32
+ root : Path
33
+ Campaign directory passed unchanged to CampaignWorkspace.init.
34
+ """
35
+ _workspace_type().init(root)
36
+
37
+
38
+ def matrix_main(argv: list[str]) -> int:
39
+ """Call the pyfs-matrix console target with unchanged arguments.
40
+
41
+ Parameters
42
+ ----------
43
+ argv : list[str]
44
+ Arguments excluding the executable name.
45
+
46
+ Returns
47
+ -------
48
+ int
49
+ Upstream exit status; argparse SystemExit propagates unchanged.
50
+ """
51
+ require_support()
52
+ from pyflightstream.run.cli import main
53
+
54
+ return cast(Callable[[list[str]], int], main)(argv)
55
+
56
+
57
+ def workspace_main(argv: list[str]) -> int:
58
+ """Call the pyfs-workspace console target with unchanged arguments.
59
+
60
+ Parameters
61
+ ----------
62
+ argv : list[str]
63
+ Arguments excluding the executable name.
64
+
65
+ Returns
66
+ -------
67
+ int
68
+ Upstream exit status; argparse SystemExit propagates unchanged.
69
+ """
70
+ require_support()
71
+ from pyflightstream.workspace.cli import main
72
+
73
+ return cast(Callable[[list[str]], int], main)(argv)
74
+
75
+
76
+ def read_ledger(root: Path) -> Any:
77
+ """Read the upstream public ledger without writing campaign products.
78
+
79
+ Parameters
80
+ ----------
81
+ root : Path
82
+ FlightStream workspace directory.
83
+
84
+ Returns
85
+ -------
86
+ Any
87
+ Upstream Ledger, whose public points and card methods return dictionaries.
88
+ """
89
+ require_support()
90
+ from pyflightstream.workspace.ledger import read_ledger
91
+
92
+ return read_ledger(root)
@@ -0,0 +1,13 @@
1
+ """Solver-independent workspace declarations and validation."""
2
+
3
+ from cfdbender.core.settings import WorkspaceConfig, WorkspaceError, read_init
4
+ from cfdbender.core.workspace import INPUT_KINDS, init_workspace, input_kinds
5
+
6
+ __all__ = [
7
+ "INPUT_KINDS",
8
+ "WorkspaceConfig",
9
+ "WorkspaceError",
10
+ "init_workspace",
11
+ "input_kinds",
12
+ "read_init",
13
+ ]
@@ -0,0 +1,148 @@
1
+ """Define an injected adapter contract without importing a solver.
2
+
3
+ Adapters expose these functions at their registered module boundary. Planning
4
+ calls validate_row(row, workspace), where workspace is the existing RowInputs
5
+ tracked reader. It must only read and validate. Every extra input is read through
6
+ that reader. translate returns deterministic ASCII from the prepared s/r/p inputs.
7
+ execute writes that input, runs the solver and reads history; it must call
8
+ check_ram before and during work and refuse existing output files. classify
9
+ requires numerical evidence; collect reads the outputs into NeutralResult.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import hashlib
15
+ from collections.abc import Callable, Mapping
16
+ from dataclasses import dataclass
17
+ from pathlib import Path
18
+ from typing import Protocol, runtime_checkable
19
+
20
+ from cfdbender.core.matrix import MatrixRow
21
+ from cfdbender.core.plan import InputFiles, Point, RowInputs, RowRequirements, apply_variables
22
+ from cfdbender.core.results import Classification, ExecutionResult, NeutralResult
23
+ from cfdbender.core.settings import read_init
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class AdapterPoint:
28
+ """A planned point and its workspace, with digest-checked s/r/p snapshots."""
29
+
30
+ root: Path
31
+ point: Point
32
+ solver: str
33
+ setup: Mapping[str, object]
34
+ reference: Mapping[str, object]
35
+ post: Mapping[str, object]
36
+
37
+ @property
38
+ def geometry(self) -> str | None:
39
+ """The workspace-relative GEOMETRY file of the row, or None."""
40
+ return self.point.geometry
41
+
42
+ def verify(self) -> None:
43
+ """Re-read init.toml and every planned input, refusing changed bytes."""
44
+ config = read_init(self.root, available_solvers=(self.solver,))
45
+ if config.solver != self.solver:
46
+ raise ValueError("init.toml solver differs from the planned solver")
47
+ files = InputFiles(self.root)
48
+ for name, digest in self.point.inputs_sha256.items():
49
+ if hashlib.sha256(files.read_bytes(name)).hexdigest() != digest:
50
+ raise ValueError(f"input changed after planning: {name}; plan again")
51
+
52
+
53
+ def load_point(root: str | Path, point: Point, *, solver: str) -> AdapterPoint:
54
+ """Read planned s/r/p snapshots, verifying all digests and the solver binding.
55
+
56
+ Parameters
57
+ ----------
58
+ root : str or Path
59
+ Workspace root.
60
+ point : Point
61
+ Point from the validated plan or registry.
62
+ solver : str
63
+ Expected init.toml solver, supplied by the composition layer.
64
+
65
+ Returns
66
+ -------
67
+ AdapterPoint
68
+ Prepared context. No solver is imported and no output is written.
69
+ """
70
+ target = Path(root).resolve()
71
+ files = InputFiles(target)
72
+ result = AdapterPoint(
73
+ target,
74
+ point,
75
+ solver,
76
+ apply_variables(files.read_toml(f"inputs/setups/{point.setup_id}.toml"), point.variables),
77
+ files.read_toml(f"inputs/references/{point.reference_id}.toml"),
78
+ files.read_toml(f"inputs/pproc/{point.post_id}.toml"),
79
+ )
80
+ result.verify()
81
+ for name, digest in files.digests().items():
82
+ if point.inputs_sha256.get(name) != digest:
83
+ raise ValueError(f"untracked or changed input: {name}")
84
+ return result
85
+
86
+
87
+ @runtime_checkable
88
+ class SolverAdapter(Protocol):
89
+ """Structural module protocol shared by real and licence-free adapters."""
90
+
91
+ def validate_row(self, row: MatrixRow, workspace: RowInputs) -> RowRequirements:
92
+ """Validate s/r/p and describe actions and output claims, without writes.
93
+
94
+ Parameters
95
+ ----------
96
+ row : MatrixRow
97
+ Parsed row, including conditions and sweep values.
98
+ workspace : RowInputs
99
+ Parsed s/r/p with tracked readers for all additional inputs.
100
+
101
+ Returns
102
+ -------
103
+ RowRequirements
104
+ Actions and output templates. Raise ValueError naming invalid input.
105
+ """
106
+ ...
107
+
108
+ def translate(self, point: AdapterPoint) -> str:
109
+ """Return deterministic ASCII solver input from a verified point.
110
+
111
+ Parameters
112
+ ----------
113
+ point : AdapterPoint
114
+ Planned point with s/r/p data and workspace binding.
115
+ """
116
+ ...
117
+
118
+ def execute(self, point: AdapterPoint, *, check_ram: Callable[[], None]) -> ExecutionResult:
119
+ """Write input, execute once and read history, checking RAM throughout.
120
+
121
+ Parameters
122
+ ----------
123
+ point : AdapterPoint
124
+ Planned point with s/r/p data and workspace binding.
125
+ check_ram : callable
126
+ Raises on unavailable RAM or a threatened 0.5 GiB free floor.
127
+ """
128
+ ...
129
+
130
+ def classify(self, result: ExecutionResult) -> Classification:
131
+ """Classify numerical evidence, never inferring convergence from exit zero.
132
+
133
+ Parameters
134
+ ----------
135
+ result : ExecutionResult
136
+ Process outcome, history, iteration limit and version.
137
+ """
138
+ ...
139
+
140
+ def collect(self, point: AdapterPoint) -> NeutralResult:
141
+ """Read saved results with explicit coefficient axes and references.
142
+
143
+ Parameters
144
+ ----------
145
+ point : AdapterPoint
146
+ Recorded point and the workspace holding its outputs.
147
+ """
148
+ ...
@@ -0,0 +1,157 @@
1
+ """Resolve a row's SOLVER_BUILD to this machine's executable for a local run.
2
+
3
+ ``inputs/executables.toml`` declares, per solver, the builds a matrix may name,
4
+ and ``inputs/executables.local.toml`` beside it (kept out of version control)
5
+ gives this machine's paths for builds the first file declares::
6
+
7
+ [su2]
8
+ "8.3.0" = "/opt/su2-8.3.0/bin/SU2_CFD"
9
+ "8.3.0-mpi" = { path = "/opt/su2-8.3.0/bin/SU2_CFD", launcher = ["mpirun", "-np", "8"] }
10
+
11
+ A bare string is the path; a table holds ``path`` and an optional ``launcher``
12
+ list. A local entry replaces the fields it states and may not add a build. A
13
+ relative path resolves from the workspace root. A cluster job takes its build
14
+ from the HPC profile's ``[builds]`` table instead; these files serve local runs.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import tomllib
20
+ from collections.abc import Mapping
21
+ from dataclasses import dataclass, replace
22
+ from pathlib import Path
23
+
24
+ from cfdbender.core.adapter import AdapterPoint
25
+ from cfdbender.core.settings import WorkspaceError
26
+
27
+ DECLARED = "inputs/executables.toml"
28
+ LOCAL = "inputs/executables.local.toml"
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class Executable:
33
+ """One build's executable path and launcher tokens on this machine."""
34
+
35
+ build: str
36
+ path: str
37
+ launcher: tuple[str, ...] = ()
38
+
39
+
40
+ def _read(path: Path) -> Mapping[str, object]:
41
+ try:
42
+ with path.open("rb") as stream:
43
+ return tomllib.load(stream)
44
+ except FileNotFoundError:
45
+ return {}
46
+ except (OSError, tomllib.TOMLDecodeError) as error:
47
+ raise WorkspaceError(f"{path}: cannot read executables: {error}") from error
48
+
49
+
50
+ def _entry(value: object, where: str) -> dict[str, object]:
51
+ if isinstance(value, str) and value:
52
+ return {"path": value}
53
+ if not isinstance(value, dict) or set(value) - {"path", "launcher"}:
54
+ raise WorkspaceError(f"{where}: give a path, or a table of path and launcher")
55
+ launcher = value.get("launcher", [])
56
+ if not isinstance(launcher, list) or not all(isinstance(t, str) and t for t in launcher):
57
+ raise WorkspaceError(f"{where}: launcher must be a list of strings")
58
+ if "path" in value and (not isinstance(value["path"], str) or not value["path"]):
59
+ raise WorkspaceError(f"{where}: path must be a non-empty string")
60
+ return dict(value)
61
+
62
+
63
+ def bind_executable(point: AdapterPoint, adapter: object) -> AdapterPoint:
64
+ """Return the point with its build's executable in the setup's [solver] table.
65
+
66
+ The adapter's EXECUTABLE_KEYS maps ``path`` and ``launcher`` to its own
67
+ [solver] option names, and optional BUILD_OPTIONS adds fixed options (SU2
68
+ selects its executable route). A point without SOLVER_BUILD, a workspace
69
+ without inputs/executables.toml, or an adapter without EXECUTABLE_KEYS keeps
70
+ the setup's [solver] table as written.
71
+
72
+ Parameters
73
+ ----------
74
+ point : AdapterPoint
75
+ Prepared, digest-checked point.
76
+ adapter : object
77
+ The workspace's adapter module.
78
+
79
+ Returns
80
+ -------
81
+ AdapterPoint
82
+ The point, or a copy whose setup carries the build's options.
83
+ """
84
+ keys = getattr(adapter, "EXECUTABLE_KEYS", None)
85
+ build = point.point.solver_build
86
+ if keys is None or build is None or not has_registry(point.root):
87
+ return point
88
+ found = resolve_executable(point.root, point.solver, build)
89
+ table = point.setup.get("solver", {})
90
+ solver = dict(table) if isinstance(table, Mapping) else {}
91
+ solver.update(getattr(adapter, "BUILD_OPTIONS", {}))
92
+ solver[keys["path"]] = found.path
93
+ if found.launcher:
94
+ solver[keys["launcher"]] = list(found.launcher)
95
+ return replace(point, setup={**point.setup, "solver": solver})
96
+
97
+
98
+ def has_registry(root: Path) -> bool:
99
+ """Return True when the workspace declares inputs/executables.toml."""
100
+ return (root / DECLARED).is_file()
101
+
102
+
103
+ def resolve_executable(root: Path, solver: str, build: str) -> Executable:
104
+ """Return the executable a local run of ``build`` uses.
105
+
106
+ Parameters
107
+ ----------
108
+ root : Path
109
+ Workspace root.
110
+ solver : str
111
+ The init.toml solver; its table in the files is read.
112
+ build : str
113
+ The row's SOLVER_BUILD.
114
+
115
+ Returns
116
+ -------
117
+ Executable
118
+ The declared entry with this machine's overlay applied.
119
+
120
+ Raises
121
+ ------
122
+ WorkspaceError
123
+ A missing file or build, a local build not declared, or a malformed entry.
124
+ """
125
+ declared_file = root / DECLARED
126
+ if not declared_file.is_file():
127
+ raise WorkspaceError(
128
+ f"SOLVER_BUILD {build!r}: {DECLARED} does not exist; declare the build there"
129
+ )
130
+ tables = []
131
+ for name in (DECLARED, LOCAL):
132
+ table = _read(root / name).get(solver, {})
133
+ if not isinstance(table, dict):
134
+ raise WorkspaceError(f"{name}: [{solver}] must be a table of builds")
135
+ tables.append(table)
136
+ declared, local = tables
137
+ if extra := sorted(set(local) - set(declared)):
138
+ raise WorkspaceError(
139
+ f"{LOCAL}: build {extra[0]!r} of [{solver}] is not declared in {DECLARED}"
140
+ )
141
+ if build not in declared:
142
+ known = ", ".join(sorted(declared)) or "none"
143
+ raise WorkspaceError(
144
+ f"SOLVER_BUILD {build!r} is not declared under [{solver}] in {DECLARED} "
145
+ f"(declared: {known}); add it with its executable path"
146
+ )
147
+ entry = _entry(declared[build], f"{DECLARED} [{solver}] {build!r}")
148
+ if build in local:
149
+ entry.update(_entry(local[build], f"{LOCAL} [{solver}] {build!r}"))
150
+ if "path" not in entry:
151
+ raise WorkspaceError(f"{DECLARED} [{solver}] {build!r}: no path")
152
+ path = Path(str(entry["path"])).expanduser()
153
+ if not path.is_absolute() and any(sep in str(entry["path"]) for sep in "/\\"):
154
+ path = root / path
155
+ launcher = entry.get("launcher", [])
156
+ assert isinstance(launcher, list)
157
+ return Executable(build, str(path), tuple(str(token) for token in launcher))