Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ce86490
Start the US one-population contract library
MaxGhenis Nov 17, 2026
41046e1
Add staging's union-column form of the generated ACS tables
MaxGhenis Nov 17, 2026
7a363f8
Rewrite the one-population provenance and derive CPS unit ids
MaxGhenis Nov 17, 2026
b825f02
Test the household sort and the validator wrap in the provenance rewrite
MaxGhenis Nov 17, 2026
456c498
Add the one-population contract's refusals
MaxGhenis Nov 17, 2026
9c829ec
Add the one-population role record and absences file
MaxGhenis Nov 17, 2026
971bac0
List every kindless absence in one refusal
MaxGhenis Nov 17, 2026
9c24c5e
Add the one-population whole-frame reader differential
MaxGhenis Nov 18, 2026
77aa266
Keep a broken reader frame out of the expected failures
MaxGhenis Nov 18, 2026
9f0019e
Apply the lead's absence calls to the population contract
MaxGhenis Nov 18, 2026
1451e8f
Answer the implementation review on the population contract
MaxGhenis Nov 18, 2026
7d36dfc
Pin the stand-in's inputs to the installed engine's
MaxGhenis Nov 18, 2026
729f0d1
Record a declaration a receipt covers as needless
MaxGhenis Nov 18, 2026
b30abcd
Apply lead calls L1-L6 to the population contract
MaxGhenis Nov 18, 2026
c5186ef
Add the two clone-only verdict flips to the reader differential
MaxGhenis Nov 18, 2026
dc99e6b
Check that a clone defect's assembled gate fails for no other reason
MaxGhenis Nov 18, 2026
250fd6a
Merge main (bcb5cba9d) into the US one-population contract branch
MaxGhenis Nov 18, 2026
3f58101
Re-anchor the population contract's citations after merging main
MaxGhenis Nov 18, 2026
05aeb34
Answer the lead-call review on the population contract
MaxGhenis Nov 19, 2026
1cc4b14
Merge main (cfd5a2a5e) into the US one-population contract branch
MaxGhenis Nov 19, 2026
1161db1
Say why each moved input left the exempt list
MaxGhenis Nov 19, 2026
74ca478
Answer the independent review of the population contract
MaxGhenis Nov 20, 2026
26c519f
Answer the second independent review of the population contract
MaxGhenis Nov 20, 2026
8f21661
Answer the third review of the population contract
MaxGhenis Nov 21, 2026
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/us-one-population-contract.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `us_runtime/one_population_contract.py`, the population contract library for d2283's national one-population file. `to_assembled_provenance` rewrites the parent export's CPS rows (Route A's `asec` and `puf_tax_detail` labels kept, spine source id = source id, spine tag `asec_puf`) and staging's ACS rows (`acs_2024_1yr`, spine source id = staging's native id) into the assembled form with a clone-0, three-channel spine assembly record, taking each origin's household weights keyed (CPS by household id, ACS by the selection's unit key) and refusing weights given by position or held as complex or temporal values, incomplete support metadata, an id, clone index, lineage number or person-to-group link held as anything but integers, real numbers or strings (such as a complex value, a time or an Arrow dictionary of times), colliding ids, a repeated (source id, rank) pair, lost `SERIALNO`/`SPORDER` lineage (it compares each ACS person's pair with staging's lineage, keyed on native household and person ids), a group unit spanning two households, and an ACS household with more than one SPM unit. `require_one_population` refuses a joined frame that breaks any clause, each with its own message: provenance (including a spine assembly record count that is not a nonnegative integer), one native row per CPS key and one row per ACS household against the selection manifest (`one_population_selection`), location clones, a missing congressional district, `TYPEHUGQ` on ACS households, columns the engine computes at 2024, unregistered lower-case columns, a null ESI premium, an SPM unit without a classified adult, a null engine input outside the release-written list, or a null inside it other than None or a float NaN (`pd.NA`, `pd.NaT` and numpy's `NaT` refuse), null PUF tail columns, a tail donor set unlike the parent's, applied twice or applied on an ACS tax unit, and an undeclared register column ACS rows lack while CPS rows hold it. `combined_spm_role_record` builds the SPM role record from a CPS record and staging's ACS receipt, checked against a recount of the frame and, on ACS rows, against the role each person's `RELSHIPP` gives (a code held as anything but an integer, real number or string refuses); `absences` and `write_absences` list what each origin lacks, by support channel, as owner-declared, release-written, raw source column, reviewed default fill, zero written or origin-native (the six ACS-native `acs_*` amounts CPS rows lack); they record declarations a frame does not use instead of refusing them, and refuse a fill receipt that gives a spine a negative row count. `cps_unit_ids` derives the CPS selection keys, and `one_population_selection`'s key digest is now public as `keys_sha256`. The engine's variable classes come from an injected index, built from the installed engine only at call time. No build calls it yet.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"acs_unit_key",
"cps_unit_key",
"group_quarters",
"keys_sha256",
"plan_selection",
"spm_zero_adult",
"starting_weights",
Expand Down Expand Up @@ -216,8 +217,13 @@ def _refuse_duplicates(keys: Sequence[str], *, side: str) -> None:
)


def _keys_sha256(keys: Iterable[str]) -> str:
"""sha256 of the sorted keys joined by newline (keys hold no newline)."""
def keys_sha256(keys: Iterable[str]) -> str:
"""sha256 of the sorted keys joined by newline (keys hold no newline).

The digest :class:`SelectionManifest` records for each selected key set.
It is public so a later check over a frame's keys (the population
contract) digests them by the same rule.
"""
return hashlib.sha256("\n".join(sorted(keys)).encode("utf-8")).hexdigest()


Expand Down Expand Up @@ -940,8 +946,8 @@ def from_plan(
n_acs=plan.n_acs,
n_cps_by_income_year=plan.n_cps_by_income_year,
threshold_draw=plan.threshold_draw,
selected_acs_keys_sha256=_keys_sha256(plan.acs_keys),
cps_keys_sha256=_keys_sha256(plan.cps_keys),
selected_acs_keys_sha256=keys_sha256(plan.acs_keys),
cps_keys_sha256=keys_sha256(plan.cps_keys),
input_digests=_check_digests(input_digests),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""The population contract's stand-in index answers as the installed engine's.

The contract's engine-free tests inject ``StandInVariableIndex.from_lock()``
in place of the default :class:`PolicyEngineUSVariableIndex`, which reads the
installed policyengine-us sources. These tests pin the stand-in to that
default: over every name the stand-in classifies, the two give the same
known, computed-at-2024 and input-at-2024 answers, so a passing engine-free
clause test means what it would mean with the engine's metadata behind it.
"""

from __future__ import annotations

import pandas as pd

from microcosm.build.us_runtime.multispine_pool import (
POOL_ENGINE_INPUT_PROJECTION_CONTRACT,
)
from microcosm.build.us_runtime.one_population_contract import (
STRUCTURAL_COLUMNS,
PolicyEngineUSVariableIndex,
)
from microcosm.frame.adapters.policyengine_us import (
PolicyEngineUSVariableMetadataIndex,
)
from test_support.microcosm_build.us_one_population_contract import (
SPM_ROLE,
STAND_IN_COMPAT_AGGREGATES,
STAND_IN_COMPUTED_AT_2024,
STAND_IN_FORMULA_AFTER_2024,
STAND_IN_STRUCTURAL_FORMULAS,
StandInVariableIndex,
lock_engine_inputs,
)


def test_the_lock_inputs_are_the_installed_engine_inputs() -> None:
# The stand-in's inputs are the lock's 926 names; the installed index's
# year-blind input list must be the same names.
installed = frozenset(PolicyEngineUSVariableMetadataIndex().variables())
assert installed == frozenset(lock_engine_inputs())
assert len(installed) == POOL_ENGINE_INPUT_PROJECTION_CONTRACT.input_count


def _every_classified_name() -> dict[str, pd.DataFrame]:
names = sorted(
frozenset(lock_engine_inputs())
| STAND_IN_COMPUTED_AT_2024
| STAND_IN_COMPAT_AGGREGATES
| STAND_IN_FORMULA_AFTER_2024
| STAND_IN_STRUCTURAL_FORMULAS
| STRUCTURAL_COLUMNS
)
return {"person": pd.DataFrame(columns=names)}


def test_the_stand_in_answers_as_the_default_index() -> None:
tables = _every_classified_name()
names = list(tables["person"].columns)
default = PolicyEngineUSVariableIndex()
stand_in = StandInVariableIndex.from_lock()

assert default.known_variables(names) == stand_in.known_variables(names)
assert default.computed_at_2024(tables) == stand_in.computed_at_2024(tables)
assert default.inputs_at_2024(tables) == stand_in.inputs_at_2024(tables)


def test_a_post_2024_formula_and_the_role_are_inputs_at_2024() -> None:
# weeks_worked has only formula_2025 at the locked policyengine-us, and
# the SPM role is a declared dataset source input despite its fallback
# formula: the contract reads both as inputs at 2024.
tables = {"person": pd.DataFrame(columns=["weeks_worked", SPM_ROLE])}
inputs = PolicyEngineUSVariableIndex().inputs_at_2024(tables)
assert inputs == {"weeks_worked", SPM_ROLE}
Loading
Loading