Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/be-gate-parameters.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Belgium's `gates.json` rows now pass the transport gate registry's validators, ahead of Belgium's transport graph (PR 4b). `calibration_per_family_fit` is not applicable until d1902 rules on the method card's fit tolerances, as NZ's was before its ruling. Its notes carry the proposed parameters. `demographics_vs_statbel` selects the demography family in place of an unroutable `surface` key. `nonnegative_columns` and `formula_owned_export` declare their column lists: the source manifest's non-negative outputs, and the variables Belgium's Axiom bindings request. `commune_fiscal_income_fit` is not applicable until Belgium has commune-grain references and a commune tolerance, and its unroutable `report_worst_fit` key moves into its notes. A new test, `test_be_gate_manifest.py`, runs the battery's validators on Belgium's manifest. Belgium stays inactive.
56 changes: 37 additions & 19 deletions packages/microcosm-build/src/microcosm/build/be/gates.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
"gate": "per_family_fit",
"phase": "terminal",
"criticality": "release_blocking",
"parameters": {
"within": 0.1,
"min_family_share": 0.8
},
"notes": "Calibration fit per source family (demography, fiscal income, income tax, social security, caseloads) so no family hides in the average."
"not_applicable": "awaiting d1902: Belgium's per-family fit tolerances (method card BE-MC6) are proposed, not ruled. Shared runner defaults and other countries' numbers may not silently govern Belgium.",
"notes": "Calibration fit per source family so no family hides in the average. Activate when d1902 rules BE-MC6's fit tolerances, before any calibrated Belgian candidate. BE-MC6 proposes every calibration target within 5% and demography within 2%. NZ's ruled d1376 wrote its two tolerances as two per_family_fit rows, each with evidence_absent_blocks true: one at 5% over its calibration families and demography_per_family_fit at 2%, each with within = hard_within, min_family_share = min_hard_family_share = 1 and min_family_size = 1, so a one-target family gates too. Belgium's 2% lives in demographics_vs_statbel (aggregate_admin), so on activation this row takes within = hard_within = 0.05, both family shares 1, min_family_size 1 and evidence_absent_blocks true as NZ's rows carry; a demography per_family_fit row at 0.02, as NZ has, is the other option. NZ's rows also list their families, so a missing calibration family fails the row; without families, target_profile_coverage is what catches a missing family. Only hard_within, min_hard_family_share and min_family_size decide pass or fail; within and min_family_share are reported."
},
{
"id": "national_and_nuts1_admin_aggregates",
Expand All @@ -29,20 +26,15 @@
],
"default_rtol": 0.05
},
"notes": "Intended weighted aggregates against admin anchors on the future hard surface. The tier metadata in target_references.json is declaration-only in this change; a later runner integration must explicitly bridge it into gate tolerances."
"notes": "Intended weighted aggregates against admin anchors on the future hard surface. The tier metadata in target_references.json is declaration-only in this change; a later runner integration must explicitly bridge it into gate tolerances. default_rtol 0.05 is BE-MC6's administrative-aggregate tolerance, proposed and pending d1902; it equals the 5% each non-demography reference's fit_tolerance carries today. The row stays applicable on purpose, so it binds as soon as a country-level reference activates. Until then it fails on a calibrated surface, because its country level selects no active reference. demographics_vs_statbel is Belgium's live fit grading while calibration_per_family_fit waits on d1902, and a d1902 ruling moves all three rows. Every anchor the row selects, the NUTS1 demography anchors included, is graded at default_rtol; demographics_vs_statbel holds the demography anchors to 2%."
},
{
"id": "commune_fiscal_income_fit",
"gate": "aggregate_admin",
"phase": "terminal",
"criticality": "diagnostic",
"parameters": {
"geography_levels": [
"commune"
],
"report_worst_fit": 25
},
"notes": "Commune-grain diagnostics render per-target fit with the worst-fit communes named; promotion to release_blocking is a spine-quality decision (populace#263), not a default."
"not_applicable": "Belgium has no commune-grain fiscal income calibration reference: commune fiscal income waits for a later commune spine gate, and no ruling sets a commune tolerance, so aggregate_admin has no anchor to select and no default_rtol to apply.",
"notes": "Commune-grain diagnostics should render per-target fit with the 25 worst-fit communes named; promotion to release_blocking is a spine-quality decision (populace#263), not a default. Activate with commune fiscal-income calibration references, families [fiscal_income], geography_levels [commune] and a ruled default_rtol. aggregate_admin names every anchor that misses default_rtol, with its miss; a ranked worst-25 list that also shows passing communes needs a shared binding parameter first."
},
{
"id": "target_profile_coverage",
Expand Down Expand Up @@ -77,10 +69,12 @@
"phase": "terminal",
"criticality": "release_blocking",
"parameters": {
"surface": "demography",
"families": [
"demography"
],
"default_rtol": 0.02
},
"notes": "The US demographics.json / base_population_scale posture against Statbel population structure: age-band x sex x region totals within tight tolerance."
"notes": "The US demographics.json / base_population_scale posture against Statbel population structure: age-band x sex x region totals within tight tolerance. families [demography] selects the compiled demography anchors (all NUTS1 today). default_rtol 0.02 is BE-MC6's demography tolerance, proposed and pending d1902, as each demography reference's fit_tolerance also is. The row stays applicable on purpose: it is Belgium's live fit grading while calibration_per_family_fit waits on d1902, and a d1902 ruling moves it, national_and_nuts1_admin_aggregates and calibration_per_family_fit together."
},
{
"id": "exported_nonzero",
Expand All @@ -95,16 +89,40 @@
"gate": "formula_owned_export",
"phase": "terminal",
"criticality": "release_blocking",
"parameters": {},
"notes": "No Axiom derived-rule output may persist as a dataset input (a stored engine output masks reforms) \u2014 enforced from day one; the adapter's writer refuses such columns and this gate re-checks the artifact."
"parameters": {
"formula_owned_columns": [
"belgium_family_benefits_eligibility_gated_monthly_amount",
"belgium_lgaf_selected_monthly_indexed_amount",
"brussels_family_benefits_article_7_base_monthly_amount",
"brussels_family_benefits_article_9_social_supplement_monthly_amount",
"brussels_family_benefits_child_entitlement",
"brussels_family_benefits_eligible_monthly_amount",
"brussels_family_benefits_selected_monthly_amount",
"flanders_family_benefits_child_entitlement",
"flanders_family_benefits_eligible_monthly_amount",
"flanders_family_benefits_selected_monthly_amount",
"german_speaking_community_family_benefits_eligible_monthly_amount",
"german_speaking_community_family_benefits_selected_monthly_amount",
"german_speaking_community_family_benefits_statutory_base_entitlement",
"wallonia_family_benefits_child_entitlement",
"wallonia_family_benefits_eligible_monthly_amount",
"wallonia_family_benefits_selected_monthly_amount"
]
},
"notes": "No Axiom derived-rule output may persist as a dataset input (a stored engine output masks reforms) \u2014 enforced from day one; the adapter's writer refuses such columns and this gate re-checks the artifact. Until Belgium's export contract lists its formula-owned exclusions, formula_owned_columns is every variable a binding in axiom_rules_bindings.json requests, so the gate checks those outputs only."
},
{
"id": "nonnegative_columns",
"gate": "nonnegative_columns",
"phase": "terminal",
"criticality": "release_blocking",
"parameters": {},
"notes": "Physically non-negative columns (incomes, contributions) carry no negatives; the column list follows the source manifest's nonnegative_outputs."
"parameters": {
"columns": [
"household_weight",
"age"
]
},
"notes": "Physically non-negative columns carry no negatives. columns is the source manifest's nonnegative_outputs (household_weight and age today); incomes and contributions join the list when the source manifest declares them."
},
{
"id": "macro_realism_nbb",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"""Belgium's gates.json against the transport gate registry.

Belgium has no transport graph yet, so no ``gates.battery@1`` node parses
this manifest. These tests run the battery's own validators on it now, so a
row the registry cannot route or complete fails here, not in the first
Belgian battery node. NZ's twin is ``TestNewZealandManifest`` in
test_transport_gate_bindings.py.
"""

from __future__ import annotations

import json

import pytest

from microcosm.build.country_spec import load_country_spec
from microcosm.build.gate_battery import validate_gate_parameters
from microcosm.build.transport.gate_bindings import (
TRANSPORT_GATE_REGISTRY,
validate_required_gate_parameters,
)
from test_support.paths import paths_for

BE_ROOT = paths_for("microcosm-build").package / "src/microcosm/build/be"


@pytest.fixture(scope="module")
def spec():
return load_country_spec("be")


def _entry(spec, entry_id: str):
(entry,) = (e for e in spec.gates.gates if e.id == entry_id)
return entry


#: Applicable rows whose gate has no transport binding yet. Both validators
#: skip them, so they report a gap rather than a pass or a refusal.
UNBOUND_APPLICABLE = {"macro_realism_nbb"}


def test_parameters_are_routed_and_complete(spec) -> None:
validate_gate_parameters(spec.gates, TRANSPORT_GATE_REGISTRY)
validate_required_gate_parameters(spec.gates, TRANSPORT_GATE_REGISTRY)


def test_every_gate_is_bound_or_declared_not_applicable(spec) -> None:
# The validators skip a row whose gate has no binding, so a shared change
# that dropped a binding Belgium uses would leave the test above passing.
unbound = {
entry.id
for entry in spec.gates.gates
if entry.not_applicable is None and entry.gate not in TRANSPORT_GATE_REGISTRY
}
assert unbound == UNBOUND_APPLICABLE


def test_nonnegative_columns_are_the_source_manifest_list(spec) -> None:
declared = list(
dict.fromkeys(
column
for stage in spec.sources.stages
for column in stage.nonnegative_outputs
)
)
assert list(_entry(spec, "nonnegative_columns").parameters["columns"]) == declared


def test_formula_owned_columns_are_the_bound_rule_outputs(spec) -> None:
# Until Belgium has an export contract; then pin formula_owned_excluded,
# as NZ does.
bindings = json.loads(
(BE_ROOT / "axiom_rules_bindings.json").read_text(encoding="utf-8")
)["bindings"]
bound = sorted({column for row in bindings for column in row["variables"]})
entry = _entry(spec, "formula_owned_export")
assert list(entry.parameters["formula_owned_columns"]) == bound


def test_fit_tolerances_wait_for_d1902_in_both_places(spec) -> None:
# BE-MC6's fit tolerances are a proposal (d1902). They live in each
# reference's fit_tolerance and in these rows, so a ruling moves both:
# the per-family row takes parameters (its notes give them) when BE-MC6
# stops being pending. The card lets d1902 rule its rows one by one, so
# this reads the BE-MC6 references' status only. The generator writes one
# status for every card row today (METHOD_CARD_STATUS in
# tools/generate_be_target_references.py); ruling BE-MC6 alone needs
# per-row statuses there first.
statuses = {
reference.metadata["method_card_status"]
for reference in spec.target_references
if reference.metadata["method_card_row"] == "BE-MC6"
}
assert statuses, "no reference names method card row BE-MC6"
fit = _entry(spec, "calibration_per_family_fit")
assert (fit.not_applicable is not None) is (statuses == {"proposed_pending_d1902"})
if fit.not_applicable is not None:
assert fit.not_applicable.startswith("awaiting d1902:")
# The two aggregate_admin rows stay applicable with BE-MC6's unruled 2%
# and 5%: demography's is the live fit grading while the per-family row
# waits, and the national row binds once a country-level reference
# activates. The national pin ties BE-MC6's administrative-aggregate 5%
# to the per-target 5% in the references' fit_tolerance; they coincide
# today, and a ruling that splits them changes this pin.
for entry_id in ("demographics_vs_statbel", "national_and_nuts1_admin_aggregates"):
assert _entry(spec, entry_id).not_applicable is None, entry_id
demography_tolerances = {
float(reference.metadata["fit_tolerance"])
for reference in spec.target_references
if reference.family == "demography"
}
demography = _entry(spec, "demographics_vs_statbel").parameters
assert demography_tolerances == {demography["default_rtol"]}
assert list(demography["families"]) == ["demography"]
other_tolerances = {
float(reference.metadata["fit_tolerance"])
for reference in spec.target_references
if reference.family != "demography"
}
national = _entry(spec, "national_and_nuts1_admin_aggregates").parameters
assert other_tolerances == {national["default_rtol"]}


def test_commune_row_waits_for_commune_fiscal_income_references(spec) -> None:
entry = _entry(spec, "commune_fiscal_income_fit")
assert entry.criticality == "diagnostic"
selected = {
(reference.family, reference.ledger_selector.get("geography_level"))
for reference in spec.target_references
}
# Activate the row (families, geography_levels, a ruled default_rtol)
# once a commune fiscal income reference exists.
has_reference = ("fiscal_income", "commune") in selected
assert (entry.not_applicable is not None) is not has_reference
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,17 @@ def test_the_be_spec_runs_as_declared_with_named_gaps(self, tmp_path, monkeypatc
run.run_phase("terminal", EvidenceContext())
report = json.loads((tmp_path / "terminal_gates.json").read_text())
assert set(report["gates"]) == {gate.id for gate in spec.gates.gates}
declared = {gate.id: gate.not_applicable for gate in spec.gates.gates}
assert all(
gate["status"] == "evidence_absent" for gate in report["gates"].values()
), "unimplemented BE gates are named gaps, never crashes or passes"
gate["status"] == "evidence_absent"
or (
gate["status"] == "not_applicable"
and gate["reason"] == declared[gate_id]
)
for gate_id, gate in report["gates"].items()
), (
"unbound BE gates are named gaps or declared exclusions, never crashes or passes"
)
assert report["shippable"] is False
assert len(report["gates_manifest_sha256"]) == 64
assert (
Expand Down
4 changes: 2 additions & 2 deletions packages/microcosm-build/tests/golden/be_country_spec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"country": "be",
"fingerprint": "d35397e4071d5eb7b5e293ee17a0847eb18f79ef15cad708365d80416ea8d67b",
"fingerprint": "d482b2f983feecc744541ac16f3a01e61d45f06614bbbcd09530c2037983ddde",
"gate_ids": [
"calibration_per_family_fit",
"national_and_nuts1_admin_aggregates",
Expand Down Expand Up @@ -33,7 +33,7 @@
"axiom_rules_bindings.json": "0d8c9670cc22761f90fba5df99c27bfea420708dad94926248da7dc1cea3a589",
"chronicle_feed.json": "71f3967cefa12d8ad6c4b955547bfc37e33183ee839b3edf3a43e0cb72559030",
"country_package.json": "204c8c06934160c856d86a9d6c5305d40e9b3a85713c11c3ab031bebb27fbe89",
"gates.json": "df207d9fbb7142a24b09f1987d87d6285031bacdd547c443eb6832cbe30c8424",
"gates.json": "9704a0c86b324d4243365a320438b47a9d7d5a6af7ec2adfa1821ecb8d611f68",
"geography_spine.json": "090b83a4fa511e691b8f1486bc4188e4170cf9d4a1239e7418d33d5020ceca50",
"holdout_references.json": "c9d32204b4c6364a95fcab066cbbc8b1b99dd49ef608e72c99009f01c7d1c942",
"precal_references.json": "321bd4bd675b80c2e3241e19346fb191b72c8a0c101080dca27bae061c3edd89",
Expand Down
Loading