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 / e32 says 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 factor Fs = 1.25 for 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 sets deterministic;

  • NOT_TESTABLE: the model does not declare dt_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: ValueError

The 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: object

How 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 r between levels, greater than 1.

Type:

float

refine

What to refine: dt, optionally with dx.

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 convergence section, 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: object

Richardson-type estimates from three levels. gci_fine is relative to the fine value.

to_dict() → dict[str, Any][source]

The estimate as a plain dictionary.

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, medium f2 and coarse f3.

class abmfact.verify.convergence.ConvergenceResult(data: dict[str, Any])[source]

Bases: object

The 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.

by_claim() → dict[str, str][source]

Each claim’s id mapped to its verdict.

to_json(include_timestamp: bool = True) → str[source]

The result as indented JSON with sorted keys; include_timestamp=False drops created.

abmfact.verify.convergence.level_knobs(k: int, settings: ConvergenceSettings, refine_dx: bool) → Knobs[source]

Knobs for level k: dt_scale is ratio**-k, and so is dx_scale when refine_dx is 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: ValueError

A comparison file or option is not valid.

class abmfact.verify.compare.Budget(absolute: float | None = None, relative: float | None = None)[source]

Bases: object

How far an engine’s mean may sit from the baseline’s and still agree.

Exactly one of absolute (in the metric’s units) or relative (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.

margin(baseline: ndarray) → float[source]

The budget in the metric’s units, given the baseline engine’s values.

describe() → str[source]

The budget in words.

class abmfact.verify.compare.CompareMetric(metric: Metric, budget: Budget, note: str = '')[source]

Bases: object

One 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: object

A 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 baseline names 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_start to seed_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:

list[abmfact.verify.compare.CompareMetric]

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 into options in order, so a frozen comparison takes calibrated gains without being edited.

Type:

dict[str, list[str]]

seeds_for(engine: str) → int[source]

The number of seeds engine runs.

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.

overrides replaces top-level keys, such as seeds or jobs from the command line.

class abmfact.verify.compare.CompareResult(data: dict[str, Any])[source]

Bases: object

The 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.

to_json(include_timestamp: bool = True) → str[source]

The result as JSON; without the timestamp it is the same for the same runs.

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.