From c8da0c72bce48628e94e7af96c1d995b897dadc4 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Wed, 1 Jul 2026 13:40:27 -0700 Subject: [PATCH] feat: tie calibration artefact sets to configs via provenance stamps Calibration artefacts now live in per-config sets under data/curated/calibration//, selected by the new calibration.source config key (a {calibration_source} placeholder in artefact paths, resolved at config-load time). Each set carries a provenance.yaml stamp of the structural config it was calibrated against; every workflow run checks its config against the stamp of the set it consumes and errors on structural mismatch. calibration.accept_provenance_mismatch downgrades the error to a warning for configs where calibration fidelity is irrelevant (test, tutorials). tools/calibrate gains --base to calibrate a dedicated set for a structurally divergent config: the base must declare its own calibration.source, a fresh set is seeded from the default set, the chain runs under name=calibration- to keep processing trees separate, and the set is (re)stamped after each successful run. tools/calibrate --check also reports provenance drift. --- .claude/skills/model-calibration/SKILL.md | 43 +- AGENTS.md | 21 +- REUSE.toml | 8 + config/default.yaml | 37 +- config/schemas/config.schema.yaml | 15 + config/tutorial/01_ghg_prices.yaml | 5 + config/tutorial/02_consumer_values.yaml | 5 + .../calibration/{ => default}/animal_cost.csv | 0 .../calibration/{ => default}/crop_cost.csv | 0 .../{ => default}/deviation_penalty.yaml | 0 .../{ => default}/exogenous_feed.csv | 0 .../{ => default}/exogenous_forage.csv | 0 .../{ => default}/fodder_conversion.csv | 0 .../calibration/{ => default}/food_demand.csv | 0 .../calibration/{ => default}/food_waste.yaml | 0 .../{ => default}/grassland_cost.csv | 0 .../{ => default}/grassland_yield.csv | 0 .../calibration/default/provenance.yaml | 853 ++++++++++++++++++ docs/calibration.rst | 58 +- docs/configuration.rst | 13 +- docs/costs.rst | 6 +- docs/livestock.rst | 20 +- tests/config/test.yaml | 6 + tests/test_calibration_provenance.py | 184 ++++ tests/test_production_stability.py | 2 +- tools/calibrate | 169 +++- tools/export_model.py | 3 +- tools/smk | 2 +- workflow/Snakefile | 5 + workflow/scripts/solve_namespace.py | 27 +- .../scripts/write_calibration_provenance.py | 118 +++ workflow/validation/__init__.py | 2 + workflow/validation/calibration_provenance.py | 173 ++++ 33 files changed, 1702 insertions(+), 73 deletions(-) rename data/curated/calibration/{ => default}/animal_cost.csv (100%) rename data/curated/calibration/{ => default}/crop_cost.csv (100%) rename data/curated/calibration/{ => default}/deviation_penalty.yaml (100%) rename data/curated/calibration/{ => default}/exogenous_feed.csv (100%) rename data/curated/calibration/{ => default}/exogenous_forage.csv (100%) rename data/curated/calibration/{ => default}/fodder_conversion.csv (100%) rename data/curated/calibration/{ => default}/food_demand.csv (100%) rename data/curated/calibration/{ => default}/food_waste.yaml (100%) rename data/curated/calibration/{ => default}/grassland_cost.csv (100%) rename data/curated/calibration/{ => default}/grassland_yield.csv (100%) create mode 100644 data/curated/calibration/default/provenance.yaml create mode 100644 tests/test_calibration_provenance.py create mode 100644 workflow/scripts/write_calibration_provenance.py create mode 100644 workflow/validation/calibration_provenance.py diff --git a/.claude/skills/model-calibration/SKILL.md b/.claude/skills/model-calibration/SKILL.md index 1744bd72..e56e5754 100644 --- a/.claude/skills/model-calibration/SKILL.md +++ b/.claude/skills/model-calibration/SKILL.md @@ -1,6 +1,6 @@ --- name: model-calibration -description: Run, refresh, or diagnose the model's calibration pipeline (feed -> food_waste -> food_demand -> cost -> stability) that produces the git-tracked artefacts under `data/curated/calibration/`. Covers the dependency order, the `tools/calibrate` wrapper, realistic runtime expectations, when each kind of upstream change forces a re-run, and how to diagnose the most common failure mode: a hidden supply/demand mismatch that inflates the production-stability L1 cost. Use whenever calibration is relevant -- the user touches inputs/build logic that feed the calibration solves, calibration artefacts look off, or a refresh of the artefacts is needed after a model/data change. +description: Run, refresh, or diagnose the model's calibration pipeline (feed -> food_waste -> food_demand -> cost -> stability) that produces the per-config artefact sets under `data/curated/calibration//` (the default set is git-tracked). Covers the dependency order, the `tools/calibrate` wrapper, realistic runtime expectations, when each kind of upstream change forces a re-run, and how to diagnose the most common failure mode: a hidden supply/demand mismatch that inflates the production-stability L1 cost. Use whenever calibration is relevant -- the user touches inputs/build logic that feed the calibration solves, calibration artefacts look off, or a refresh of the artefacts is needed after a model/data change. ---