Verification¶
Convergence under time-step and voxel refinement, and comparison of one model across engines.
abmfact.verify¶
Verification beyond the audit checks: convergence under time-step and voxel refinement.
abmfact.verify.convergence¶
Convergence under refinement of the time step and, where a model supports it, the voxel size.
For every claim’s metric at every parameter point, the model runs at three levels: level k scales
dt (and the voxel size, when the model declares dx_scale) by r**-k with r = 2. Each level
runs the audit’s seeds, so the estimates are ensemble means with intervals. With f3 the coarsest
and f1 the finest mean, e21 = f2 - f1 and e32 = f3 - f2:
the convergence ratio
R = e21 / e32says whether the levels converge monotonically (0 < R < 1), oscillate (-1 < R < 0) or diverge (|R| >= 1);the observed order is
p = ln(e32 / e21) / ln(r);the grid convergence index of the fine solution is
GCI = Fs |e21 / f1| / (r**p - 1)with safety factorFs = 1.25for three levels (Roache, 1994; 1998).
Verdicts compare the change between the two finest levels with a tolerance (the claim’s own, or 10% of the fine mean as in the audit) using the same three-outcome equivalence test as the audit:
CONVERGED: the change between the two finest levels lies within the tolerance;NOT_CONVERGED: the change between levels is established (its intervals exclude zero) and grows with refinement, whatever its size; or it lies outside the tolerance; or a level gave non-finite values (the solution blew up);INCONCLUSIVE: the intervals are too wide to decide (the result says how many seeds would settle it), or every seed gave the same value at some level, so noise cannot be told from discretisation error (the audit treats such degenerate data the same way); a deterministic model setsdeterministic;NOT_TESTABLE: the model does not declaredt_scale.
Roache, P. J. (1994). Perspective: a method for uniform reporting of grid refinement studies. Journal of Fluids Engineering, 116(3), 405-413. Roache, P. J. (1998). Verification and Validation in Computational Science and Engineering. Hermosa.
- exception abmfact.verify.convergence.ConvergenceError[source]¶
Bases:
ValueErrorThe convergence settings are not valid.
- class abmfact.verify.convergence.ConvergenceSettings(levels: int = 3, ratio: float = 2.0, refine: tuple[str, ...] = ('dt', 'dx'), safety_factor: float = 1.25, deterministic: bool = False)[source]¶
Bases:
objectHow a convergence study refines the model and estimates the GCI.
- levels¶
The number of refinement levels; only 3 is accepted.
- Type:
int
- ratio¶
The refinement ratio
rbetween levels, greater than 1.- Type:
float
- refine¶
What to refine:
dt, optionally withdx.- Type:
tuple[str, …]
- safety_factor¶
The GCI safety factor
Fs.- Type:
float
- deterministic¶
Whether the model is meant to give the same value for every seed.
- Type:
bool
- classmethod from_mapping(m: Mapping[str, Any] | None) ConvergenceSettings[source]¶
Settings from a mapping such as an audit’s
convergencesection, using the defaults for missing keys.- Raises:
ConvergenceError – A key is unknown or a value is out of range.
- class abmfact.verify.convergence.GCIEstimate(e21: float, e32: float, ratio_R: float | None, kind: str, order: float | None, extrapolated: float | None, gci_fine: float | None)[source]¶
Bases:
objectRichardson-type estimates from three levels.
gci_fineis relative to the fine value.
- abmfact.verify.convergence.gci(f1: float, f2: float, f3: float, r: float = 2.0, safety_factor: float = 1.25) GCIEstimate[source]¶
Observed order, extrapolated value and GCI from fine
f1, mediumf2and coarsef3.
- class abmfact.verify.convergence.ConvergenceResult(data: dict[str, Any])[source]¶
Bases:
objectThe outcome of
converge().- data¶
The full result: tool and environment, audit, settings, levels, a verdict per claim and a summary.
- Type:
dict[str, Any]
- property verdicts: list[dict[str, Any]]¶
One row per claim, with its verdict, reason and per-point detail.
- property any_not_converged: bool¶
Whether any claim has the verdict
NOT_CONVERGED.
- abmfact.verify.convergence.level_knobs(k: int, settings: ConvergenceSettings, refine_dx: bool) Knobs[source]¶
Knobs for level
k:dt_scaleisratio**-k, and so isdx_scalewhenrefine_dxis set.
- abmfact.verify.convergence.converge(audit: Audit, settings: ConvergenceSettings | None = None, progress: Callable[[int, int], None] | None = None) ConvergenceResult[source]¶
Run every claim’s metric at three refinement levels and judge convergence.
abmfact.verify.compare¶
Compare one model across engines (docking) against a declared disagreement budget.
The same ABM-IR model runs in each engine over the same seeds. For every metric the engines’ means are compared with the baseline engine’s by a Welch interval for the difference, and the interval is read against the metric’s budget with the same three-outcome test as the audit:
AGREE: the whole interval lies within the budget;DISAGREE: the whole interval lies outside it;INCONCLUSIVE: neither; the result says how many seeds would settle it;NOT_RUN: the engine refused the model, is not installed here, or every run failed.
Agreement within a budget is numerical equivalence. A comparison may also name threshold claims (from an audit file); each engine’s status for each claim (holds, fails, uncertain) shows whether the engines draw the same conclusion, which is relational equivalence (Axtell et al., 2000). A translated model is a second implementation, so each engine’s fidelity report is kept beside its verdicts.
Budgets belong to the comparison file and are meant to be written before any run, as audit claims are.
Axtell, R., Axelrod, R., Epstein, J. M. and Cohen, M. D. (1996). Aligning simulation models: a case study and results. Computational and Mathematical Organization Theory, 1(2), 123-141.
- exception abmfact.verify.compare.CompareError[source]¶
Bases:
ValueErrorA comparison file or option is not valid.
- class abmfact.verify.compare.Budget(absolute: float | None = None, relative: float | None = None)[source]¶
Bases:
objectHow far an engine’s mean may sit from the baseline’s and still agree.
Exactly one of
absolute(in the metric’s units) orrelative(a fraction of the absolute baseline mean) is set.- classmethod parse(raw: Any) Budget[source]¶
A number is an absolute budget;
{relative: f}or{absolute: x}say which.
- class abmfact.verify.compare.CompareMetric(metric: Metric, budget: Budget, note: str = '')[source]¶
Bases:
objectOne compared metric, its budget and why the budget is that size.
- class abmfact.verify.compare.Comparison(title: str, model: ~pathlib.Path, engines: list[str], baseline: str, metrics: list[~abmfact.verify.compare.CompareMetric], options: dict[str, dict[str, ~typing.Any]] = <factory>, params: dict[str, ~typing.Any] = <factory>, seeds: int = 10, seed_start: int = 0, jobs: int = 1, alpha: float = 0.05, claims: list[~abmfact.claims.Claim] = <factory>, seeds_by_engine: dict[str, int] = <factory>, notes: dict[str, str] = <factory>, options_from: dict[str, list[str]] = <factory>)[source]¶
Bases:
objectA parsed comparison: one model, several engines, metrics with budgets, and optional claims.
- title¶
A short title.
- Type:
str
- model¶
The ABM-IR model file.
- Type:
pathlib.Path
- engines¶
Engine names; the first is the baseline unless
baselinenames another.- Type:
list[str]
- baseline¶
The engine every other is compared with.
- Type:
str
- options¶
Engine options by engine name, as for
run-model --option.- Type:
dict[str, dict[str, Any]]
- params¶
ABM-IR parameters applied in every engine.
- Type:
dict[str, Any]
- seeds¶
Seeds per engine (
seed_starttoseed_start + seeds - 1).- Type:
int
- seed_start¶
The first seed, so a follow-up can draw seeds an earlier comparison has not seen.
- Type:
int
- jobs¶
Runs at once.
- Type:
int
- alpha¶
One-sided significance level; intervals cover
1 - 2*alpha.- Type:
float
- metrics¶
The compared metrics.
- Type:
- claims¶
Threshold claims whose status is reported per engine.
- Type:
list[abmfact.claims.Claim]
- seeds_by_engine¶
Fewer seeds for a slow engine, with the reason in
notes.- Type:
dict[str, int]
- notes¶
Free-text notes kept in the result.
- Type:
dict[str, str]
- options_from¶
T2 translation files (
translation.json), one or a list per engine; their calibrated gains are merged intooptionsin order, so a frozen comparison takes calibrated gains without being edited.- Type:
dict[str, list[str]]
- abmfact.verify.compare.load_comparison(path: str | Path, overrides: Mapping[str, Any] | None = None) Comparison[source]¶
Read a comparison file; relative paths are resolved against its folder.
overridesreplaces top-level keys, such asseedsorjobsfrom the command line.
- class abmfact.verify.compare.CompareResult(data: dict[str, Any])[source]¶
Bases:
objectThe outcome of a comparison.
- data¶
The full result: tool and environment, the comparison, each engine’s runs, a verdict per metric and engine, each engine’s claim statuses, and a summary.
- Type:
dict[str, Any]
- property verdicts: list[dict[str, Any]]¶
One verdict per metric and compared engine.
- property any_disagree: bool¶
True when any engine disagrees with the baseline on any metric.
- abmfact.verify.compare.compare(cmp: Comparison, workdir: str | Path | None = None, store: str | Path | None = None, progress: Callable[[int, int], None] | None = None) CompareResult[source]¶
Run the model in every engine over its seeds and compare each metric with the baseline engine.
- Parameters:
cmp – The comparison.
workdir – Where run folders go; a temporary folder by default.
store – A run store; finished runs are kept there and reused when the comparison is run again.
progress – Called with
(done, total)after each run.
- abmfact.verify.compare.comparison_from_model(model: str | Path, engines: Sequence[str], metrics: Sequence[str], budget: float, seeds: int, jobs: int) Comparison[source]¶
A quick comparison from the command line: every metric gets the same relative budget.