Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.income_tax",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -40,6 +41,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.ni",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -58,6 +60,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.ni_employee",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -76,6 +79,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.ni_employer",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -94,6 +98,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.ni_self_employed",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -112,6 +117,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.vat",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -130,6 +136,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.fuel_duties",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -148,6 +155,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.capital_gains_tax",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -166,6 +174,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.sdlt",
"diagnostic_variable_id": "efo_receipts",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -184,6 +193,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.attendance_allowance",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -202,6 +212,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.carers_allowance",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -220,6 +231,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.child_benefit",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -238,6 +250,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.council_tax",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -256,6 +269,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.esa",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection",
Expand All @@ -275,6 +289,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.housing_benefit",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -293,6 +308,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.jobseekers_allowance",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -311,6 +327,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.pension_credit",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -329,6 +346,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.pip",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -347,6 +365,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.state_pension",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -365,6 +384,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.statutory_maternity_pay",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -383,6 +403,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.tv_licence_fee",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -401,6 +422,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.universal_credit_in_cap",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -419,6 +441,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.universal_credit_outside_cap",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand All @@ -437,6 +460,7 @@
"period": 2025,
"metadata": {
"contract_target_id": "obr.winter_fuel_allowance",
"diagnostic_variable_id": "efo_expenditure",
"measure_kind": "prepared_column"
},
"assertion_policy": "allow_source_projection"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Standard calibration diagnostics for UK release candidates.

The shared :mod:`microcosm.calibrate.diagnostics` payload is the release
contract: it carries the target surface, every target row, solver options, and
the concentration scalars used by US releases. UK needs a little more release
evidence without changing that shared schema (and therefore without changing
US output): the effective-sample-size fraction, shipped-weight concentration,
zero-weight rows split by their declared support strata, and target fit by UK
geography level.
contract: it carries the target surface, every target row, solver options,
schema-7 source/variable/dimension identity, and the concentration scalars used
by US releases. UK adds the effective-sample-size fraction, shipped-weight
concentration, zero-weight rows split by their declared support strata, and
target fit by UK geography level.

This module wraps the shared payload and places those additions under a
separately versioned ``uk_diagnostics`` block. The common top-level
Expand Down
2 changes: 1 addition & 1 deletion packages/microcosm-build/tests/test_uk_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def test_payload_requires_a_valid_matching_uk_registry() -> None:
target_geography_levels=geography,
target_registry=TargetRegistry((), country="uk"),
)
with pytest.raises(ValueError, match="exactly partition"):
with pytest.raises(ValueError, match="does not contain compiled target row"):
uk_calibration_diagnostics_payload(
result,
frame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def test_candidate_build_writes_calibrated_h5_and_evidence(
assert diagnostics["metric"].unique().tolist() == ["households"]
assert len(support) == 8
assert past_cap["n_targets"] == 4
assert calibration_diagnostics["schema_version"] == 6
assert calibration_diagnostics["schema_version"] == 7
uk_diagnostics = calibration_diagnostics["uk_diagnostics"]
assert len(uk_diagnostics["weakest_families"]) == 1
assert len(uk_diagnostics["weakest_areas_by_fit"]["bottom_by_fit"]) == 4
Expand Down
49 changes: 48 additions & 1 deletion packages/microcosm-build/tests/test_uk_target_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
TargetReferenceAuthoringConfig,
author_target_references,
)
from microcosm.calibrate.diagnostics import diagnostics_payload
from microcosm.calibrate.matrix import build_constraint_matrix
from microcosm.calibrate.score import score_targets
from microcosm.frame import EntitySchema, Frame, WeightKind, Weights
from tools.generate_uk_target_references import (
OBR_DIAGNOSTIC_VARIABLE_BY_TARGET_ID,
POLICYENGINE_BINDING_KEYS,
_annual_uc_award_band_token,
_geography_pins,
Expand Down Expand Up @@ -128,10 +131,16 @@ def test_uk_target_references_follow_contract_derivation_rules() -> None:
assert reference["measure"] == expected_measure
assert reference["family"] == target["family"]
assert reference["period"] == 2025
assert reference["metadata"] == {
expected_metadata = {
"contract_target_id": contract_target_id,
"measure_kind": "prepared_column",
}
diagnostic_variable_id = OBR_DIAGNOSTIC_VARIABLE_BY_TARGET_ID.get(
contract_target_id
)
if diagnostic_variable_id is not None:
expected_metadata["diagnostic_variable_id"] = diagnostic_variable_id
assert reference["metadata"] == expected_metadata
# The measure is a prepared column, so the pointed-to contract binding
# must carry what the microcosm#622 materializer needs to prepare it.
assert (
Expand All @@ -152,6 +161,29 @@ def test_uk_target_references_do_not_bind_known_mismatched_property_amounts() ->
]


def test_uk_obr_references_declare_receipts_and_expenditure_categories() -> None:
references = _load_uk_resource("target_references.json")["target_references"]
obr_references = [
reference
for reference in references
if reference["metadata"]["contract_target_id"].startswith("obr.")
]

assert len(obr_references) == len(OBR_DIAGNOSTIC_VARIABLE_BY_TARGET_ID)
assert {
reference["metadata"]["contract_target_id"]: reference["metadata"][
"diagnostic_variable_id"
]
for reference in obr_references
} == OBR_DIAGNOSTIC_VARIABLE_BY_TARGET_ID
assert not [
reference["name"]
for reference in references
if not reference["metadata"]["contract_target_id"].startswith("obr.")
and "diagnostic_variable_id" in reference["metadata"]
]


def test_uk_target_references_do_not_emit_nan_uc_payment_bands() -> None:
resource = _load_uk_resource("target_references.json")

Expand Down Expand Up @@ -418,6 +450,7 @@ def test_uk_target_references_compile_from_real_staged_feed_rows() -> None:
assert income_tax.period == 2025
assert income_tax.metadata["ledger_assertion"] == "source_projection"
assert income_tax.metadata["ledger_assertion_policy"] == ("allow_source_projection")
assert income_tax.metadata["diagnostic_variable_id"] == "efo_receipts"

tcl_households = targets["dwp.uc.two_child_limit.households_affected"]
assert tcl_households.value == 469_780
Expand Down Expand Up @@ -558,6 +591,20 @@ def test_uk_target_references_constrain_a_frame_with_prepared_columns() -> None:
for name, target_value in zip(problem.names, problem.target_vector, strict=True):
assert target_value == fact_values_by_name[name], name

diagnostics = diagnostics_payload(
score_targets(frame, registry.to_target_set()),
target_registry=registry,
)
obr_variables = {
row["name"]: row["variable"]["id"]
for row in diagnostics["targets"]
if row["source"]["id"] == "obr"
}
assert obr_variables == {
"obr.esa@2025": "efo_expenditure",
"obr.income_tax@2025": "efo_receipts",
}


def _real_uk_consumer_fact_rows() -> list[dict]:
"""Public rows copied from .codex-work/consumer_facts_uk.jsonl."""
Expand Down
Loading
Loading