courant-dev 0.5.0__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.
- courant/__init__.py +26 -0
- courant/case/__init__.py +0 -0
- courant/case/_foam_reader.py +269 -0
- courant/case/config.py +134 -0
- courant/case/mesh.py +135 -0
- courant/case/reads.py +90 -0
- courant/case/schemes.py +99 -0
- courant/case/solvers.py +170 -0
- courant/cli/__init__.py +0 -0
- courant/cli/commands/__init__.py +6 -0
- courant/cli/commands/audit.py +40 -0
- courant/cli/commands/convergence.py +68 -0
- courant/cli/commands/ctest.py +76 -0
- courant/cli/commands/doctor.py +162 -0
- courant/cli/commands/gate.py +88 -0
- courant/cli/commands/live.py +73 -0
- courant/cli/commands/mcp.py +57 -0
- courant/cli/commands/preflight.py +36 -0
- courant/cli/commands/spec.py +231 -0
- courant/cli/commands/tour.py +122 -0
- courant/cli/commands/update.py +213 -0
- courant/cli/commands/verify.py +222 -0
- courant/cli/config.py +244 -0
- courant/cli/guard.py +69 -0
- courant/cli/main.py +130 -0
- courant/cli/tail.py +351 -0
- courant/config.py +155 -0
- courant/converge/__init__.py +57 -0
- courant/converge/assess.py +823 -0
- courant/converge/exact.py +112 -0
- courant/converge/render.py +182 -0
- courant/converge/scale.py +87 -0
- courant/converge/sentences.py +82 -0
- courant/converge/series.py +413 -0
- courant/converge/steady.py +261 -0
- courant/converge/tables.py +1019 -0
- courant/converge/transient.py +314 -0
- courant/ctest/__init__.py +6 -0
- courant/ctest/build.py +82 -0
- courant/ctest/data/judge-v0.labels.jsonl +31 -0
- courant/ctest/data/judge-v0.tasks.jsonl.gz +0 -0
- courant/ctest/judges/__init__.py +27 -0
- courant/ctest/judges/constant.py +18 -0
- courant/ctest/judges/courant.py +23 -0
- courant/ctest/judges/llm.py +166 -0
- courant/ctest/run.py +74 -0
- courant/ctest/schema.py +46 -0
- courant/ctest/score.py +91 -0
- courant/ctest/splits.py +20 -0
- courant/data/__init__.py +46 -0
- courant/data/certification.json +1 -0
- courant/data/certified_codes.json +18 -0
- courant/data/demo/icoFoam_cavity__cfl_blowup.case.json +68 -0
- courant/data/demo/icoFoam_cavity__cfl_blowup.log.gz +0 -0
- courant/data/demo/icoFoam_cavity__healthy.case.json +68 -0
- courant/data/demo/icoFoam_cavity__healthy.log.gz +0 -0
- courant/data/demo/icoFoam_cavity__transport_units.case.json +68 -0
- courant/data/demo/icoFoam_cavity__transport_units.log.gz +0 -0
- courant/data/demo/pitzDaily_fixed_budget.tar.gz +0 -0
- courant/data/schemas/audit.1.json +129 -0
- courant/data/schemas/cache.1.json +77 -0
- courant/data/schemas/convergence.1.json +112 -0
- courant/data/schemas/error-rates.1.json +53 -0
- courant/data/schemas/preflight.1.json +250 -0
- courant/data/schemas/record.1.json +155 -0
- courant/data/schemas/release-signature.1.json +39 -0
- courant/data/schemas/spec.1.json +258 -0
- courant/data/schemas/support.1.json +80 -0
- courant/data/schemas/verdict.1.json +716 -0
- courant/data/schemas/verdict.2.json +752 -0
- courant/diagnosis/__init__.py +0 -0
- courant/diagnosis/bundle.py +168 -0
- courant/diagnosis/checkers.py +919 -0
- courant/diagnosis/deterministic.py +110 -0
- courant/diagnosis/findings.py +107 -0
- courant/diagnosis/kb.py +188 -0
- courant/diagnosis/kb_data.py +253 -0
- courant/diagnosis/llm.py +299 -0
- courant/diagnosis/redact.py +425 -0
- courant/diagnosis/schema.py +83 -0
- courant/events/__init__.py +35 -0
- courant/events/core.py +194 -0
- courant/events/diverged.py +55 -0
- courant/gate/__init__.py +1 -0
- courant/gate/config.py +150 -0
- courant/gate/run.py +295 -0
- courant/live/__init__.py +16 -0
- courant/live/engine.py +155 -0
- courant/live/watch.py +164 -0
- courant/llm/__init__.py +59 -0
- courant/llm/allowlist.py +60 -0
- courant/llm/anthropic.py +137 -0
- courant/llm/budget.py +491 -0
- courant/llm/door.py +1071 -0
- courant/llm/errors.py +105 -0
- courant/llm/openrouter.py +118 -0
- courant/llm/policy.py +268 -0
- courant/llm/transport.py +48 -0
- courant/mcp/__init__.py +7 -0
- courant/mcp/server.py +113 -0
- courant/mcp/tools.py +177 -0
- courant/record/__init__.py +22 -0
- courant/record/filter.py +99 -0
- courant/record/record.py +149 -0
- courant/release.py +205 -0
- courant/signing.py +99 -0
- courant/spec/__init__.py +31 -0
- courant/spec/check.py +353 -0
- courant/spec/deck.py +455 -0
- courant/spec/extract.py +181 -0
- courant/spec/impossible.py +197 -0
- courant/spec/model.py +194 -0
- courant/taxonomy.py +219 -0
- courant/verification/__init__.py +30 -0
- courant/verification/_fluid_reader.py +228 -0
- courant/verification/bounding.py +84 -0
- courant/verification/checks.py +369 -0
- courant/verification/convergence.py +257 -0
- courant/verification/fields.py +38 -0
- courant/verification/grade.py +101 -0
- courant/verification/suite.py +30 -0
- courant/verify/__init__.py +37 -0
- courant/verify/about.py +100 -0
- courant/verify/audit.py +209 -0
- courant/verify/batch.py +141 -0
- courant/verify/cache.py +329 -0
- courant/verify/checks.py +37 -0
- courant/verify/html.py +330 -0
- courant/verify/ingest.py +115 -0
- courant/verify/junit.py +48 -0
- courant/verify/outcome.py +74 -0
- courant/verify/pack.py +106 -0
- courant/verify/pipeline.py +396 -0
- courant/verify/policy.py +167 -0
- courant/verify/preflight.py +166 -0
- courant/verify/render.py +174 -0
- courant/verify/schema.py +398 -0
- courant/verify/sentences.py +137 -0
- courant/verify/support.py +142 -0
- courant/verify/verdict2.py +235 -0
- courant/watcher/__init__.py +13 -0
- courant/watcher/anomaly.py +244 -0
- courant/watcher/exitcode.py +23 -0
- courant/watcher/parser.py +435 -0
- courant/watcher/watcher.py +49 -0
- courant_dev-0.5.0.dist-info/METADATA +146 -0
- courant_dev-0.5.0.dist-info/RECORD +152 -0
- courant_dev-0.5.0.dist-info/WHEEL +5 -0
- courant_dev-0.5.0.dist-info/entry_points.txt +3 -0
- courant_dev-0.5.0.dist-info/licenses/LICENSE +202 -0
- courant_dev-0.5.0.dist-info/licenses/NOTICE +4 -0
- courant_dev-0.5.0.dist-info/top_level.txt +1 -0
courant/case/schemes.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Which OpenFOAM discretisation schemes are bounded, in one place.
|
|
2
|
+
|
|
3
|
+
This module exists because the question "is this scheme bounded?" was answered
|
|
4
|
+
twice in the codebase, and the two answers disagreed.
|
|
5
|
+
|
|
6
|
+
The original rule was `"bounded" not in scheme and "upwind" not in scheme`, which
|
|
7
|
+
is wrong on the most common turbulence scheme OpenFOAM ships:
|
|
8
|
+
`div(phi,k) Gauss limitedLinear 1` contains neither word and `limitedLinear` is
|
|
9
|
+
*definitionally* a limited scheme. Both of OpenFOAM's turbulent tutorials use it.
|
|
10
|
+
The certification run of 30 Jul 2026 found this and it was fixed — in
|
|
11
|
+
`courant/diagnosis/checkers.py`. The copy in the knowledge base's
|
|
12
|
+
`unbounded_div` config predicate was missed, so the KB kept scoring
|
|
13
|
+
`NUM.UNBOUNDED_SCHEME` +2.0 on every RAS case for a scheme that is bounded, and
|
|
14
|
+
the next full matrix had that code in the wrong answer of eight of twelve
|
|
15
|
+
failing scenarios.
|
|
16
|
+
|
|
17
|
+
A fact about OpenFOAM with two implementations is a fact with two truth values.
|
|
18
|
+
There is now one.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import re
|
|
24
|
+
|
|
25
|
+
#: OpenFOAM's limited (bounded) surface-interpolation schemes, read from
|
|
26
|
+
#: `src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes` in v2406
|
|
27
|
+
#: rather than recalled. Lower-cased for matching.
|
|
28
|
+
BOUNDED_SCHEMES = frozenset({
|
|
29
|
+
"limitedlinear", "limitedcubic", "limitedlinear01", "limitedcubic01",
|
|
30
|
+
"vanleer", "vanalbada", "minmod", "muscl", "superbee", "ospre", "umist",
|
|
31
|
+
"quick", "sfcd", "gamma", "limitwith", "limited", "limited01",
|
|
32
|
+
"filteredlinear", "filteredlinear2", "filteredlinear3",
|
|
33
|
+
"upwind", "linearupwind",
|
|
34
|
+
# Courant- and region-blended schemes fall back to upwind where it matters,
|
|
35
|
+
# which is the whole point of them.
|
|
36
|
+
"coblended", "cellcoblended", "localblended", "limiterblended",
|
|
37
|
+
"fixedblended", "blended", "outletstabilised", "lust",
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
#: The explicit keyword, still honoured — `bounded Gauss limitedLinear 1` is how
|
|
41
|
+
#: OpenFOAM's own steady tutorials write it.
|
|
42
|
+
BOUNDED_KEYWORD = "bounded"
|
|
43
|
+
|
|
44
|
+
#: `div(phi,<field>)` is convection of a transported quantity. Matching any
|
|
45
|
+
#: field rather than a hardcoded three: pisoFoam/RAS/cavity also transports
|
|
46
|
+
#: `omega`, `R` and `nuTilda`, and an unbounded scheme on those is just as real.
|
|
47
|
+
_RE_CONVECTION = re.compile(r"^div\(\s*phi\s*,", re.I)
|
|
48
|
+
|
|
49
|
+
_RE_WORDS = re.compile(r"[^a-z0-9]+")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def is_convection_term(term: str) -> bool:
|
|
53
|
+
"""Whether this `divSchemes` key discretises transport of a field."""
|
|
54
|
+
return bool(_RE_CONVECTION.match(term.strip()))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def is_bounded_scheme(scheme: str) -> bool:
|
|
58
|
+
"""Whether this discretisation is bounded/limited.
|
|
59
|
+
|
|
60
|
+
Word-wise rather than substring: `linear` is a substring of `limitedLinear`,
|
|
61
|
+
so a naive `in` test would call the genuinely unbounded `Gauss linear`
|
|
62
|
+
bounded and miss the real thing.
|
|
63
|
+
"""
|
|
64
|
+
lowered = scheme.lower()
|
|
65
|
+
if BOUNDED_KEYWORD in lowered:
|
|
66
|
+
return True
|
|
67
|
+
return any(word in BOUNDED_SCHEMES for word in _RE_WORDS.split(lowered) if word)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def resolve_macros(div_schemes: dict[str, str], depth: int = 8) -> dict[str, str]:
|
|
71
|
+
"""Expand `$name` references, the way OpenFOAM reads the dictionary.
|
|
72
|
+
|
|
73
|
+
`simpleFoam/T3A` writes `turbulence bounded Gauss linearUpwind grad;` once, and every
|
|
74
|
+
turbulence term as `div(phi,k) $turbulence;`. Unexpanded, `$turbulence` read as a scheme
|
|
75
|
+
with no bounding in it, and an unmodified tutorial was told its schemes were unbounded.
|
|
76
|
+
That was the first fresh case run, and nothing in the corpus wrote a macro. Only
|
|
77
|
+
same-dictionary references are resolved. An unresolved one is left as written, and
|
|
78
|
+
`is_bounded_scheme` then treats it as not known to be bounded, as before.
|
|
79
|
+
"""
|
|
80
|
+
out = dict(div_schemes)
|
|
81
|
+
for _ in range(depth):
|
|
82
|
+
changed = False
|
|
83
|
+
for term, scheme in out.items():
|
|
84
|
+
s = str(scheme).strip()
|
|
85
|
+
if s.startswith("$"):
|
|
86
|
+
ref = s[1:].strip().rstrip(";").strip()
|
|
87
|
+
if ref in out and str(out[ref]).strip() != s:
|
|
88
|
+
out[term] = out[ref]
|
|
89
|
+
changed = True
|
|
90
|
+
if not changed:
|
|
91
|
+
break
|
|
92
|
+
return out
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def unbounded_convection_schemes(div_schemes: dict[str, str]) -> dict[str, str]:
|
|
96
|
+
"""The convection terms in this case discretised without bounding (macros expanded)."""
|
|
97
|
+
resolved = resolve_macros(div_schemes)
|
|
98
|
+
return {term: scheme for term, scheme in resolved.items()
|
|
99
|
+
if is_convection_term(term) and not is_bounded_scheme(scheme)}
|
courant/case/solvers.py
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""What each OpenFOAM solver can actually do.
|
|
2
|
+
|
|
3
|
+
Domain knowledge, kept in one place because getting it wrong is invisible.
|
|
4
|
+
`adjustTimeStep` is the case in point: it is read from `controlDict` only by
|
|
5
|
+
solvers that include `setDeltaT.H`. Every other solver **silently ignores it** —
|
|
6
|
+
no warning, no error, no entry in the log.
|
|
7
|
+
|
|
8
|
+
That produced a real and embarrassing failure. Given a lid-driven cavity
|
|
9
|
+
diverging on the Courant number, Courant proposed "enable adaptive timestepping
|
|
10
|
+
capped at maxCo 0.8" to `icoFoam`, which is a fixed-timestep PISO solver. The
|
|
11
|
+
edit applied cleanly, `foamDictionary` confirmed the values were written, and the
|
|
12
|
+
solve crashed exactly as before. Measured in the container:
|
|
13
|
+
|
|
14
|
+
adjustTimeStep yes; maxCo 0.8; → icoFoam
|
|
15
|
+
"deltaT = " lines in the log: 0 (the timestep never adapted)
|
|
16
|
+
Courant Number max: 66.8, 113.8, … (against maxCo 0.8)
|
|
17
|
+
|
|
18
|
+
Two costs. One of a three-attempt budget is spent on a fix that cannot work, and
|
|
19
|
+
any CFD engineer reading the report sees us tell icoFoam to do something icoFoam
|
|
20
|
+
does not do — which is the kind of error that ends an evaluation.
|
|
21
|
+
|
|
22
|
+
The lists below are read from OpenFOAM v2406's own sources rather than recalled:
|
|
23
|
+
|
|
24
|
+
grep -rl setDeltaT.H $WM_PROJECT_DIR/applications/solvers --include='*.C'
|
|
25
|
+
|
|
26
|
+
58 solvers include it. Rather than carry all 58, the rule is expressed as the
|
|
27
|
+
family it actually tracks — the PIMPLE/multiphase/reacting transient solvers —
|
|
28
|
+
with the common fixed-timestep solvers named explicitly, because those are the
|
|
29
|
+
ones a wrong answer costs us.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
#: Solvers that read `adjustTimeStep`, verified against v2406 sources.
|
|
35
|
+
ADAPTIVE_TIMESTEP_SOLVERS = frozenset({
|
|
36
|
+
"pimpleFoam", "rhoPimpleFoam", "rhoPimpleAdiabaticFoam", "SRFPimpleFoam",
|
|
37
|
+
"buoyantPimpleFoam", "buoyantBoussinesqPimpleFoam",
|
|
38
|
+
"interFoam", "interIsoFoam", "interMixingFoam", "interPhaseChangeFoam",
|
|
39
|
+
"compressibleInterFoam", "multiphaseInterFoam", "multiphaseEulerFoam",
|
|
40
|
+
"twoPhaseEulerFoam", "twoLiquidMixingFoam", "driftFluxFoam",
|
|
41
|
+
"cavitatingFoam", "potentialFreeSurfaceFoam",
|
|
42
|
+
"reactingFoam", "rhoReactingFoam", "rhoReactingBuoyantFoam",
|
|
43
|
+
"sprayFoam", "engineFoam", "XiFoam", "XiEngineFoam", "fireFoam",
|
|
44
|
+
"PDRFoam", "chemFoam", "DPMFoam", "MPPICInterFoam", "rhoCentralFoam",
|
|
45
|
+
"chtMultiRegionFoam",
|
|
46
|
+
# Overset. `over*DyMFoam` wrap a PIMPLE loop and read `adjustTimeStep` the
|
|
47
|
+
# same way; an unknown solver name defaulted to "no adaptivity", which makes
|
|
48
|
+
# the timestep fix propose the wrong repair on a family that does support it.
|
|
49
|
+
"overPimpleDyMFoam", "overRhoPimpleDyMFoam", "overInterDyMFoam",
|
|
50
|
+
"overBuoyantPimpleDyMFoam", "overPotentialFoam",
|
|
51
|
+
# The OpenFOAM.org fork. v11 replaced the individual solver executables with
|
|
52
|
+
# one `foamRun -solver <module>` binary, so an entire fork of the user base
|
|
53
|
+
# arrives under a name that was in no capability set — and `foamRun` does
|
|
54
|
+
# read `adjustTimeStep`, so the timestep repair was proposing a fixed step
|
|
55
|
+
# to every .org user.
|
|
56
|
+
#
|
|
57
|
+
# Steadiness is NOT decided here for these: a `foamRun` case is steady or
|
|
58
|
+
# transient according to its `ddtSchemes`, and `CaseConfig.is_steady` already
|
|
59
|
+
# prefers the declared scheme over the solver name. That is the correct
|
|
60
|
+
# precedence and it is why this only needed the adaptive half.
|
|
61
|
+
"foamRun", "foamMultiRun",
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
#: Solvers that ignore it. Named explicitly because these are the ones the
|
|
65
|
+
#: taxonomy's timestep failures actually show up on, so a wrong answer here is
|
|
66
|
+
#: the expensive kind.
|
|
67
|
+
FIXED_TIMESTEP_SOLVERS = frozenset({
|
|
68
|
+
"icoFoam", "pisoFoam", "simpleFoam", "potentialFoam", "sonicFoam",
|
|
69
|
+
# Steady compressible. `rhoSimpleFoam` was in neither set, so `is_steady`
|
|
70
|
+
# returned False for it and every steady-only check was silenced — the
|
|
71
|
+
# relaxation finding among them, on the most common compressible steady
|
|
72
|
+
# solver there is. Under-relaxation is the single failure mode a practising
|
|
73
|
+
# CFD consultant named first when asked what breaks most often.
|
|
74
|
+
"rhoSimpleFoam", "rhoPorousSimpleFoam",
|
|
75
|
+
"buoyantSimpleFoam", "laplacianFoam", "scalarTransportFoam",
|
|
76
|
+
"boundaryFoam", "SRFSimpleFoam", "adjointShapeOptimizationFoam",
|
|
77
|
+
"porousSimpleFoam", "shallowWaterFoam", "electrostaticFoam",
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
#: Steady-state solvers. `deltaT` is a relaxation pseudo-step, and the Courant
|
|
81
|
+
#: number is not a stability criterion — so a CFL "fix" that shrinks deltaT is
|
|
82
|
+
#: not just useless here, it slows convergence.
|
|
83
|
+
STEADY_SOLVERS = frozenset({
|
|
84
|
+
"simpleFoam", "potentialFoam", "buoyantSimpleFoam", "porousSimpleFoam",
|
|
85
|
+
"rhoSimpleFoam", "rhoPorousSimpleFoam",
|
|
86
|
+
"SRFSimpleFoam", "adjointShapeOptimizationFoam", "laplacianFoam",
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def honours_adjust_time_step(solver: str | None) -> bool:
|
|
91
|
+
"""Whether setting `adjustTimeStep` on this solver does anything.
|
|
92
|
+
|
|
93
|
+
Unknown solvers get ``False``. That is the conservative direction: proposing
|
|
94
|
+
a fix that silently does nothing wastes an attempt from a small budget and
|
|
95
|
+
misinforms the report, whereas declining to propose it only means the loop
|
|
96
|
+
reaches for the timestep reduction instead — which works on every solver.
|
|
97
|
+
"""
|
|
98
|
+
if not solver:
|
|
99
|
+
return False
|
|
100
|
+
return _base(solver) in ADAPTIVE_TIMESTEP_SOLVERS
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def is_steady(solver: str | None) -> bool:
|
|
104
|
+
if not solver:
|
|
105
|
+
return False
|
|
106
|
+
return _base(solver) in STEADY_SOLVERS
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
#: Parallel launchers. A production OpenFOAM run is never invoked bare — it is
|
|
110
|
+
#: `mpirun -np 64 <solver> -parallel`, or the scheduler's equivalent.
|
|
111
|
+
_LAUNCHERS = frozenset({
|
|
112
|
+
"mpirun", "mpiexec", "orterun", "srun", "aprun", "ibrun", "jsrun",
|
|
113
|
+
"prun", "poe", "runjob", "lamexec", "oshrun", "mpirun.openmpi",
|
|
114
|
+
"mpirun.mpich", "time", "nohup", "stdbuf",
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _base(solver: str) -> str:
|
|
119
|
+
"""The solver executable's name, with its decoration removed.
|
|
120
|
+
|
|
121
|
+
Decoration means a path, a launcher, the launcher's flags, and the solver's
|
|
122
|
+
own flags: `mpirun --allow-run-as-root -np 8 rhoSimpleFoam -parallel` is a
|
|
123
|
+
`rhoSimpleFoam` run.
|
|
124
|
+
|
|
125
|
+
THIS USED TO TAKE THE FIRST TOKEN, while its docstring claimed to strip the
|
|
126
|
+
MPI wrapper. It returned `mpirun` for every parallel command, so on every
|
|
127
|
+
parallel run — which is every industrial run — the solver was unrecognised:
|
|
128
|
+
`is_steady` said False, silencing every steady-only check including
|
|
129
|
+
relaxation, and `honours_adjust_time_step` said False, which makes the
|
|
130
|
+
timestep repair propose a fixed step on a solver that supports adaptivity.
|
|
131
|
+
|
|
132
|
+
A known solver name anywhere in the command wins outright, because it is
|
|
133
|
+
exact and survives any flag spelling — `-hostfile hosts` would otherwise
|
|
134
|
+
offer `hosts` as the executable. Only when nothing is recognised does this
|
|
135
|
+
fall back to position: the first token that is not a launcher, not a flag,
|
|
136
|
+
and not a flag's numeric value.
|
|
137
|
+
"""
|
|
138
|
+
tokens = [tok.rsplit("/", 1)[-1] for tok in solver.strip().split()]
|
|
139
|
+
if not tokens:
|
|
140
|
+
return ""
|
|
141
|
+
|
|
142
|
+
known = ADAPTIVE_TIMESTEP_SOLVERS | FIXED_TIMESTEP_SOLVERS | STEADY_SOLVERS
|
|
143
|
+
for tok in tokens:
|
|
144
|
+
if tok in known:
|
|
145
|
+
return tok
|
|
146
|
+
|
|
147
|
+
# Naming convention, for a solver we do not have in the table. Nearly every
|
|
148
|
+
# OpenFOAM solver ends in "Foam", and this is what rescues a custom or
|
|
149
|
+
# in-house solver from being mistaken for a launcher flag's value —
|
|
150
|
+
# `-hostfile hosts myCustomFoam` would otherwise resolve to `hosts`.
|
|
151
|
+
for tok in tokens:
|
|
152
|
+
if tok.endswith("Foam") and tok not in _LAUNCHERS:
|
|
153
|
+
return tok
|
|
154
|
+
|
|
155
|
+
for tok in tokens:
|
|
156
|
+
if tok in _LAUNCHERS or tok.startswith("-") or "=" in tok:
|
|
157
|
+
continue # a launcher, its flag, or `-x VAR=value`
|
|
158
|
+
# `-np 4` — the count trailing a launcher flag, not an executable.
|
|
159
|
+
try:
|
|
160
|
+
float(tok)
|
|
161
|
+
except ValueError:
|
|
162
|
+
return tok
|
|
163
|
+
return tokens[0]
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def is_known(solver: str | None) -> bool:
|
|
167
|
+
"""Whether the capability table names this solver (after stripping any MPI wrapper)."""
|
|
168
|
+
if not solver:
|
|
169
|
+
return False
|
|
170
|
+
return _base(solver) in (ADAPTIVE_TIMESTEP_SOLVERS | FIXED_TIMESTEP_SOLVERS | STEADY_SOLVERS)
|
courant/cli/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""`courant audit`: what a folder of runs cost, and how much of it bought nothing (TRD AUDIT-1).
|
|
2
|
+
|
|
3
|
+
Exit codes follow `courant verify --batch`:
|
|
4
|
+
- 2 if any run is NOT_TRUSTWORTHY;
|
|
5
|
+
- 3 if any is NOT_ASSESSABLE;
|
|
6
|
+
- 4 if any could not be read;
|
|
7
|
+
- 0 otherwise.
|
|
8
|
+
|
|
9
|
+
Read-only and offline. Writes only the files you name.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import typer
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def audit(
|
|
21
|
+
root: str = typer.Argument(..., help="A directory of runs: case directories with a log, or *.log / *.log.gz files."),
|
|
22
|
+
cost: float = typer.Option(None, "--cost-per-core-hour", help="Your rate, to price the core-hours. Without it no money is shown."),
|
|
23
|
+
as_json: bool = typer.Option(False, "--json", help="Print the canonical audit JSON."),
|
|
24
|
+
html: str = typer.Option(None, "--html", help="Write a self-contained HTML audit to this file."),
|
|
25
|
+
) -> None:
|
|
26
|
+
"""The compute audit: core-hours on untrusted results, after convergence, and on broken setups."""
|
|
27
|
+
from courant.verify.audit import audit as run_audit
|
|
28
|
+
from courant.verify.audit import render_html, render_text
|
|
29
|
+
from courant.verify.schema import canonical_json
|
|
30
|
+
|
|
31
|
+
if not Path(root).is_dir():
|
|
32
|
+
print(f"courant audit: not a directory: {root}", file=sys.stderr)
|
|
33
|
+
raise typer.Exit(4)
|
|
34
|
+
doc = run_audit(root, cost)
|
|
35
|
+
if html:
|
|
36
|
+
Path(html).write_text(render_html(doc))
|
|
37
|
+
print(f"audit written: {html}", file=sys.stderr)
|
|
38
|
+
sys.stdout.write(canonical_json(doc) if as_json else render_text(doc))
|
|
39
|
+
t = doc["totals"]
|
|
40
|
+
raise typer.Exit(2 if t["not_trustworthy"] else 3 if t["not_assessable"] else 4 if t["unreadable"] else 0)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""`courant convergence`: where the answer stopped changing, and what the rest cost (TRD CONV-13).
|
|
2
|
+
|
|
3
|
+
Exit codes:
|
|
4
|
+
- 0 PASS or WARN
|
|
5
|
+
- 2 FAIL
|
|
6
|
+
- 3 NOT_ASSESSABLE
|
|
7
|
+
- 4 the inputs could not be read
|
|
8
|
+
|
|
9
|
+
Read-only. Named `convergence`, not `stop`: a command called `stop` that does not stop the
|
|
10
|
+
solver is a trap for the person typing it.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
import typer
|
|
18
|
+
|
|
19
|
+
EXIT = {"PASS": 0, "WARN": 0, "FAIL": 2, "NOT_ASSESSABLE": 3}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _pairs(items: list[str], flag: str) -> dict[str, float]:
|
|
23
|
+
out = {}
|
|
24
|
+
for item in items or []:
|
|
25
|
+
name, sep, value = item.partition("=")
|
|
26
|
+
if not sep or not name:
|
|
27
|
+
raise ValueError(f"{flag} expects NAME=VALUE, got {item!r}")
|
|
28
|
+
out[name] = float(value)
|
|
29
|
+
return out
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def convergence(
|
|
33
|
+
path: str = typer.Argument(..., help="A case directory (monitors are read from postProcessing/), or a solver log."),
|
|
34
|
+
case_json: str = typer.Option(None, "--case-json", help="Captured configuration sidecar (*.case.json)."),
|
|
35
|
+
as_json: bool = typer.Option(False, "--json", help="Print the canonical convergence JSON."),
|
|
36
|
+
tol: list[str] = typer.Option(None, "--tol", help="Absolute tolerance for a monitor or column: NAME=VALUE. Repeatable."),
|
|
37
|
+
tol_rel: list[str] = typer.Option(None, "--tol-rel", help="Relative tolerance: NAME=VALUE (0.01 is one part in a hundred). Repeatable."),
|
|
38
|
+
ref_scale: list[str] = typer.Option(None, "--ref-scale", help="Reference scale for a relative tolerance: NAME=VALUE."),
|
|
39
|
+
transient_average: bool = typer.Option(False, "--transient-average", help="Judge transient monitors as time-averages."),
|
|
40
|
+
monitor: list[str] = typer.Option(None, "--monitor", help="Judge only monitors matching this glob (id or column), e.g. '*:Cd'. Repeatable. Default: the totals each function object writes."),
|
|
41
|
+
cost: float = typer.Option(None, "--cost-per-core-hour", help="Your rate, to price the core-hours past convergence."),
|
|
42
|
+
ccf: float = typer.Option(None, "--ccf-ghz", help="FIA CCF in GHz: also report allocation unit hours (Art. F4.4.4)."),
|
|
43
|
+
) -> None:
|
|
44
|
+
"""Where the answer stopped changing, and the iterations, wall clock and core-hours after it."""
|
|
45
|
+
from pathlib import Path
|
|
46
|
+
|
|
47
|
+
from courant.converge import Options, from_run_inputs, render_text, to_document
|
|
48
|
+
from courant.converge.series import solver_from_log
|
|
49
|
+
from courant.verify.ingest import InputError, from_path
|
|
50
|
+
from courant.verify.schema import canonical_json
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
options = Options(tol_abs=_pairs(tol, "--tol"), tol_rel=_pairs(tol_rel, "--tol-rel"),
|
|
54
|
+
ref_scale=_pairs(ref_scale, "--ref-scale"),
|
|
55
|
+
transient_average=transient_average, monitors=tuple(monitor or ()),
|
|
56
|
+
cost_per_core_hour=cost, ccf_ghz=ccf)
|
|
57
|
+
inputs = from_path(path, case_json)
|
|
58
|
+
conv = from_run_inputs(inputs, options)
|
|
59
|
+
except (InputError, ValueError) as exc:
|
|
60
|
+
print(f"courant convergence: {exc}", file=sys.stderr)
|
|
61
|
+
raise typer.Exit(4) from exc
|
|
62
|
+
name = Path(path).name
|
|
63
|
+
solver = inputs.solver_hint or solver_from_log(inputs.log_text)
|
|
64
|
+
if as_json:
|
|
65
|
+
sys.stdout.write(canonical_json(to_document(conv, name, solver)))
|
|
66
|
+
else:
|
|
67
|
+
sys.stdout.write(render_text(conv, name, solver))
|
|
68
|
+
raise typer.Exit(EXIT[conv.status])
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""`courant test`: the Courant Test (TRD CT-8)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
app = typer.Typer(help="The Courant Test: can AI do engineering simulation, and tell when it is wrong?",
|
|
10
|
+
no_args_is_help=True)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@app.command("build")
|
|
14
|
+
def build() -> None:
|
|
15
|
+
"""Build judge-v0 from certification/corpus (tasks and hash-locked labels)."""
|
|
16
|
+
from courant.ctest.build import LABELS, TASKS, build_judge_v0, write
|
|
17
|
+
|
|
18
|
+
tasks, labels = build_judge_v0()
|
|
19
|
+
write(tasks, labels)
|
|
20
|
+
print(f"{len(tasks)} tasks -> {TASKS.name}; labels -> {LABELS.name}")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@app.command("run")
|
|
24
|
+
def run(judge: str = typer.Option("courant", help="courant | constant:<VERDICT> | llm:<provider>:<model>. "
|
|
25
|
+
"An llm judge sends each task's text to that provider with your "
|
|
26
|
+
"key, only once the model door lets that model judge, and names "
|
|
27
|
+
"the host first; otherwise it contacts nothing. The others are "
|
|
28
|
+
"offline."),
|
|
29
|
+
split: str = typer.Option("all", help="all | held-in | held-out"),
|
|
30
|
+
out: str = typer.Option(None, help="write the full result JSON here")) -> None:
|
|
31
|
+
"""Score a judge. Every rate prints with its denominator."""
|
|
32
|
+
from courant.ctest.run import run as run_ctest
|
|
33
|
+
from courant.verify.schema import canonical_json
|
|
34
|
+
|
|
35
|
+
door = None
|
|
36
|
+
if judge.startswith("llm:"):
|
|
37
|
+
from courant.llm import contact_notice, default_door
|
|
38
|
+
|
|
39
|
+
_, provider, model = (judge.split(":", 2) + ["", ""])[:3]
|
|
40
|
+
door = default_door()
|
|
41
|
+
# Asked before anything touches the network: a call the door refuses contacts nothing
|
|
42
|
+
# (docs/NETWORK.md); one it lets through names its host first.
|
|
43
|
+
reason = door.why_not(task="judge", data="public", model=model or None,
|
|
44
|
+
provider=provider or None)
|
|
45
|
+
if reason is not None:
|
|
46
|
+
print(f"stopped, nothing scored or written: {reason}. Nothing was contacted.",
|
|
47
|
+
file=sys.stderr)
|
|
48
|
+
raise typer.Exit(3)
|
|
49
|
+
print(f"courant test run: {contact_notice(provider)}, through the model door; each "
|
|
50
|
+
"task's text is sent", file=sys.stderr)
|
|
51
|
+
try:
|
|
52
|
+
result = run_ctest(judge, split, door=door)
|
|
53
|
+
except Exception as exc:
|
|
54
|
+
from courant.llm import stops_batch
|
|
55
|
+
|
|
56
|
+
if not stops_batch(exc):
|
|
57
|
+
raise
|
|
58
|
+
# A stop is not the judge's answer: nothing is scored or written (ARC-19).
|
|
59
|
+
until = getattr(exc, "until", None)
|
|
60
|
+
print(f"stopped, nothing scored or written: {exc}"
|
|
61
|
+
+ (f" (resumes after {until:%Y-%m-%d %H:%M} UTC)" if until is not None else ""),
|
|
62
|
+
file=sys.stderr)
|
|
63
|
+
raise typer.Exit(3) from None
|
|
64
|
+
if out:
|
|
65
|
+
with open(out, "w") as fh:
|
|
66
|
+
fh.write(canonical_json(result))
|
|
67
|
+
for name in ("all", "held_in", "held_out"):
|
|
68
|
+
c = result["scorecard"][name]
|
|
69
|
+
if not c["tasks"]:
|
|
70
|
+
continue
|
|
71
|
+
print(f"{name:9s} tasks {c['tasks']:3d} · accuracy {c['accuracy']['n']}/{c['accuracy']['of']}"
|
|
72
|
+
f" · false accepts {c['far']['n']}/{c['far']['of']}"
|
|
73
|
+
f" · false alarms {c['frr']['n']}/{c['frr']['of']}"
|
|
74
|
+
f" · abstain {c['abstain']['n']}/{c['abstain']['of']}"
|
|
75
|
+
f" · top-2 {c['top2']['n']}/{c['top2']['of']}")
|
|
76
|
+
sys.stdout.flush()
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""`courant doctor`: what this installation is, and what it can reach for.
|
|
2
|
+
|
|
3
|
+
It contacts nothing, with one exception the user asks for by name: `--models` reads
|
|
4
|
+
OpenRouter's public model listing (no key) and names the host before it does
|
|
5
|
+
(docs/NETWORK.md). The previous product's cloud account commands (`login`, `logout`,
|
|
6
|
+
`whoami`) and doctor's probe of its API are gone: there is no Courant service to reach.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import typer
|
|
12
|
+
from rich.console import Console
|
|
13
|
+
from rich.markup import escape
|
|
14
|
+
from rich.table import Table
|
|
15
|
+
|
|
16
|
+
from courant import __version__
|
|
17
|
+
from courant.cli.config import config_dir
|
|
18
|
+
|
|
19
|
+
console = Console()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def doctor(
|
|
23
|
+
models: bool = typer.Option(
|
|
24
|
+
False, "--models",
|
|
25
|
+
help="list the models the model door may call, and which of them OpenRouter's "
|
|
26
|
+
"live listing has dropped, and exit. This reads OpenRouter's public model listing "
|
|
27
|
+
"over the network, without a key; nothing else in doctor uses the network"),
|
|
28
|
+
bundle: str = typer.Option(
|
|
29
|
+
None, "--bundle",
|
|
30
|
+
help="write a support bundle (courant.support/1: versions, platform, the command "
|
|
31
|
+
"line, and a verdict if --verdict names one; no case data) to this file, and exit"),
|
|
32
|
+
verdict: str = typer.Option(
|
|
33
|
+
None, "--verdict", help="with --bundle: a verdict JSON file to include"),
|
|
34
|
+
pseudonymise: bool = typer.Option(
|
|
35
|
+
False, "--pseudonymise",
|
|
36
|
+
help="with --bundle: replace the run id, patch names, file names and item names with "
|
|
37
|
+
"stable pseudonyms and strip paths and hosts, so the bundle can be shared"),
|
|
38
|
+
) -> None:
|
|
39
|
+
"""Diagnose this installation, the first thing to run when something is off. Offline;
|
|
40
|
+
only --models contacts OpenRouter."""
|
|
41
|
+
if bundle:
|
|
42
|
+
import sys
|
|
43
|
+
from pathlib import Path
|
|
44
|
+
|
|
45
|
+
from courant.verify import support
|
|
46
|
+
from courant.verify.schema import canonical_json
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
out = Path(bundle)
|
|
50
|
+
out.write_text(canonical_json(support.build(sys.argv, verdict, pseudonymise=pseudonymise)))
|
|
51
|
+
except (ValueError, OSError) as exc:
|
|
52
|
+
console.print(f"courant doctor: {exc}", style="red", markup=False)
|
|
53
|
+
raise typer.Exit(4) from exc
|
|
54
|
+
console.print(f"support bundle written: {out} (nothing was sent)", markup=False)
|
|
55
|
+
return
|
|
56
|
+
if models:
|
|
57
|
+
_show_models()
|
|
58
|
+
return
|
|
59
|
+
|
|
60
|
+
table = Table(show_header=False, box=None, padding=(0, 2, 0, 0))
|
|
61
|
+
|
|
62
|
+
def check(label: str, ok: bool | None, detail: str = "") -> None:
|
|
63
|
+
mark = "[green]✓[/green]" if ok else ("[yellow]—[/yellow]" if ok is None
|
|
64
|
+
else "[red]✗[/red]")
|
|
65
|
+
# Escaped: a detail such as "pip install 'courant-dev[sandbox]'" is text, not markup.
|
|
66
|
+
table.add_row(mark, label, f"[dim]{escape(detail)}[/dim]")
|
|
67
|
+
|
|
68
|
+
check("version", True, __version__)
|
|
69
|
+
check("config dir", config_dir().exists(), str(config_dir()))
|
|
70
|
+
# Said, because "does it phone home" is the question a security review asks first.
|
|
71
|
+
check("network", True, "doctor contacted nothing; which commands do: docs/NETWORK.md")
|
|
72
|
+
|
|
73
|
+
# The reasoning model, as the model door decides it. On a customer laptop
|
|
74
|
+
# this is normally none, and that is correct: the deterministic diagnoser is
|
|
75
|
+
# the floor. It is shown because "why is it not using the LLM" is otherwise
|
|
76
|
+
# an invisible question, and a key alone is not the answer: the door also
|
|
77
|
+
# needs a zero-data-retention model measured on diagnosis (ARC-9, ARC-12).
|
|
78
|
+
from courant.config import Settings
|
|
79
|
+
from courant.diagnosis.llm import DIAGNOSIS_CALL
|
|
80
|
+
from courant.llm import default_door
|
|
81
|
+
|
|
82
|
+
local = Settings()
|
|
83
|
+
door = default_door()
|
|
84
|
+
chosen = door.eligible(**DIAGNOSIS_CALL)
|
|
85
|
+
if chosen:
|
|
86
|
+
check("reasoning model", True, f"{chosen[0].provider} · {chosen[0].id}")
|
|
87
|
+
elif local.providers:
|
|
88
|
+
check("reasoning model", None,
|
|
89
|
+
f"{' · '.join(local.providers)} key set; diagnosis stays deterministic: "
|
|
90
|
+
f"{door.why_not(**DIAGNOSIS_CALL)}")
|
|
91
|
+
else:
|
|
92
|
+
check("reasoning model", None,
|
|
93
|
+
"no model provider configured; diagnosis is deterministic")
|
|
94
|
+
|
|
95
|
+
# Optional, and only interesting to someone running real solves locally —
|
|
96
|
+
# so a dash rather than a cross when it is absent, and the *reason* when it
|
|
97
|
+
# is, because "no docker" on a machine where `docker run` works is a
|
|
98
|
+
# missing Python package, not a broken daemon. This asks the local Docker
|
|
99
|
+
# daemon (its socket, or DOCKER_HOST if the user set one) whether it runs.
|
|
100
|
+
if local.docker_ready():
|
|
101
|
+
check("docker (real solves)", True, local.openfoam_image)
|
|
102
|
+
else:
|
|
103
|
+
check("docker (real solves)", None, local.docker_detail)
|
|
104
|
+
|
|
105
|
+
console.print(table)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _show_models() -> None:
|
|
109
|
+
"""`courant doctor --models`: the models the model door may call, and what OpenRouter's
|
|
110
|
+
live listing says of them today.
|
|
111
|
+
|
|
112
|
+
The allowlist is in the repository (courant/llm/allowlist.py), not discovered: free is
|
|
113
|
+
decided by the list and the exact `:free` suffix, never by a price that reads "0" (ARC-6).
|
|
114
|
+
Free ids are renamed and retired on OpenRouter's schedule, so the live listing, read
|
|
115
|
+
without a key, marks every listed id it no longer serves or that is past its expiration
|
|
116
|
+
date (ARC-10). A dropped id is a reason to refresh the allowlist, not to pick another
|
|
117
|
+
model here.
|
|
118
|
+
"""
|
|
119
|
+
from datetime import UTC, datetime
|
|
120
|
+
|
|
121
|
+
from courant.llm import LISTING_HOST, LLMError, public_listing
|
|
122
|
+
from courant.llm.allowlist import ALLOWLIST, READ_ON
|
|
123
|
+
from courant.llm.policy import refresh
|
|
124
|
+
|
|
125
|
+
dropped: dict[str, str] = {}
|
|
126
|
+
live = False
|
|
127
|
+
console.print(f"[dim]contacting {LISTING_HOST}: OpenRouter's public model listing, "
|
|
128
|
+
"without a key[/dim]\n")
|
|
129
|
+
try:
|
|
130
|
+
listing = public_listing()["models"]
|
|
131
|
+
live = True
|
|
132
|
+
except LLMError as exc:
|
|
133
|
+
console.print(f"[yellow]Could not read OpenRouter's live listing[/yellow] "
|
|
134
|
+
f"({exc.message}); showing the committed allowlist only.\n")
|
|
135
|
+
if live:
|
|
136
|
+
today = datetime.now(UTC).date()
|
|
137
|
+
_, gone = refresh(ALLOWLIST.get("openrouter", []), listing, today)
|
|
138
|
+
dropped = {entry["id"]: reason for entry, reason in gone}
|
|
139
|
+
|
|
140
|
+
table = Table(box=None, padding=(0, 2, 0, 0))
|
|
141
|
+
for column in ("provider", "model", "capabilities", "zdr", "measured", "expires", "today"):
|
|
142
|
+
# The id is what a refresh or a pin needs verbatim, so it never wraps or truncates.
|
|
143
|
+
table.add_column(column, style="cyan" if column == "model" else None,
|
|
144
|
+
no_wrap=column == "model")
|
|
145
|
+
for provider, entries in ALLOWLIST.items():
|
|
146
|
+
for entry in entries:
|
|
147
|
+
measured = ", ".join(f"{task}: {run}" for task, run in entry["measured"].items())
|
|
148
|
+
status = (f"[red]{dropped[entry['id']]}[/red]" if entry["id"] in dropped
|
|
149
|
+
else ("listed" if live and provider == "openrouter" else "—"))
|
|
150
|
+
table.add_row(provider, entry["id"], ", ".join(entry["capabilities"]),
|
|
151
|
+
{True: "yes", False: "no", None: "unknown"}[entry["zdr"]],
|
|
152
|
+
measured or "not yet (ARC-12)", entry["expires"] or "—", status)
|
|
153
|
+
|
|
154
|
+
console.print(f"[bold]The model door's allowlist[/bold], read {READ_ON} "
|
|
155
|
+
f"(courant/llm/allowlist.py)\n")
|
|
156
|
+
console.print(table)
|
|
157
|
+
console.print("\nCustomer data goes only to zdr: yes (ARC-9). A model diagnoses only once "
|
|
158
|
+
"it is measured on diagnosis (ARC-12). Paid models need S's "
|
|
159
|
+
"COURANT_ALLOW_PAID_LLM=1 and a caller that pins them.")
|
|
160
|
+
if dropped:
|
|
161
|
+
console.print("[yellow]Refresh the allowlist:[/yellow] "
|
|
162
|
+
"python scripts/llm_allowlist.py refresh")
|