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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `microcosm.calibrate.solve.solve_constraint_system`, the Adam solve `calibrate` runs, for a caller that already holds a compiled constraint system (a SciPy matrix or its own operator), with the same mass, ratio-cap and L2 options and the same checks; the US support-mix bake-off now calls it instead of the private `_optimize` (microcosm#1585 item 8.3).
1 change: 1 addition & 0 deletions changelog.d/1585-cd-surface-ess-validation.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ACS local-area Kish ESS (`tools/us_acs_local_cd_surface.py`'s `kish_ess`, which the district and county surfaces and the release's weight-origin summaries of the design and calibrated weights read) is now `microcosm.calibrate.solve.effective_sample_size`, so it refuses negative, NaN or infinite weights instead of scoring them, and every valid weight vector, an empty one included, scores as before (microcosm#1585).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The US seed protocol's direct-draw kernel now attests `microcosm.build.stochastic_assignment`, whose `stable_identity_uniforms` computes the US keyed draws, so an edit to that module moves the US seed-protocol and seed-map digests (microcosm#1585).
1 change: 1 addition & 0 deletions changelog.d/1585-tanf-seed-ledger-salt.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The US seed protocol's ledger now records the TANF take-up draw's salt as `takes_up_tanf_if_eligible`, the program variable the draw has always been salted with, instead of `takes_up_tanf`; no draw changes, and the US seed-protocol digests move (microcosm#1585).
1 change: 1 addition & 0 deletions changelog.d/1585-us-keyed-draws-shared-helper.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The eleven US seeded draw loops (generic, SNAP and SSI take-up, the SNAP discretionary exemption, WIC, pregnancy, immigration, the ACA-family source operations, and the ACS local-area SSI disability, Medicaid keep and Head Start draws) now call `microcosm.build.stochastic_assignment.stable_identity_uniforms` instead of carrying copies of its BLAKE2b loop, and every draw is unchanged (microcosm#1585 item 4).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The US release tool now reads its population-aggregate list, SOI signed-component rule and known-period walker from `microcosm.data.compatibility_recertification`, which the recertification tool also reads (the walker through explicit `walk_branches` and `skip_unknown` options), and `support_mix` takes its hash draw from `microcosm.build.holdout` and its Kish ESS from `microcosm.calibrate.solve`, all with unchanged results (microcosm#1585 item 5).
34 changes: 17 additions & 17 deletions docs/evidence/spec-engine/us-f0-coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@
"legacy_sinks": [],
"mode": "compiler_semantic",
"pointer_class": "all",
"pointer_count": 827,
"pointer_sha256": "525ed8621baa2c6e0c0970a6cec85b3b250f8aadfe93750a08deb0d9f240f15e",
"pointer_count": 828,
"pointer_sha256": "c358fa57ee3bf91f3b25df541cd6e4cf833e49f976a3d57b37006b7f5960b2fc",
"rationale": null,
"relative_sink_prefix": null,
"source_prefix": "/resolved/seed_protocol",
Expand Down Expand Up @@ -758,21 +758,21 @@
"verifier": "vintages"
}
],
"configuration_field_count": 42394,
"consumed_field_count": 42394,
"configuration_field_count": 42395,
"consumed_field_count": 42395,
"generation0_effect_counts": {
"legacy_behavior": 38780,
"no_generation0_effect": 3614
"no_generation0_effect": 3615
},
"mode_counts": {
"compiler_semantic": 27673,
"compiler_semantic": 27674,
"front_end_validation": 349,
"identity_only": 103,
"legacy_behavior": 14269
},
"multiple_primary_use_field_count": 0,
"pointer_inventory_sha256": "f6832e8d2892af22e41afd0b0bea0cba354bbff8b84bebcc652e765a3ae7df92",
"resolved_binding_field_count": 9785,
"pointer_inventory_sha256": "81bc649e653b467b0da8fa7442a895fe45f24a263c725d764ca9ed8f4441325c",
"resolved_binding_field_count": 9786,
"unused_field_count": 0
},
"inventory_coverage": {
Expand Down Expand Up @@ -1642,13 +1642,13 @@
"compiler_ir.node_slices"
],
"expected": {
"map_sha256": "0c19b903a43b997886be6222045485954c96d6a624ce2ae3f83cadb4b22a7883",
"protocol_sha256": "15e6cad1f1b0082ffd5980095b4060827ed18786fae3076c97cf431c93a50e16"
"map_sha256": "270cf6498f8a2977993f969d0703be88fb930499dab42741a2111f57ffec4266",
"protocol_sha256": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47"
},
"failures": [],
"observed": {
"map_sha256": "0c19b903a43b997886be6222045485954c96d6a624ce2ae3f83cadb4b22a7883",
"protocol_sha256": "15e6cad1f1b0082ffd5980095b4060827ed18786fae3076c97cf431c93a50e16"
"map_sha256": "270cf6498f8a2977993f969d0703be88fb930499dab42741a2111f57ffec4266",
"protocol_sha256": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47"
},
"status": "covered"
},
Expand All @@ -1663,7 +1663,7 @@
"compiler_ir.seed_stream_map"
],
"expected": {
"implementation_sha256": "15e6cad1f1b0082ffd5980095b4060827ed18786fae3076c97cf431c93a50e16",
"implementation_sha256": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47",
"protocol": "legacy-v1",
"streams": [
"build_model",
Expand All @@ -1684,7 +1684,7 @@
},
"failures": [],
"observed": {
"implementation_sha256": "15e6cad1f1b0082ffd5980095b4060827ed18786fae3076c97cf431c93a50e16",
"implementation_sha256": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47",
"protocol": "legacy-v1",
"streams": [
"build_model",
Expand Down Expand Up @@ -1722,7 +1722,7 @@
},
"failures": [],
"observed": {
"sha256": "a0366cd518f42a240b589af3ef6580aac44ad7ed70969bcc669b365d315146ab",
"sha256": "67302e3a53429c0a31195f23c594570885c47052cf7e907664d61b96278a61eb",
"sites": 53
},
"status": "covered"
Expand Down Expand Up @@ -2585,7 +2585,7 @@
"country": "us",
"schema_id": "country_spec",
"schema_version": 1,
"spec_sha256": "98d583653d37fe58edcace1cf3e21a139b69ebe7d1c3dac6a58f08b2b5aab8cf"
"spec_sha256": "bd526d8cf819e9f97fa46c5fe279c7b9ef4458b3e2d3498f823602f45e6a7575"
}
},
"report_schema_version": 3,
Expand All @@ -2595,7 +2595,7 @@
"country": "us",
"schema_id": "country_spec",
"schema_version": 1,
"spec_sha256": "98d583653d37fe58edcace1cf3e21a139b69ebe7d1c3dac6a58f08b2b5aab8cf"
"spec_sha256": "bd526d8cf819e9f97fa46c5fe279c7b9ef4458b3e2d3498f823602f45e6a7575"
},
"status": "pass"
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from .schemas import load_schema_registry

EXPECTED_AUTHORED_FIELD_COUNT = 32609
EXPECTED_RESOLVED_BINDING_FIELD_COUNT = 9_785
EXPECTED_CONFIGURATION_FIELD_COUNT = 42394
EXPECTED_RESOLVED_BINDING_FIELD_COUNT = 9786
EXPECTED_CONFIGURATION_FIELD_COUNT = 42395


class FieldUsageError(AssertionError):
Expand Down Expand Up @@ -449,8 +449,8 @@ def _path_inventory(rows: Sequence[tuple[str, object]]) -> tuple[int, str]:
"6a781915fd491d2c4b16d2b7d482f69cf362c904130093c59f9629f7a319269b",
),
"resolved_seed_protocol": (
827,
"525ed8621baa2c6e0c0970a6cec85b3b250f8aadfe93750a08deb0d9f240f15e",
828,
"c358fa57ee3bf91f3b25df541cd6e4cf833e49f976a3d57b37006b7f5960b2fc",
),
"resolved_seed_site_bindings": (
277,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,15 @@
# S-corp line-32 shares as separate leaves.
# The hierarchy value ranks move both again: medicaid_take_up, an
# attested kernel module, gives a substituted enrollment spec's value no
# rank. No draw, RNG rule or QRF target changes.
"seed_map": "0c19b903a43b997886be6222045485954c96d6a624ce2ae3f83cadb4b22a7883",
"seed_protocol": "15e6cad1f1b0082ffd5980095b4060827ed18786fae3076c97cf431c93a50e16",
# rank. No draw, RNG rule or QRF target changes. microcosm#1585 moves both
# again: the US keyed draws call stochastic_assignment's
# stable_identity_uniforms, and that module joins the attested kernel
# modules; no draw changes. #1585's public solve_constraint_system and
# calibrate's shared option checks move both again; no US solve changes.
# Its TANF ledger fix moves the protocol again: the site's recorded salt
# becomes the takes_up_tanf_if_eligible its draw always used.
"seed_map": "270cf6498f8a2977993f969d0703be88fb930499dab42741a2111f57ffec4266",
"seed_protocol": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47",
"source_manifest": "dc3879886d2a69f20fb982a675d7fb322c0e4017afef6471be54b0ee3cbd2af6",
"take_up": "9522ce40f7dea569312dd7a7beb474e5a5afadd2f1e10cb5876534c3ef623d35",
"tail": "565f0ceeadab69d3e96a886a00dd0305f7425fa3acde24d12ba48db2b37d5fc0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def _site(
_DIRECT_KERNEL_MODULES = (
"microcosm.build.frame_sampling",
"microcosm.build.source_runtime",
"microcosm.build.stochastic_assignment",
"microcosm.build.us_runtime.acs_transfer",
"microcosm.build.us_runtime.adult_care",
"microcosm.build.us_runtime.child_support",
Expand Down Expand Up @@ -783,7 +784,7 @@ def _stable_site(
),
_stable_site(
"tanf_take_up_assignment",
salt="takes_up_tanf",
salt="takes_up_tanf_if_eligible",
key_grammar=(
"complete_source_identity_overrides_support_source_id",
"support_source_id_overrides_entity_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import pandas as pd

from microcosm.build.gates import GateResult
from microcosm.build.stochastic_assignment import stable_identity_uniforms
from microcosm.build.us_runtime.acs_inputs import _nullable_source_codes
from microcosm.build.us_runtime.acs_pums import ACS_2024_1YR_SPINE
from microcosm.build.us_runtime.acs_release_predictors import (
Expand Down Expand Up @@ -388,22 +389,7 @@ def _acs_draw_keys(household: pd.DataFrame, rows: pd.DataFrame) -> pd.Series:
def _keyed_uniforms(keys: Sequence[str], *, seed: int, stream: str) -> np.ndarray:
"""Seeded blake2b uniforms in ``[0, 1)``, one per key."""

denominator = float(2**64)
return np.asarray(
[
int.from_bytes(
hashlib.blake2b(
f"{seed}:{_DRAW_SALT}:{stream}:{key}".encode(),
digest_size=8,
).digest(),
byteorder="big",
signed=False,
)
/ denominator
for key in keys
],
dtype=np.float64,
)
return stable_identity_uniforms(keys, seed=seed, salt=f"{_DRAW_SALT}:{stream}")


def _assignment_sha256(person_ids: np.ndarray, values: np.ndarray) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@

from microcosm.build.gates import GateResult
from microcosm.build.source_runtime import SourceRuntimeConfig, run_source_stage
from microcosm.build.stochastic_assignment import stable_identity_uniforms
from microcosm.build.us_runtime.acs_pums import ACS_2024_1YR_SPINE
from microcosm.build.us_runtime.acs_transfer import ASEC_PUF_DONOR_SPINE
from microcosm.build.us_runtime.base_pool import spine_column
Expand Down Expand Up @@ -359,12 +360,7 @@ def _group_sums(
def _keyed_uniform(key: str, *, seed: int, stream: str) -> float:
"""A seeded blake2b uniform on ``stream`` for one ACS draw key."""

value = int.from_bytes(
hashlib.blake2b(f"{seed}:{stream}:{key}".encode(), digest_size=8).digest(),
byteorder="big",
signed=False,
)
return value / float(2**64)
return float(stable_identity_uniforms((key,), seed=seed, salt=stream)[0])


def _donor_contribution(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@

from __future__ import annotations

import hashlib
from collections.abc import Callable, Sequence

import numpy as np
import pandas as pd

from microcosm.build.stochastic_assignment import stable_identity_uniforms
from microcosm.build.us_runtime.acs_pums import ACS_2024_1YR_SPINE
from microcosm.build.us_runtime.sipp_head_start import (
_ELIGIBLE_MAX_AGE,
Expand Down Expand Up @@ -137,22 +137,7 @@ def _head_start_ages(age: np.ndarray) -> np.ndarray:

def _keyed_uniforms(keys: Sequence[str], *, seed: int) -> np.ndarray:
"""Seeded blake2b uniforms in ``[0, 1)``, one per key."""
denominator = float(2**64)
return np.fromiter(
(
int.from_bytes(
hashlib.blake2b(
f"{seed}:{_HEAD_START_DRAW_SALT}:{key}".encode(), digest_size=8
).digest(),
byteorder="big",
signed=False,
)
/ denominator
for key in keys
),
dtype=np.float64,
count=len(keys),
)
return stable_identity_uniforms(keys, seed=seed, salt=_HEAD_START_DRAW_SALT)


def vehicles_available_summary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@

from __future__ import annotations

import hashlib
from collections.abc import Mapping
from dataclasses import dataclass
from importlib.resources import files
Expand All @@ -85,6 +84,7 @@
SourceRuntimeError,
run_source_stage,
)
from microcosm.build.stochastic_assignment import stable_identity_uniforms
from microcosm.frame import Frame
from microcosm.frame.units import US_SCHEMA

Expand Down Expand Up @@ -483,23 +483,7 @@ def _stable_person_draws(
)
else:
keys = person["person_id"].astype(str)
denominator = float(2**64)
return np.fromiter(
(
int.from_bytes(
hashlib.blake2b(
f"{seed}:{salt}:{key}".encode(),
digest_size=8,
).digest(),
byteorder="big",
signed=False,
)
/ denominator
for key in keys
),
dtype=np.float64,
count=len(keys),
)
return stable_identity_uniforms(keys, seed=seed, salt=salt)


def _select_weight_to_target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

from __future__ import annotations

import hashlib
from importlib.resources import files

import numpy as np
Expand All @@ -51,6 +50,7 @@
SourceRuntimeError,
run_source_stage,
)
from microcosm.build.stochastic_assignment import stable_identity_uniforms
from microcosm.frame import Frame
from microcosm.frame.units import US_SCHEMA

Expand Down Expand Up @@ -146,22 +146,7 @@ def _stable_person_draws(persons: pd.DataFrame, *, seed: int) -> np.ndarray:
)
else:
keys = persons["person_id"].astype(str)
denominator = float(2**64)
return np.asarray(
[
int.from_bytes(
hashlib.blake2b(
f"{seed}:pregnancy:{key}".encode(),
digest_size=8,
).digest(),
byteorder="big",
signed=False,
)
/ denominator
for key in keys
],
dtype=np.float64,
)
return stable_identity_uniforms(keys, seed=seed, salt="pregnancy")


def _pregnancy_eligibility(person: pd.DataFrame) -> tuple[np.ndarray, np.ndarray]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

from __future__ import annotations

import hashlib
from importlib.resources import files

import numpy as np
Expand All @@ -56,6 +55,7 @@
SourceRuntimeError,
run_source_stage,
)
from microcosm.build.stochastic_assignment import stable_identity_uniforms
from microcosm.frame import Frame
from microcosm.frame.units import US_SCHEMA

Expand Down Expand Up @@ -150,21 +150,8 @@ def _stable_person_draws(persons: pd.DataFrame, *, seed: int) -> np.ndarray:
)
else:
keys = persons["person_id"].astype(str)
denominator = float(2**64)
return np.asarray(
[
int.from_bytes(
hashlib.blake2b(
f"{seed}:snap_abawd_discretionary_exemption:{key}".encode(),
digest_size=8,
).digest(),
byteorder="big",
signed=False,
)
/ denominator
for key in keys
],
dtype=np.float64,
return stable_identity_uniforms(
keys, seed=seed, salt="snap_abawd_discretionary_exemption"
)


Expand Down
Loading
Loading