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/nz-donor-profile-selection.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New Zealand's transport graph selects the shared `populace-us-cps-asec` donor profile, version 1, through a new `donor_profile.json` resource that `nz.create` reads whole as its `donor_profile` param. The document records ruling d3058's choices for one engineering measurement run on donor `48b9d479`: `assisted_renter_tenure` is `rented_public_authority` (assisted renters stand in for public-authority tenants, because the donor carries no landlord signal), `blank_full_time_study` is `read_false` (blank study answers read as not full time on this pinned donor) and `housing_cost_contradicting_tenure` is `tenure_wins` (rent or mortgage interest that contradicts the staged tenure is zeroed and counted in CREATE's receipt). The donor stage in `source_stages.json` and its copy in `spec/sources.yaml` now declare the donor's `spm_unit` table, which the profile reader opens, so the source receipt, `nz.create`'s `donor_pin_sha256` and `nz.evidence.donor_receipt`'s `source_stages` params move with that file. `nz.create` and `nz.evidence.donor_receipt` re-key, and so does every other node of the graph, since all of them descend from `nz.create`; a CREATE inventory stored before this change does not serve the profiled run, because its store key includes CREATE's params. One profiled CREATE probe on the pinned donor refreshes the D4 fixture (`create_inventory_populace_us_48b9d479.json` and its provenance): it adds `household.tenure`, `person.enrolled_full_time` and `person.legal_marital_status` and changes no other column, so the declared staging gap is empty and the NZ graph composes against the real inventory alone. The entitlement document also lists the cell diagnostics collector just before `nz.gates.terminal`, so the collector's checkpoint manifest is written even if a node that only the battery's checkpoint runs raises; the composed graph is byte-identical with and without that entry. NZ's golden spec summary moves with these files. No shared source module changes.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@
"path": "export_replay_bindings.json",
"kind": "legacy_json",
"schema_id": "legacy_json"
},
{
"path": "donor_profile.json",
"kind": "legacy_json",
"schema_id": "legacy_json"
}
]
}
11 changes: 11 additions & 0 deletions packages/microcosm-build/src/microcosm/build/nz/donor_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"format": "microcosm.donor-profile/1",
"profile": "populace-us-cps-asec",
"version": 1,
"donor_sha256": "48b9d479fb4fd1c3537f9383ce4697d130b6f618658409d74f6233c43b994c7e",
"choices": {
"assisted_renter_tenure": "rented_public_authority",
"blank_full_time_study": "read_false",
"housing_cost_contradicting_tenure": "tenure_wins"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@
},
"checkpoints": [
"nz.as.bands",
"nz.as.bands.cell_diagnostics",
"nz.gates.terminal"
],
"gate_evidence": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"kind": "read_tables",
"tables": [
"person",
"household"
"household",
"spm_unit"
],
"weight": "household_weight"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
sources:
- byte_size: 2928
- byte_size: 2952
id: nz_populace_us_support_contract
loader: kernel:load_populace_us_support_pool
role: nz_populace_us_support_pool
sha256: cc82c68878ac0fc07ecbd796c1a66de6f34786ef8785125046425c37f26aff31
sha256: a9111d0e319f06de459236bf036468268726969b520ae30b5e68e346b29ad124
vintage_authorities:
- id: nz_support_pool_2024_buildp
kind: survey_period
Expand Down Expand Up @@ -55,6 +55,7 @@ stages:
tables:
- person
- household
- spm_unit
weight: household_weight
outputs:
- person_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
"path": [],
"encoding": "sha256"
},
"donor_profile": {
"resource": "donor_profile",
"path": [],
"encoding": "json"
},
"unit_rule": {
"resource": "benefit_unit_rule",
"path": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
from microcosm.frame import concepts as frame_concepts
from microcosm.frame.concept_mapping import MAPPING_FORMAT
from microcosm.frame.input_closure import INPUT_CLOSURE_FORMAT
from microcosm.frame.transport import DONOR_PROFILE_FORMAT
from test_support.paths import paths_for

_BUILD = paths_for("microcosm-build")
Expand Down Expand Up @@ -1019,7 +1020,7 @@ def _serialized_identifier(key: object, child: object) -> bool:
"""

if key == "format":
return child in {INPUT_CLOSURE_FORMAT, MAPPING_FORMAT}
return child in {INPUT_CLOSURE_FORMAT, MAPPING_FORMAT, DONOR_PROFILE_FORMAT}
return (
key == "type"
and isinstance(child, Mapping)
Expand Down Expand Up @@ -3368,6 +3369,14 @@ def test_the_input_closure_format_identifier_is_not_a_python_symbol(self) -> Non
INPUT_CLOSURE_FORMAT
}

def test_the_donor_profile_format_identifier_is_not_a_python_symbol(self) -> None:
# donor_profile.json's format tag; outside a format key the scan reads
# its dotted prefix as a module that does not exist.
assert dotted_symbol_citations({"format": DONOR_PROFILE_FORMAT}) == set()
assert dotted_symbol_citations({"note": DONOR_PROFILE_FORMAT}) == {
"microcosm.donor"
}

def test_a_declared_artifact_type_is_not_a_python_symbol(self) -> None:
from microcosm.build.transport.income_evidence_kernels import (
OMISSION_REGISTER_TYPE,
Expand Down Expand Up @@ -4218,6 +4227,50 @@ def test_donor_pin_and_us_support_provenance_are_explicit(self) -> None:
assert {"donor_country_code", "support_stratum"} <= set(donor.outputs)
assert "US donor support records" in donor.survey

def test_donor_profile_is_the_d3058_selection_for_the_pinned_donor(self) -> None:
from microcosm.frame.transport import parse_donor_profile
from microcosm.graph.canonical import canonical_json

document = _load("donor_profile.json")
# Composition hands CREATE the canonical text of the whole document
# (transport/compose.py's whole-resource json selection), and the
# shared parser accepts only that spelling.
text = canonical_json(document).decode("utf-8")
profile = parse_donor_profile(text)
assert profile.canonical_text == text
assert document["format"] == DONOR_PROFILE_FORMAT
assert (profile.name, profile.version) == ("populace-us-cps-asec", 1)
# d3058, rules 2 to 5, for one engineering measurement run: assisted
# renters stand in for public-authority tenants (the donor has no
# landlord signal), blank study answers read as not full time on this
# pinned donor only, and tenure wins over contradicting housing costs.
assert dict(profile.choices) == {
"assisted_renter_tenure": "rented_public_authority",
"blank_full_time_study": "read_false",
"housing_cost_contradicting_tenure": "tenure_wins",
}
stages = load_country_spec("nz").sources.stage_map()
(artifact,) = stages["load_populace_us_support_pool"].artifacts
assert profile.donor_sha256 == artifact["sha256"]
assert profile.donor_sha256 == _load("transport_inputs.json")["donor"]["sha256"]
# Whole-document selection trims documents with target_references,
# and the reference-closure scan reads "reference"/"target" keys.
assert not {"target_references", "reference", "target"} & set(
_nested_keys(document)
)

def test_donor_stage_reads_the_spm_unit_table_the_profile_stages(self) -> None:
from microcosm.frame.transport import _PROFILE_COLUMNS

stages = load_country_spec("nz").sources.stage_map()
(operation,) = stages["load_populace_us_support_pool"].operations
assert operation.kind == "read_tables"
assert operation.parameters["tables"] == ["person", "household", "spm_unit"]
# Placement ruling term 3: the stage declares every donor table the
# profile reader opens. CREATE sees only this file's digest
# (donor_pin_sha256), so nothing at run time checks the declaration.
assert set(_PROFILE_COLUMNS) <= set(operation.parameters["tables"])


class TestReportingClassifiers:
def test_reporting_resource_is_packaged_and_loader_visible(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,18 +676,21 @@ def test_nz_executable_support_keeps_region99_separate_from_ta999():
}


# D4 (d3058): CREATE's inventory on the pinned donor, as the transport store
# records it. prepare_create_outputs declares every non-structural column of
# the CREATE frame with its dtype (transport/cli.py), and
# prepare_transport_build passes all of them as create_outputs.
# D4 (d3058): CREATE's inventory on the pinned donor under NZ's donor profile,
# as the transport store records it. prepare_create_outputs declares every
# non-structural column of the CREATE frame with its dtype (transport/cli.py),
# and prepare_transport_build passes all of them as create_outputs.
_CREATE_INVENTORY = (
paths_for("microcosm-build").tests
/ "fixtures/nz/create_inventory_populace_us_48b9d479.json"
)
# The graph reads these, and CREATE on the pinned donor does not give them yet.
# d3058 rules 2, 4 and 5 stage them in the donor reader; that change must
# refresh the fixture from its CREATE probe and empty this mapping.
_AWAITING_DONOR_STAGING = {
# Columns the graph reads that CREATE on the pinned donor does not give. The
# donor profile (d3058 rules 2, 4 and 5) now stages household.tenure,
# person.enrolled_full_time and person.legal_marital_status, and the fixture
# holds them, so nothing awaits staging.
_AWAITING_DONOR_STAGING: dict[tuple[str, str], str] = {}
# The columns NZ's donor profile stages, with the dtypes the graph declares.
_PROFILE_STAGED = {
("household", "tenure"): "string",
("person", "enrolled_full_time"): "bool",
("person", "legal_marital_status"): "string",
Expand Down Expand Up @@ -769,8 +772,9 @@ def _nz_composition_spec_and_config():
bindings carry the engine pins, so the compiler checks the complete
packaged node and population structure with no synthetic node or pin. The
synthetic engine refs certify no runtime result. CREATE's outputs are the
inventory the pinned donor gave, plus the columns awaiting donor staging
at their concept dtypes. No bridge or region column enters as a root.
inventory the pinned donor gave under NZ's donor profile, plus any columns
awaiting donor staging at their concept dtypes (none now). No bridge or
region column enters as a root.
"""
from microcosm.graph import Owned

Expand Down Expand Up @@ -817,6 +821,23 @@ def test_the_staging_gap_declares_the_canonical_concept_dtypes():
}


def test_the_profiled_inventory_holds_the_staged_columns_at_canonical_dtypes():
"""D4: the donor profile fills the gap attempt 7 found, at graph dtypes."""
from microcosm.frame.transport import _PROFILE_CONCEPTS

# The shared reader's own list of the concepts a profile writes.
assert set(_PROFILE_STAGED) == {
(entity, column)
for entity, columns in _PROFILE_CONCEPTS.items()
for column in columns
}
canonical = _canonical_dtypes()
assert _PROFILE_STAGED == {key: canonical[key] for key in _PROFILE_STAGED}
real = _real_create_inventory()
assert {key: real.get(key) for key in _PROFILE_STAGED} == _PROFILE_STAGED
assert set(_PROFILE_STAGED) <= _nz_root_reads(_spec())


def test_every_real_create_column_is_a_canonical_concept_or_unit_output():
canonical = _canonical_dtypes()
_, unit = _structural_and_unit_columns(_spec())
Expand Down Expand Up @@ -865,41 +886,49 @@ def test_the_create_inventory_fixture_is_the_pinned_donors_stored_payload():
if row.get("structural") == "create"
)
assert create["kernel"] == provenance["create_kernel"]
# The fixture is CREATE under this donor profile; a new profile document
# must refresh it.
from microcosm.frame.transport import parse_donor_profile
from microcosm.graph.canonical import canonical_json

profile = parse_donor_profile(
canonical_json(spec["resources"]["donor_profile"]).decode("utf-8")
)
assert provenance["donor_profile"]["document_sha256"] == profile.sha256

def test_nz_refuses_the_real_inventory_alone_at_graph_compile():
"""Without the staged columns, NZ cannot compose on the pinned donor."""
import dataclasses

from microcosm.graph import GraphError
def test_nz_composes_against_the_real_profiled_inventory_alone():
"""D4: NZ composes on the pinned donor's profiled CREATE inventory alone.

spec, config = _nz_composition_spec_and_config()
real = dataclasses.replace(
config,
create_outputs=tuple(
owned
for owned in config.create_outputs
if (owned.entity, owned.column) not in _AWAITING_DONOR_STAGING
),
)
missing = "|".join(
re.escape(f"{entity}.{column}") for entity, column in _AWAITING_DONOR_STAGING
)
with pytest.raises(GraphError, match=rf"reads ({missing}), which no node owns"):
compose.compose_transport_graph(spec, real)
Attempt 7's unprofiled inventory lacked three columns the graph reads, so
composition refused. The profile stages them, so CREATE declares exactly
the stored inventory and owns the staged columns in the composed graph.
"""
assert not _AWAITING_DONOR_STAGING
_, config, graph, compiled = _nz_composed()
assert {
(owned.entity, owned.column): owned.dtype for owned in config.create_outputs
} == _real_create_inventory()
owned = {
(item.entity, item.column): item.dtype
for item in graph.node("nz.create").outputs
}
assert {key: owned.get(key) for key in _PROFILE_STAGED} == _PROFILE_STAGED
assert "nz.create" in compiled.order


def test_nz_checkpoints_keep_the_gate_report_before_export():
"""d3058: a run that export.prepare refuses still writes the gate closure.

Extension checkpoints write their manifests before export.prepare runs
(transport/cli.py). entitlement.py appends the cell diagnostics collector
after the declared entries.
Extension checkpoints write their manifests in declared order before
export.prepare runs (transport/cli.py). The document lists the cell
diagnostics collector before nz.gates.terminal, so its manifest is written
even if a node only the battery's checkpoint runs raises.
"""
assert compose.transport_endpoints(_spec())["checkpoints"] == (
"nz.as.bands",
"nz.gates.terminal",
"nz.as.bands.cell_diagnostics",
"nz.gates.terminal",
)


Expand Down Expand Up @@ -968,6 +997,33 @@ def test_nz_packaged_graph_compiles_with_only_pins_and_money_producers():
assert f"nz.v.{variant}.gap" in compiled.order


def test_nz_create_receives_the_donor_profile_as_canonical_text():
"""nz.create selects the whole profile document; CREATE's parser accepts it."""
from microcosm.frame.transport import parse_donor_profile

spec = _spec()
(row,) = (
row
for row in spec["resources"]["transport_graph"]["nodes"]
if row["id"] == "nz.create"
)
assert row["params"]["donor_profile"] == {
"resource": "donor_profile",
"path": [],
"encoding": "json",
}
# Placement ruling term 6: the node key hashes the document; no digest.
assert "donor_profile_sha256" not in row["params"]
_, _, graph, _ = _nz_composed()
create = graph.node("nz.create")
text = create.params["donor_profile"]
assert isinstance(text, str)
profile = parse_donor_profile(text)
assert profile.canonical_text == text
assert profile.donor_sha256 == create.params["donor_sha256"]
assert not list(compose._named_reference_values(json.loads(text)))


def test_every_composed_battery_keeps_the_d1982_release_candidate_off():
"""d1982: the batteries an extension branch adds keep the flag off too.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def test_nz_generation_zero_views_come_from_the_country_spec_seam() -> None:
"chronicle_feed.json",
"concept_mapping.json",
"currency_bridge.json",
"donor_profile.json",
"earnings_bands.json",
"entitlement_graph.json",
"export_contract.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"columns":[{"column":"age","dtype":"int64","entity":"person"},{"column":"sex","dtype":"string","entity":"person"},{"column":"employment_income","dtype":"float64","entity":"person"},{"column":"nonfarm_self_employment_income","dtype":"float64","entity":"person"},{"column":"farm_self_employment_income","dtype":"float64","entity":"person"},{"column":"interest_income","dtype":"float64","entity":"person"},{"column":"dividend_income","dtype":"float64","entity":"person"},{"column":"rental_income","dtype":"float64","entity":"person"},{"column":"realized_capital_gains","dtype":"float64","entity":"person"},{"column":"private_pension_income","dtype":"float64","entity":"person"},{"column":"usual_weekly_hours","dtype":"float64","entity":"person"},{"column":"has_disability","dtype":"bool","entity":"person"},{"column":"partner_person_id","dtype":"Int64","entity":"person"},{"column":"parent_1_person_id","dtype":"Int64","entity":"person"},{"column":"parent_2_person_id","dtype":"Int64","entity":"person"},{"column":"liquid_financial_assets","dtype":"float64","entity":"person"},{"column":"take_up_seed","dtype":"float64","entity":"person"},{"column":"reference_person_id","dtype":"Int64","entity":"household"},{"column":"rent","dtype":"float64","entity":"household"},{"column":"mortgage_interest","dtype":"float64","entity":"household"},{"column":"property_tax","dtype":"float64","entity":"household"},{"column":"source_household_id","dtype":"string","entity":"household"},{"column":"donor_support_stratum","dtype":"string","entity":"household"},{"column":"family_household_id","dtype":"int64","entity":"family"},{"column":"family_head_person_id","dtype":"int64","entity":"family"},{"column":"family_source_household_id","dtype":"string","entity":"family"}]}
{"columns":[{"column":"age","dtype":"int64","entity":"person"},{"column":"sex","dtype":"string","entity":"person"},{"column":"employment_income","dtype":"float64","entity":"person"},{"column":"nonfarm_self_employment_income","dtype":"float64","entity":"person"},{"column":"farm_self_employment_income","dtype":"float64","entity":"person"},{"column":"interest_income","dtype":"float64","entity":"person"},{"column":"dividend_income","dtype":"float64","entity":"person"},{"column":"rental_income","dtype":"float64","entity":"person"},{"column":"realized_capital_gains","dtype":"float64","entity":"person"},{"column":"private_pension_income","dtype":"float64","entity":"person"},{"column":"usual_weekly_hours","dtype":"float64","entity":"person"},{"column":"has_disability","dtype":"bool","entity":"person"},{"column":"partner_person_id","dtype":"Int64","entity":"person"},{"column":"parent_1_person_id","dtype":"Int64","entity":"person"},{"column":"parent_2_person_id","dtype":"Int64","entity":"person"},{"column":"liquid_financial_assets","dtype":"float64","entity":"person"},{"column":"legal_marital_status","dtype":"string","entity":"person"},{"column":"enrolled_full_time","dtype":"bool","entity":"person"},{"column":"take_up_seed","dtype":"float64","entity":"person"},{"column":"reference_person_id","dtype":"Int64","entity":"household"},{"column":"rent","dtype":"float64","entity":"household"},{"column":"mortgage_interest","dtype":"float64","entity":"household"},{"column":"property_tax","dtype":"float64","entity":"household"},{"column":"source_household_id","dtype":"string","entity":"household"},{"column":"tenure","dtype":"string","entity":"household"},{"column":"donor_support_stratum","dtype":"string","entity":"household"},{"column":"family_household_id","dtype":"int64","entity":"family"},{"column":"family_head_person_id","dtype":"int64","entity":"family"},{"column":"family_source_household_id","dtype":"string","entity":"family"}]}
Loading
Loading