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.
- cfdbender/__init__.py +7 -0
- cfdbender/_pyfs.py +92 -0
- cfdbender/core/__init__.py +13 -0
- cfdbender/core/adapter.py +148 -0
- cfdbender/core/executables.py +157 -0
- cfdbender/core/flight.py +346 -0
- cfdbender/core/matrix.py +354 -0
- cfdbender/core/naming.py +172 -0
- cfdbender/core/plan.py +463 -0
- cfdbender/core/registry.py +735 -0
- cfdbender/core/results.py +117 -0
- cfdbender/core/run.py +150 -0
- cfdbender/core/settings.py +92 -0
- cfdbender/core/workspace.py +93 -0
- cfdbender/geometry/__init__.py +1 -0
- cfdbender/geometry/blade_slicing.py +355 -0
- cfdbender/hpc/__init__.py +21 -0
- cfdbender/hpc/_plan.py +266 -0
- cfdbender/hpc/_profiles.py +305 -0
- cfdbender/hpc/_render.py +271 -0
- cfdbender/hpc/_submit.py +96 -0
- cfdbender/hpc/_walltime.py +301 -0
- cfdbender/matrix/__init__.py +1 -0
- cfdbender/matrix/cli.py +228 -0
- cfdbender/matrix/collection.py +251 -0
- cfdbender/matrix/exports.py +122 -0
- cfdbender/matrix/rerun.py +126 -0
- cfdbender/matrix/selection.py +62 -0
- cfdbender/matrix/submission.py +272 -0
- cfdbender/solvers/__init__.py +47 -0
- cfdbender/solvers/_host/__init__.py +1 -0
- cfdbender/solvers/_host/_config.py +10 -0
- cfdbender/solvers/_host/_execute.py +52 -0
- cfdbender/solvers/_host/_mesh.py +62 -0
- cfdbender/solvers/_host/_ram.py +69 -0
- cfdbender/solvers/_host/_single.py +63 -0
- cfdbender/solvers/flightstream/__init__.py +114 -0
- cfdbender/solvers/flightstream/reader.py +191 -0
- cfdbender/solvers/mock/__init__.py +273 -0
- cfdbender/solvers/openfoam/__init__.py +201 -0
- cfdbender/solvers/openfoam/_config.py +410 -0
- cfdbender/solvers/openfoam/_execute.py +162 -0
- cfdbender/solvers/openfoam/_history.py +158 -0
- cfdbender/solvers/pyfr/__init__.py +118 -0
- cfdbender/solvers/pyfr/_config.py +196 -0
- cfdbender/solvers/pyfr/_execute.py +127 -0
- cfdbender/solvers/pyfr/_history.py +88 -0
- cfdbender/solvers/qprop/__init__.py +303 -0
- cfdbender/solvers/qprop/_config.py +259 -0
- cfdbender/solvers/qprop/_execute.py +269 -0
- cfdbender/solvers/qprop/_output.py +64 -0
- cfdbender/solvers/qprop/_polar.py +98 -0
- cfdbender/solvers/qprop/_prop.py +81 -0
- cfdbender/solvers/qprop/_sections.py +193 -0
- cfdbender/solvers/su2/__init__.py +210 -0
- cfdbender/solvers/su2/_config.py +290 -0
- cfdbender/solvers/su2/_execute.py +196 -0
- cfdbender/solvers/su2/_history.py +117 -0
- cfdbender/solvers/su2/_pysu2_worker.py +25 -0
- cfdbender/solvers/su2/_ram.py +13 -0
- cfdbender/solvers/su2/_reference.py +79 -0
- cfdbender/solvers/su2/_single.py +3 -0
- cfdbender/solvers/su2/routes.py +61 -0
- cfdbender/solvers/xfoil/__init__.py +171 -0
- cfdbender/solvers/xfoil/_config.py +144 -0
- cfdbender/solvers/xfoil/_execute.py +227 -0
- cfdbender/solvers/xfoil/_polar.py +88 -0
- cfdbender/testing/__init__.py +301 -0
- cfdbender/workspace/__init__.py +1 -0
- cfdbender/workspace/cli.py +99 -0
- cfdbender/workspace/planning.py +38 -0
- cfdbender-0.4.2.dist-info/METADATA +57 -0
- cfdbender-0.4.2.dist-info/RECORD +77 -0
- cfdbender-0.4.2.dist-info/WHEEL +5 -0
- cfdbender-0.4.2.dist-info/entry_points.txt +3 -0
- cfdbender-0.4.2.dist-info/licenses/LICENSE +21 -0
- cfdbender-0.4.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"""Numeric grouped walltime rules, independent of any solver or executor."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
BEST_FACTOR = 1.25
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class BudgetRow:
|
|
13
|
+
"""One row and its points, with budgets supplied by the planning caller."""
|
|
14
|
+
|
|
15
|
+
sim_id: str
|
|
16
|
+
run_ids: tuple[str, ...]
|
|
17
|
+
point_seconds: tuple[float | None, ...]
|
|
18
|
+
walltime_cell_s: float | None
|
|
19
|
+
walltime_cell_text: str | None
|
|
20
|
+
best: bool
|
|
21
|
+
margin_s: float
|
|
22
|
+
timeout_s: float | None = None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class BudgetGroup:
|
|
27
|
+
"""The rows of one job, in their input order."""
|
|
28
|
+
|
|
29
|
+
units: tuple[BudgetRow, ...]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _unestimated(split: BudgetGroup) -> list[str]:
|
|
33
|
+
"""Return the points with neither a recorded estimate nor a row cell to fall back on."""
|
|
34
|
+
return [
|
|
35
|
+
run_id
|
|
36
|
+
for unit in split.units
|
|
37
|
+
for run_id, seconds in zip(unit.run_ids, unit.point_seconds, strict=True)
|
|
38
|
+
if seconds is None and unit.walltime_cell_s is None
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def best_walltime_s(estimate_s: float, margin_s: float, factor: float = BEST_FACTOR) -> int:
|
|
43
|
+
"""Return the BEST walltime: ``factor x estimate + margin``, ceiled to the minute (FR-364).
|
|
44
|
+
|
|
45
|
+
Parameters
|
|
46
|
+
----------
|
|
47
|
+
estimate_s : float
|
|
48
|
+
The job's estimate in seconds.
|
|
49
|
+
margin_s : float
|
|
50
|
+
The walltime margin in seconds.
|
|
51
|
+
factor : float, optional
|
|
52
|
+
The safety factor, 1.25 by default.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
int
|
|
57
|
+
Whole seconds, a multiple of 60.
|
|
58
|
+
"""
|
|
59
|
+
return math.ceil((factor * estimate_s + margin_s) / 60.0 - 1e-9) * 60
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def walltime_text(seconds: int, *, split: BudgetGroup | None = None) -> str:
|
|
63
|
+
"""Return a job's wall clock as the WALLTIME cell writes it: whole minutes, else seconds.
|
|
64
|
+
|
|
65
|
+
Parameters
|
|
66
|
+
----------
|
|
67
|
+
seconds : int
|
|
68
|
+
The wall clock in seconds.
|
|
69
|
+
split : BudgetGroup or None, optional
|
|
70
|
+
Unused; kept so callers that pass the job keep working.
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
str
|
|
75
|
+
``<minutes>m`` when the seconds are whole minutes, else ``<seconds>s`` (``68s``), so a
|
|
76
|
+
clock summed from the rows' own cells is written exactly and never rounded up.
|
|
77
|
+
"""
|
|
78
|
+
del split
|
|
79
|
+
return f"{seconds // 60}m" if seconds % 60 == 0 else f"{seconds}s"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _minutes(seconds: float) -> str:
|
|
83
|
+
"""Return a duration in whole hours and minutes for a sentence."""
|
|
84
|
+
total = int(round(seconds / 60.0))
|
|
85
|
+
return f"{total // 60}h{total % 60:02d}m"
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _cells_of(split: BudgetGroup) -> list[BudgetRow]:
|
|
89
|
+
"""Return the rows of the job that state a wall clock of their own."""
|
|
90
|
+
return [unit for unit in split.units if unit.walltime_cell_s is not None]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _unstated_walltime(
|
|
94
|
+
split: BudgetGroup, cells: list[BudgetRow], max_walltime_s: float | None
|
|
95
|
+
) -> tuple[int | None, str, bool | None, float | None, list[str], str | None] | None:
|
|
96
|
+
"""Return the judgment of a job holding a row with no WALLTIME that is not BEST, else None.
|
|
97
|
+
|
|
98
|
+
A ROW THAT STATES NO WALL CLOCK AND IS NOT BEST adds nothing to the sum, so
|
|
99
|
+
the sum would bound its points at zero seconds: the job asks
|
|
100
|
+
the profile's limit, said, or is refused where there is none.
|
|
101
|
+
"""
|
|
102
|
+
unstated = [
|
|
103
|
+
unit.sim_id for unit in split.units if unit.walltime_cell_s is None and not unit.best
|
|
104
|
+
]
|
|
105
|
+
if not unstated:
|
|
106
|
+
return None
|
|
107
|
+
names = ", ".join(unstated)
|
|
108
|
+
if max_walltime_s is None:
|
|
109
|
+
return (
|
|
110
|
+
None,
|
|
111
|
+
"none",
|
|
112
|
+
None,
|
|
113
|
+
None,
|
|
114
|
+
[],
|
|
115
|
+
f"rows {names} state no WALLTIME and are not BEST, and share a job with rows "
|
|
116
|
+
f"that state one ({', '.join(unit.sim_id for unit in cells)}), so the job's "
|
|
117
|
+
"walltime cannot budget their points and the profile states no max_walltime "
|
|
118
|
+
"to ask for; write a wall clock with its unit or BEST in those rows.",
|
|
119
|
+
)
|
|
120
|
+
# The points no estimate prices are named too.
|
|
121
|
+
unpriced = _unestimated(split)
|
|
122
|
+
warning = (
|
|
123
|
+
f"rows {names} state no WALLTIME and are not BEST, so the cells of the job do not "
|
|
124
|
+
"budget their points; the job asks the profile's max_walltime."
|
|
125
|
+
+ (f" No estimate for {', '.join(unpriced)}." if unpriced else "")
|
|
126
|
+
)
|
|
127
|
+
return int(max_walltime_s), "max_walltime", None, None, [warning], None
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _need_of(split: BudgetGroup, estimate_s: float | None) -> int | None:
|
|
131
|
+
"""Return the walltime the job's estimate needs, or None where no point is priced."""
|
|
132
|
+
if estimate_s is None or not any(
|
|
133
|
+
value is not None for unit in split.units for value in unit.point_seconds
|
|
134
|
+
):
|
|
135
|
+
return None
|
|
136
|
+
return best_walltime_s(estimate_s, max(unit.margin_s for unit in split.units))
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _priced_seconds(split: BudgetGroup, cells: list[BudgetRow]) -> int | None:
|
|
140
|
+
"""Return the sum of the cells' budgets with every row priced, or None where one cannot be.
|
|
141
|
+
|
|
142
|
+
EVERY UNIT IS PRICED: a row that states no WALLTIME shares
|
|
143
|
+
the job and added 0 s, as BEST does by its estimate. None where such a row
|
|
144
|
+
has a point no estimate prices.
|
|
145
|
+
"""
|
|
146
|
+
seconds = int(sum((unit.walltime_cell_s or 0.0) * max(len(unit.run_ids), 1) for unit in cells))
|
|
147
|
+
for unit in split.units:
|
|
148
|
+
if unit.walltime_cell_s is None:
|
|
149
|
+
if any(value is None for value in unit.point_seconds):
|
|
150
|
+
return None
|
|
151
|
+
seconds += best_walltime_s(
|
|
152
|
+
sum(value for value in unit.point_seconds if value is not None), unit.margin_s
|
|
153
|
+
)
|
|
154
|
+
return seconds
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _cell_above_the_limit(cells: list[BudgetRow], max_walltime_s: float | None) -> str | None:
|
|
158
|
+
"""Return the refusal of the first row whose own WALLTIME cell is above the limit, else None."""
|
|
159
|
+
if max_walltime_s is None:
|
|
160
|
+
return None
|
|
161
|
+
for unit in cells:
|
|
162
|
+
if (unit.walltime_cell_s or 0.0) > max_walltime_s:
|
|
163
|
+
return (
|
|
164
|
+
f"the WALLTIME {unit.walltime_cell_text} of row {unit.sim_id} is above the "
|
|
165
|
+
f"cluster's max_walltime of {_minutes(max_walltime_s)}; write a cell the cluster "
|
|
166
|
+
"grants, or BEST."
|
|
167
|
+
)
|
|
168
|
+
return None
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _from_cells(
|
|
172
|
+
split: BudgetGroup, estimate_s: float | None, max_walltime_s: float | None
|
|
173
|
+
) -> tuple[int | None, str, bool | None, float | None, list[str], str | None]:
|
|
174
|
+
"""Return the walltime of a job whose rows state cells: the SUM of its points' budgets.
|
|
175
|
+
|
|
176
|
+
A row's WALLTIME cell is the budget of ONE of its points (it states the
|
|
177
|
+
wall clock a single datapoint is given), so a job that runs several points in
|
|
178
|
+
one instance asks for the sum over its points of their rows' cells. A sum above the
|
|
179
|
+
profile's ``max_walltime`` is capped there with a warning suggesting a larger ``n``; one
|
|
180
|
+
point's own cell above it is refused.
|
|
181
|
+
"""
|
|
182
|
+
cells = _cells_of(split)
|
|
183
|
+
warnings: list[str] = []
|
|
184
|
+
refusal = _cell_above_the_limit(cells, max_walltime_s)
|
|
185
|
+
if refusal is not None:
|
|
186
|
+
return None, "matrix", None, None, warnings, refusal
|
|
187
|
+
unstated = _unstated_walltime(split, cells, max_walltime_s)
|
|
188
|
+
if unstated is not None:
|
|
189
|
+
return unstated
|
|
190
|
+
priced = _priced_seconds(split, cells)
|
|
191
|
+
if priced is None:
|
|
192
|
+
return _from_estimate(split, None, max_walltime_s)
|
|
193
|
+
seconds = priced
|
|
194
|
+
if max_walltime_s is not None and seconds > max_walltime_s:
|
|
195
|
+
warnings.append(
|
|
196
|
+
f"the job's points ask {_minutes(seconds)} together, above the cluster's max_walltime "
|
|
197
|
+
f"of {_minutes(max_walltime_s)}; the job asks the maximum, and a larger --batch n "
|
|
198
|
+
"makes shorter jobs."
|
|
199
|
+
)
|
|
200
|
+
seconds = int(max_walltime_s)
|
|
201
|
+
# THE CAP IS COMPARED WITH THE ESTIMATE (F-263): the cells' sum above the limit does
|
|
202
|
+
# not say the job's estimated need does not fit under it.
|
|
203
|
+
need = _need_of(split, estimate_s)
|
|
204
|
+
if need is None:
|
|
205
|
+
return seconds, "max_walltime", False, None, warnings, None
|
|
206
|
+
if need <= seconds:
|
|
207
|
+
return seconds, "max_walltime", True, None, warnings, None
|
|
208
|
+
return seconds, "max_walltime", False, float(need - seconds), warnings, None
|
|
209
|
+
need = _need_of(split, estimate_s)
|
|
210
|
+
if need is None or estimate_s is None:
|
|
211
|
+
return seconds, "matrix", None, None, warnings, None
|
|
212
|
+
if need <= seconds:
|
|
213
|
+
return seconds, "matrix", True, None, warnings, None
|
|
214
|
+
short = float(need - seconds)
|
|
215
|
+
warnings.append(
|
|
216
|
+
f"the job's points ask {_minutes(seconds)} together and its estimate needs {need // 60}m "
|
|
217
|
+
f"(1.25 x {_minutes(estimate_s)} plus the margin), {_minutes(short)} short; the cells "
|
|
218
|
+
"are kept, and a larger --batch n makes shorter jobs."
|
|
219
|
+
)
|
|
220
|
+
return seconds, "matrix", False, short, warnings, None
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _from_estimate(
|
|
224
|
+
split: BudgetGroup, estimate_s: float | None, max_walltime_s: float | None
|
|
225
|
+
) -> tuple[int | None, str, bool | None, float | None, list[str], str | None]:
|
|
226
|
+
"""Return the walltime of an all-BEST job: its estimate, else the limit, else a block."""
|
|
227
|
+
if estimate_s is None:
|
|
228
|
+
names = ", ".join(_unestimated(split))
|
|
229
|
+
if max_walltime_s is None:
|
|
230
|
+
return (
|
|
231
|
+
None,
|
|
232
|
+
"none",
|
|
233
|
+
None,
|
|
234
|
+
None,
|
|
235
|
+
[],
|
|
236
|
+
f"no estimate for {names}, and the profile states no max_walltime to ask for; "
|
|
237
|
+
"write a wall clock with its unit in those rows, or run one point of the row "
|
|
238
|
+
"first so the fit has a sample.",
|
|
239
|
+
)
|
|
240
|
+
return (
|
|
241
|
+
int(max_walltime_s),
|
|
242
|
+
"max_walltime",
|
|
243
|
+
None,
|
|
244
|
+
None,
|
|
245
|
+
[f"no estimate for {names}; the job asks the profile's max_walltime."],
|
|
246
|
+
None,
|
|
247
|
+
)
|
|
248
|
+
wanted = best_walltime_s(estimate_s, max(unit.margin_s for unit in split.units))
|
|
249
|
+
if max_walltime_s is not None and wanted > max_walltime_s:
|
|
250
|
+
short = wanted - max_walltime_s
|
|
251
|
+
return (
|
|
252
|
+
int(max_walltime_s),
|
|
253
|
+
"max_walltime",
|
|
254
|
+
False,
|
|
255
|
+
float(short),
|
|
256
|
+
[
|
|
257
|
+
f"BEST asks {wanted // 60}m, above the cluster's max_walltime of "
|
|
258
|
+
f"{_minutes(max_walltime_s)}, so the job asks the limit and is {_minutes(short)} "
|
|
259
|
+
"short; a larger --batch n makes shorter jobs."
|
|
260
|
+
],
|
|
261
|
+
None,
|
|
262
|
+
)
|
|
263
|
+
return wanted, "BEST", True, None, [], None
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def job_walltime(
|
|
267
|
+
split: BudgetGroup, estimate_s: float | None, *, max_walltime_s: float | None
|
|
268
|
+
) -> tuple[int | None, str, bool | None, float | None, list[str], str | None]:
|
|
269
|
+
"""Decide the wall clock one job asks for (FR-364, FR-377).
|
|
270
|
+
|
|
271
|
+
No cell and a BEST row: the job is BEST, ``ceil(1.25 x estimate + margin)`` to the minute,
|
|
272
|
+
capped at ``max_walltime_s`` with a warning that suggests a larger ``n``. Otherwise the job
|
|
273
|
+
takes the sum of the cells per point and each BEST row's priced estimate; a
|
|
274
|
+
row that states no WALLTIME and is not BEST sends the job to ``max_walltime_s`` with a
|
|
275
|
+
warning, and the plan is refused where the profile states none. A point with no estimate
|
|
276
|
+
takes ``max_walltime_s`` with a warning naming it, or blocks the plan where the profile
|
|
277
|
+
states none. A cell above
|
|
278
|
+
``max_walltime_s`` is refused; a shortfall is named only with a recorded point estimate. A job
|
|
279
|
+
whose rows all state nothing asks for none.
|
|
280
|
+
|
|
281
|
+
Parameters
|
|
282
|
+
----------
|
|
283
|
+
split : BudgetGroup
|
|
284
|
+
The job's rows.
|
|
285
|
+
estimate_s : float or None
|
|
286
|
+
The job's estimate from :func:`job_estimate`.
|
|
287
|
+
max_walltime_s : float or None
|
|
288
|
+
The profile's ``max_walltime`` in seconds.
|
|
289
|
+
|
|
290
|
+
Returns
|
|
291
|
+
-------
|
|
292
|
+
tuple
|
|
293
|
+
``(walltime_s, source, fits, shortfall_s, warnings, refusal)``; ``source`` is one of
|
|
294
|
+
``BEST``, ``matrix``, ``max_walltime`` and ``none``; ``refusal`` is the sentence that
|
|
295
|
+
blocks the plan, or None.
|
|
296
|
+
"""
|
|
297
|
+
if _cells_of(split):
|
|
298
|
+
return _from_cells(split, estimate_s, max_walltime_s)
|
|
299
|
+
if any(unit.best for unit in split.units):
|
|
300
|
+
return _from_estimate(split, estimate_s, max_walltime_s)
|
|
301
|
+
return None, "none", None, None, [], None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Named matrix command family; use cfd-matrix plan to inspect proposed work."""
|
cfdbender/matrix/cli.py
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Plan, run and collect matrices through the workspace's declared adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import shlex
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import cast
|
|
10
|
+
|
|
11
|
+
from cfdbender.core.adapter import SolverAdapter
|
|
12
|
+
from cfdbender.core.run import execute_plan
|
|
13
|
+
from cfdbender.core.settings import WorkspaceError
|
|
14
|
+
from cfdbender.matrix.collection import collect_workspace
|
|
15
|
+
from cfdbender.matrix.rerun import decide
|
|
16
|
+
from cfdbender.matrix.selection import select_plan, split_ids
|
|
17
|
+
from cfdbender.matrix.submission import select_profile, submission_plans, submit_plan
|
|
18
|
+
from cfdbender.solvers import load_solver
|
|
19
|
+
from cfdbender.solvers.flightstream import dispatch
|
|
20
|
+
from cfdbender.workspace.planning import plan_workspace
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main(argv: list[str] | None = None) -> int:
|
|
24
|
+
"""Plan, run or collect a matrix, printing refusals to stderr with exit code 2.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
argv : list of str, optional
|
|
29
|
+
Command arguments, excluding the program name.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
int
|
|
34
|
+
Plan and successful runs return 0; run failures and refusals return 2.
|
|
35
|
+
Collect returns 0 for complete, 1 for failures, 3 for outstanding work,
|
|
36
|
+
or 2 for a refusal or summary write error. Help exits with zero.
|
|
37
|
+
"""
|
|
38
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
39
|
+
if (forwarded := dispatch(argv, workspace=False)) is not None:
|
|
40
|
+
return forwarded
|
|
41
|
+
parser = argparse.ArgumentParser(prog="cfd-matrix", allow_abbrev=False)
|
|
42
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
43
|
+
plan_parser = commands.add_parser(
|
|
44
|
+
"plan", help="print proposed work without writing files", allow_abbrev=False
|
|
45
|
+
)
|
|
46
|
+
plan_parser.add_argument("matrix", help="matrix name in inputs/matrices/ (.fs is optional)")
|
|
47
|
+
plan_parser.add_argument("--workspace", default=".", help="campaign workspace (default: .)")
|
|
48
|
+
run_parser = commands.add_parser(
|
|
49
|
+
"run",
|
|
50
|
+
help="run every active point; on this machine a row's SOLVER_BUILD picks its "
|
|
51
|
+
"executable from inputs/executables.toml and executables.local.toml",
|
|
52
|
+
allow_abbrev=False,
|
|
53
|
+
)
|
|
54
|
+
run_parser.add_argument("matrix", help="matrix name in inputs/matrices/ (.fs is optional)")
|
|
55
|
+
run_parser.add_argument("--workspace", default=".", help="campaign workspace (default: .)")
|
|
56
|
+
run_parser.add_argument(
|
|
57
|
+
"--resume",
|
|
58
|
+
action="store_true",
|
|
59
|
+
help="skip points already recorded COMPLETED or SUBMITTED and run the rest, so a "
|
|
60
|
+
"grown matrix runs only its new points; a point left RUNNING by a crashed local run "
|
|
61
|
+
"runs again when no solver process holds this host's slot. Without it a recorded "
|
|
62
|
+
"point refuses the run",
|
|
63
|
+
)
|
|
64
|
+
run_parser.add_argument(
|
|
65
|
+
"--force-rerun",
|
|
66
|
+
dest="force_rerun",
|
|
67
|
+
action="append",
|
|
68
|
+
default=[],
|
|
69
|
+
metavar="POINT",
|
|
70
|
+
help="redo this recorded point, named POL/DP-name or DP-name; repeat for several. "
|
|
71
|
+
"runs.json is copied to archive/<stamp>/runs.json, the point folder moves to "
|
|
72
|
+
"archive/<stamp>/ and its record joins the runs.json history; nothing is deleted",
|
|
73
|
+
)
|
|
74
|
+
run_parser.add_argument(
|
|
75
|
+
"--force-rerun-all",
|
|
76
|
+
dest="force_rerun_all",
|
|
77
|
+
action="store_true",
|
|
78
|
+
help="redo every recorded point of the matrix, archived as --force-rerun archives; "
|
|
79
|
+
"a SUBMITTED job is not cancelled, cancel it in the scheduler first",
|
|
80
|
+
)
|
|
81
|
+
collect_parser = commands.add_parser(
|
|
82
|
+
"collect",
|
|
83
|
+
help="read saved results and rebuild post/<matrix>/campaign_summary.json, "
|
|
84
|
+
"campaign_sweep.csv and polars/P<POL>.csv",
|
|
85
|
+
allow_abbrev=False,
|
|
86
|
+
)
|
|
87
|
+
collect_parser.add_argument("matrix", nargs="?", help="recorded matrix name (default: all)")
|
|
88
|
+
collect_parser.add_argument("--workspace", default=".", help="campaign workspace (default: .)")
|
|
89
|
+
for command_parser in (plan_parser, run_parser, collect_parser):
|
|
90
|
+
command_parser.add_argument(
|
|
91
|
+
"--sims",
|
|
92
|
+
nargs="+",
|
|
93
|
+
metavar="POL",
|
|
94
|
+
help="only these simulations, by POL, space or comma separated "
|
|
95
|
+
"(--sims 1001 1002 or --sims 1001,1002); an id the matrix lacks is refused",
|
|
96
|
+
)
|
|
97
|
+
command_parser.add_argument(
|
|
98
|
+
"--points",
|
|
99
|
+
nargs="+",
|
|
100
|
+
metavar="NAME",
|
|
101
|
+
help="only these points, named DP-name or POL/DP-name, within --sims when "
|
|
102
|
+
"given; a name no point carries is refused",
|
|
103
|
+
)
|
|
104
|
+
command_parser.add_argument(
|
|
105
|
+
"--hpc",
|
|
106
|
+
metavar="NAME",
|
|
107
|
+
help="the HPC profile inputs/hpc/<NAME>.toml to use when the workspace holds several",
|
|
108
|
+
)
|
|
109
|
+
command_parser.add_argument(
|
|
110
|
+
"--local",
|
|
111
|
+
action="store_true",
|
|
112
|
+
help="keep work on THIS machine instead of submitting it",
|
|
113
|
+
)
|
|
114
|
+
args = parser.parse_args(argv)
|
|
115
|
+
try:
|
|
116
|
+
profile = select_profile(Path(args.workspace).resolve(), args.hpc)
|
|
117
|
+
if args.command == "collect":
|
|
118
|
+
report = collect_workspace(
|
|
119
|
+
args.workspace,
|
|
120
|
+
args.matrix,
|
|
121
|
+
sims=split_ids(args.sims),
|
|
122
|
+
points=split_ids(args.points),
|
|
123
|
+
)
|
|
124
|
+
for path in report.summaries:
|
|
125
|
+
print(f"collected summary: {path}")
|
|
126
|
+
for path in report.tables:
|
|
127
|
+
print(f"collected table: {path}")
|
|
128
|
+
print(
|
|
129
|
+
f"collected {report.collected}, failed {report.failed}, "
|
|
130
|
+
f"outstanding {report.outstanding}"
|
|
131
|
+
)
|
|
132
|
+
return report.exit_code
|
|
133
|
+
plan = select_plan(
|
|
134
|
+
plan_workspace(args.workspace, args.matrix),
|
|
135
|
+
split_ids(args.sims),
|
|
136
|
+
split_ids(args.points),
|
|
137
|
+
)
|
|
138
|
+
jobs = submission_plans(plan, profile) if profile is not None and not args.local else ()
|
|
139
|
+
if args.command == "run":
|
|
140
|
+
submitting = profile is not None and not args.local
|
|
141
|
+
decision = decide(
|
|
142
|
+
plan,
|
|
143
|
+
resume=args.resume,
|
|
144
|
+
force=args.force_rerun,
|
|
145
|
+
force_all=args.force_rerun_all,
|
|
146
|
+
submitting=submitting,
|
|
147
|
+
)
|
|
148
|
+
if decision.archive is not None:
|
|
149
|
+
print(f"archived previous evidence: {decision.archive}")
|
|
150
|
+
for point_id, reason in decision.skipped:
|
|
151
|
+
print(f" {point_id} skipped: {reason}")
|
|
152
|
+
plan = decision.plan
|
|
153
|
+
jobs = submission_plans(plan, profile) if submitting and profile is not None else ()
|
|
154
|
+
adapter = cast(SolverAdapter, load_solver(plan.solver))
|
|
155
|
+
records = (
|
|
156
|
+
submit_plan(plan, jobs, profile, adapter)
|
|
157
|
+
if profile is not None and not args.local
|
|
158
|
+
else execute_plan(plan, adapter)
|
|
159
|
+
)
|
|
160
|
+
for record in records:
|
|
161
|
+
print(f" {record.point_id} {record.status} {record.classification}")
|
|
162
|
+
if record.error:
|
|
163
|
+
print(f" {record.point_id}: {record.error}", file=sys.stderr)
|
|
164
|
+
elif record.submission and record.submission["timed_out"]:
|
|
165
|
+
print(record.submission["stderr"], file=sys.stderr)
|
|
166
|
+
if any(
|
|
167
|
+
record.classification == "failed"
|
|
168
|
+
or (record.submission and record.submission["return_code"] != 0)
|
|
169
|
+
for record in records
|
|
170
|
+
):
|
|
171
|
+
print("matrix run with failures", file=sys.stderr)
|
|
172
|
+
return 2
|
|
173
|
+
if any(record.status == "SUBMITTED" for record in records):
|
|
174
|
+
print("submitted; extraction pending collect")
|
|
175
|
+
return 0
|
|
176
|
+
except (WorkspaceError, OSError, ValueError) as error:
|
|
177
|
+
prefix = "matrix not run: " if args.command == "run" else ""
|
|
178
|
+
print(prefix + str(error), file=sys.stderr)
|
|
179
|
+
return 2
|
|
180
|
+
print(f"matrix: {plan.matrix}")
|
|
181
|
+
print(f"solver: {plan.solver}")
|
|
182
|
+
print(f"{len(plan.points)} point(s)")
|
|
183
|
+
for point in plan.points:
|
|
184
|
+
condition = ", ".join(f"{key}={value:g}" for key, value in sorted(point.condition.items()))
|
|
185
|
+
print(
|
|
186
|
+
f" {point.point_id}: SET={point.setup_id} REF={point.reference_id} "
|
|
187
|
+
f"PPROC={point.post_id} WALLTIME={point.walltime or 'NA'}"
|
|
188
|
+
)
|
|
189
|
+
labels = [
|
|
190
|
+
f"{name}={value}"
|
|
191
|
+
for name, value in (
|
|
192
|
+
("AIRCRAFT", point.aircraft),
|
|
193
|
+
("CONFIGURATION", point.configuration),
|
|
194
|
+
("DESCRIPTION", point.description),
|
|
195
|
+
)
|
|
196
|
+
if value
|
|
197
|
+
]
|
|
198
|
+
if labels:
|
|
199
|
+
print(f" {' '.join(labels)}")
|
|
200
|
+
columns = [
|
|
201
|
+
f"{name}={value}"
|
|
202
|
+
for name, value in (
|
|
203
|
+
("GEOMETRY", point.geometry),
|
|
204
|
+
("NCPUS", point.ncpus),
|
|
205
|
+
("SOLVER_BUILD", point.solver_build),
|
|
206
|
+
("HIDDEN", 1 if point.hidden else None),
|
|
207
|
+
)
|
|
208
|
+
if value is not None
|
|
209
|
+
]
|
|
210
|
+
if columns:
|
|
211
|
+
print(f" {' '.join(columns)}")
|
|
212
|
+
for key, value in point.variables.items():
|
|
213
|
+
print(f" variable {key} = {value!r}")
|
|
214
|
+
print(f" {condition or 'no condition stated'}")
|
|
215
|
+
print(f" would: {'; '.join(point.actions)}")
|
|
216
|
+
for output in point.outputs:
|
|
217
|
+
print(f" output: {output}")
|
|
218
|
+
for job in jobs:
|
|
219
|
+
for warning in job.warnings:
|
|
220
|
+
print(f"warning: {warning}", file=sys.stderr)
|
|
221
|
+
print(f"descriptor: {job.descriptor_path.as_posix()}")
|
|
222
|
+
print(job.descriptor_text, end="")
|
|
223
|
+
print(f"would submit: {shlex.join(job.command)}")
|
|
224
|
+
return 0
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
if __name__ == "__main__":
|
|
228
|
+
raise SystemExit(main())
|