cfdbender 0.4.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. cfdbender/__init__.py +7 -0
  2. cfdbender/_pyfs.py +92 -0
  3. cfdbender/core/__init__.py +13 -0
  4. cfdbender/core/adapter.py +148 -0
  5. cfdbender/core/executables.py +157 -0
  6. cfdbender/core/flight.py +346 -0
  7. cfdbender/core/matrix.py +354 -0
  8. cfdbender/core/naming.py +172 -0
  9. cfdbender/core/plan.py +463 -0
  10. cfdbender/core/registry.py +735 -0
  11. cfdbender/core/results.py +117 -0
  12. cfdbender/core/run.py +150 -0
  13. cfdbender/core/settings.py +92 -0
  14. cfdbender/core/workspace.py +93 -0
  15. cfdbender/geometry/__init__.py +1 -0
  16. cfdbender/geometry/blade_slicing.py +355 -0
  17. cfdbender/hpc/__init__.py +21 -0
  18. cfdbender/hpc/_plan.py +266 -0
  19. cfdbender/hpc/_profiles.py +305 -0
  20. cfdbender/hpc/_render.py +271 -0
  21. cfdbender/hpc/_submit.py +96 -0
  22. cfdbender/hpc/_walltime.py +301 -0
  23. cfdbender/matrix/__init__.py +1 -0
  24. cfdbender/matrix/cli.py +228 -0
  25. cfdbender/matrix/collection.py +251 -0
  26. cfdbender/matrix/exports.py +122 -0
  27. cfdbender/matrix/rerun.py +126 -0
  28. cfdbender/matrix/selection.py +62 -0
  29. cfdbender/matrix/submission.py +272 -0
  30. cfdbender/solvers/__init__.py +47 -0
  31. cfdbender/solvers/_host/__init__.py +1 -0
  32. cfdbender/solvers/_host/_config.py +10 -0
  33. cfdbender/solvers/_host/_execute.py +52 -0
  34. cfdbender/solvers/_host/_mesh.py +62 -0
  35. cfdbender/solvers/_host/_ram.py +69 -0
  36. cfdbender/solvers/_host/_single.py +63 -0
  37. cfdbender/solvers/flightstream/__init__.py +114 -0
  38. cfdbender/solvers/flightstream/reader.py +191 -0
  39. cfdbender/solvers/mock/__init__.py +273 -0
  40. cfdbender/solvers/openfoam/__init__.py +201 -0
  41. cfdbender/solvers/openfoam/_config.py +410 -0
  42. cfdbender/solvers/openfoam/_execute.py +162 -0
  43. cfdbender/solvers/openfoam/_history.py +158 -0
  44. cfdbender/solvers/pyfr/__init__.py +118 -0
  45. cfdbender/solvers/pyfr/_config.py +196 -0
  46. cfdbender/solvers/pyfr/_execute.py +127 -0
  47. cfdbender/solvers/pyfr/_history.py +88 -0
  48. cfdbender/solvers/qprop/__init__.py +303 -0
  49. cfdbender/solvers/qprop/_config.py +259 -0
  50. cfdbender/solvers/qprop/_execute.py +269 -0
  51. cfdbender/solvers/qprop/_output.py +64 -0
  52. cfdbender/solvers/qprop/_polar.py +98 -0
  53. cfdbender/solvers/qprop/_prop.py +81 -0
  54. cfdbender/solvers/qprop/_sections.py +193 -0
  55. cfdbender/solvers/su2/__init__.py +210 -0
  56. cfdbender/solvers/su2/_config.py +290 -0
  57. cfdbender/solvers/su2/_execute.py +196 -0
  58. cfdbender/solvers/su2/_history.py +117 -0
  59. cfdbender/solvers/su2/_pysu2_worker.py +25 -0
  60. cfdbender/solvers/su2/_ram.py +13 -0
  61. cfdbender/solvers/su2/_reference.py +79 -0
  62. cfdbender/solvers/su2/_single.py +3 -0
  63. cfdbender/solvers/su2/routes.py +61 -0
  64. cfdbender/solvers/xfoil/__init__.py +171 -0
  65. cfdbender/solvers/xfoil/_config.py +144 -0
  66. cfdbender/solvers/xfoil/_execute.py +227 -0
  67. cfdbender/solvers/xfoil/_polar.py +88 -0
  68. cfdbender/testing/__init__.py +301 -0
  69. cfdbender/workspace/__init__.py +1 -0
  70. cfdbender/workspace/cli.py +99 -0
  71. cfdbender/workspace/planning.py +38 -0
  72. cfdbender-0.4.2.dist-info/METADATA +57 -0
  73. cfdbender-0.4.2.dist-info/RECORD +77 -0
  74. cfdbender-0.4.2.dist-info/WHEEL +5 -0
  75. cfdbender-0.4.2.dist-info/entry_points.txt +3 -0
  76. cfdbender-0.4.2.dist-info/licenses/LICENSE +21 -0
  77. cfdbender-0.4.2.dist-info/top_level.txt +1 -0
cfdbender/__init__.py ADDED
@@ -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__"]
cfdbender/_pyfs.py ADDED
@@ -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))