Planted-fault zoo and command line

The validation models, the demo that audits them, and the command-line entry points.

abmfact.zoo

Planted-fault zoo: one clean reference model and one model per check, each with a single known bug.

The reference model is an SIR epidemic on an L x L torus with one agent per cell. A fraction immune of agents, drawn at random, starts recovered. Patient zero is a plus of five agents at (x0, y0). Each infected von Neumann neighbour adds beta to a susceptible agent’s hazard, every infected agent anywhere adds beta_g / N (weak global mixing), and infected agents recover at rate gamma. Transition probabilities are 1 - exp(-rate * dt), and every update is computed from a snapshot of the state at the start of the step. Activation order therefore only decides which random number each agent receives, so a correct implementation gives the same distribution of results under every order. The grid knobs move the whole world (agents, ids and initial state) relative to the array.

Each fault_* model differs from the clean model in exactly one place, marked # FAULT. A second clean model with a diffusing nutrient (field_clean) carries one more fault, unstable_diffusion, that only the convergence check can catch. The acceptance test checks the exact expected detection matrix: each fault caught by its own check and by no other, except one documented overlap (EXPECTED_ALSO): dt_unscaled is also caught by the convergence check, because both refine dt.

abmfact.zoo.EXPECTED_CHECK = {'boundary': 'grid', 'density': 'population_scale', 'dt_unscaled': 'time_step', 'id_dependence': 'agent_order', 'ignored_seed': 'rng_streams', 'nondeterminism': 'determinism', 'stale_state': 'update_order', 'unstable_diffusion': 'convergence'}

Which check is expected to catch each fault.

abmfact.zoo.simulate(params: Mapping[str, Any], seed: int, knobs: Knobs, fault: str | None = None) → dict[str, Any][source]

Run the reference model, optionally with one planted fault.

class abmfact.zoo.ZooRunner(fault: str | None = None)[source]

Bases: object

A picklable run(params, seed, knobs) for one zoo model, so audits can run in parallel.

abmfact.zoo.CLAIMS: list[dict[str, Any]] = [{'id': 'C1', 'metric': 'attack_rate', 'statement': 'most of the population is infected', 'test': 'greater_than', 'value': 0.6}, {'id': 'C2', 'metric': 'attack_rate', 'over': 'beta', 'statement': 'the attack rate rises with local transmission', 'test': 'monotone_increasing', 'where': {'beta': [0.25, 0.4]}}, {'id': 'C3', 'metric': 'peak_prevalence', 'statement': 'peak prevalence stays below half the population', 'test': 'less_than', 'value': 0.5}, {'id': 'C4', 'metric': 'peak_time', 'skip_checks': {'population_scale': 'peak time legitimately grows with system size'}, 'statement': 'the epidemic peaks within 25 time units', 'test': 'less_than', 'value': 25}]

Claims used to validate the checks. They are written the way a paper would state them.

abmfact.zoo.audit_document(model: str = 'clean', seeds: int = 100, jobs: int = 1) → dict[str, Any][source]

The audit file for one zoo model, as a mapping (the same shape as an audit YAML file).

abmfact.zoo.simulate_field(params: Mapping[str, Any], seed: int, knobs: Knobs, fault: str | None = None) → dict[str, Any][source]

Run the field model, optionally with the unstable-diffusion fault.

class abmfact.zoo.FieldRunner(fault: str | None = None)[source]

Bases: object

A picklable run(params, seed, knobs) for one field model.

abmfact.zoo.EXPECTED_ALSO: dict[str, tuple[str, ...]] = {'dt_unscaled': ('convergence',)}

Checks besides the expected one that must also catch a fault, and why. Both the time_step check and the convergence check refine dt, and a rate tied to the calibration step genuinely does not converge.

abmfact.demo

The planted-fault matrix: every zoo model audited by every check.

abmfact.demo.EXTRA_COLUMNS = ('convergence',)

Verification columns beyond the seven audit checks.

abmfact.demo.expected(model: str) → set[str][source]

Every check that must flag model: its own check plus any documented overlap.

class abmfact.demo.DemoResult(flags: dict[str, dict[str, bool]], results: dict[str, ~abmfact.audit.AuditResult], convergence: dict[str, ~typing.Any] = <factory>)[source]

Bases: object

flags[model][check] is True when any claim was flagged by that check.

problems() → list[str][source]

Every deviation from the expected matrix. Empty means the validation passed.

columns() → list[str][source]

Matrix columns: every audit check, then any verification column present, such as convergence.

table() → str[source]

Render the detection matrix as plain text.

A cell reads CAUGHT or MISSED for an expected flag, FALSE for a false alarm, and a dot when the check correctly stayed quiet.

abmfact.demo.run_demo(seeds: int = 100, jobs: int = 1, models: list[str] | None = None, progress: Callable[[str], None] | None = None, convergence: bool = True) → DemoResult[source]

Audit every zoo model with every check and, unless convergence is false, check convergence.

abmfact.cli

Command line: abmfact run | check | demo | init | replay | engines | run-model | import | export | converge | compare | recommend, and the modes in abmfact.modes.commands.

abmfact.cli.print_summary(result: AuditResult, stream: Any = None) → None[source]

Print the verdicts that need attention, the verdict counts, likely causes and claim warnings.

ROBUST, NOT_TESTABLE and SKIPPED rows are left out. stream defaults to standard output.

abmfact.cli.cmd_run(args: Namespace, fail_on_flag: bool) → int[source]

Run abmfact run, or abmfact check with fail_on_flag; exit 1 if check flags a claim, else 0.

abmfact.cli.cmd_demo(args: Namespace) → int[source]

Run abmfact demo; exit code 1 when the detection matrix is not as expected, else 0.

abmfact.cli.cmd_init(args: Namespace) → int[source]

Run abmfact init; exit code 2 when the output file exists without --force, else 0.

abmfact.cli.cmd_replay(args: Namespace) → int[source]

Run abmfact replay and print the run’s outputs as JSON; exit code 0.

abmfact.cli.cmd_engines(args: Namespace) → int[source]

Run abmfact engines and list each engine’s availability and capabilities; exit code 0.

abmfact.cli.cmd_recommend(args: Namespace) → int[source]

Run abmfact recommend and rank the engines for one model; exit code 0.

abmfact.cli.cmd_run_model(args: Namespace) → int[source]

Run abmfact run-model; exit code 1 when the run failed, else 0.

abmfact.cli.cmd_import(args: Namespace) → int[source]

Run abmfact import and write the ABM-IR model with its fidelity report; exit code 0.

abmfact.cli.cmd_export(args: Namespace) → int[source]

Run abmfact export and write the project with its fidelity report; exit code 0.

abmfact.cli.cmd_converge(args: Namespace) → int[source]

Run abmfact converge; exit code 1 when any claim has not converged, else 0.

abmfact.cli.cmd_compare(args: Namespace) → int[source]

Run abmfact compare; exit code 1 when any engine disagrees with the baseline, else 0.

abmfact.cli.build_parser() → ArgumentParser[source]

Build the argument parser with every subcommand and its options.

abmfact.cli.main(argv: Sequence[str] | None = None) → int[source]

Parse argv and run the chosen subcommand.

Returns the exit code: 0 on success, 1 when a command reports a problem, and 2 for an input or configuration error.