Repository navigation
Rebuild a subsampled simulation from its inputs, not its calculated values - #573
Merged
Merged
Conversation
subsample exported every stored value, calculated ones included, and loaded them all back as inputs. A formula result calculated before subsampling then replaced its formula for good: it was carried over past the formula's end and survived apply_reform and later set_input calls, so results after subsampling depended on what had been calculated before. It now exports the values the simulation was given (loaded from the dataset or passed to set_input), for variables with a formula too, so formula-backed structural IDs from the dataset are still kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 2, 2026
Draft
Contributor
Author
|
#601 supersedes this PR. It keeps the same rule (keep inputs, including those of formula-backed variables, and drop calculated values), with three differences:
#601 carries this PR's tests unchanged, and they pass there. Run against this branch merged locally onto current master, #601's tests fail in three cases: a value calculated where an input was deleted, and a formula-backed |
Preserve current storage provenance and baseline binding while retaining the original inputs-only export. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preserve the baseline policy while recreating calculation branches on the sampled population. Extend the existing differential property to formulas that create branches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep restored input provenance in the input export registry while excluding values listed in derived_periods.txt. Add a differential restore and subsample regression without relying on PR #560. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Calculate sampling probabilities from the requested period independently of the input export. Keep existing input-column normalization and recompute derived weights on the sample. Add focused differential and property coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the flat-file loader\x27s recorded membership labels when an input-only household ID is absent. Keep calculated default IDs out of the rebuilt dataset and verify complete household partitions with shuffled, nonconsecutive labels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Extend differential sampling examples and properties to monthly requests. Verify annual FLOW weights divide by twelve while normalized probabilities, source inputs and the default calculation period stay consistent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis
marked this pull request as ready for review
October 9, 2026 15:56
Contributor
Author
|
US + core hub merge audit, core#573 at
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Subsampling rebuilds from surviving source inputs recorded by the holder, including explicit overrides of formula-backed variables. Calculated values stay calculated; deleted or cache-replaced inputs cannot become source inputs again. Loaded IDs, memberships and roles provide any missing structural leaves, and pre-sample calculation branches are recreated against the retained populations.
Merged
masterata934dc3465cd3284b6d21fb6fd7a0506b3e6581bwith merge commita19b8eaffab026ce18cfea81b00e60bb572d12e0, incorporating #558, #561, #571 and #581. The subsequent normalization fix isd5e775675dd9fe5c3cc1fd268bfae07d4b5d7605. The dump/restore conflict uses master's_restore_inputimplementation, so restored values enter #561's per-tier input record through the holder lifecycle. Dataframe export, dictionary export and subsample rebuilds share that record and read surviving inputs from their recorded tiers. An unrecorded memory cache cannot replace a recorded disk source input during export. The existing structural-only default public export andinclude_computed_variables=Truebehavior are retained.d1026 Proposal A: each recorded weight column preserves its own entity's source total. Normalization groups by the exported membership column that the rebuild reads, addressing review r2 P3-1 when membership is overridden after dataset load. Source totals also come from recorded input tiers. Zero-total inputs stay zero; an unquantized sample retaining only zero weights for a positive source total raises before replacing the dataset.
Requested-period sampling weights still use available inputs, formulas, uprating or carry-over, falling back to recorded dataset-period weights when no requested-period source exists. Missing both sources raises a clear error. Legacy dumps without provenance may still restore calculated values as inputs.
Authorization and hub gates
Max gave go under d1118 on 2026-10-09, subject to the hub gates. The hub's current-head US and UK microsimulations, marginal-tax-rate check and partner-output check are in "Hub validation" below. Existing #570/#572 holds and d1024's fresh-parameter-lookup contract remain in force.
Master contains the earlier d899 sequence, including #561, #571 and #581, with #558 alongside. #601 still overlaps structural rebuilding; #560 composition must retain master's restored-input record and provenance lifecycle. Historical composition results do not validate the updated head.
Master merge (2026-10-10): Merge commit
372b328638fcc35f6f65ca607e44717534ce02fdincludes current master (78a6c503ca6623f2735410412b8ca9e93816ec0d) and #560 (b5beeda37c9e79b50b0310ec0944f00a831cd71b), with no conflicts or additional code changes. Combination validation at this merge: 430 passed across 24 files — 151 in all 12 subsample files,test_dump_restore.pyand the selected subsample case oftest_clone_reform_baseline.py, plus 279 in all 10 #560 test files; its supporting fixture module collected no tests. Each file ran separately in the foreground withuv run pytest -qunder Python 3.13.9, with Hypothesis integration enabled. Source review found no composition defect: export and invalidation share surviving per-tier input provenance, deleted overrides stay excluded, subsampling resets store history and recreates branches on the sample, and restore loads inputs before calculated arrays. Formatting, lint andgit diff --checkpass. The hub's microsimulations and downstream checks are below.Validation
Focused validation: 278 passed across 19 files — 172 subsample, dump/restore and clone/baseline checks, plus 106 checks across all five requested #561 input-record files. These include all ten added regression cases and property tests configured for up to 150 input-rebuild examples, 35 sampling differential examples and 200 memory/disk provenance sequences.
The required single
tests/corerun completed with 2,298 passed, 1 skipped, 3 xfailed and 457 warnings, exit code 0. Ruff formatting and lint checks andgit diff --checkpass for the final PR diff. All thirteen changed Python files parse successfully.Focused tests ran one file at a time in the foreground with
uv run pytest -q -p no:cacheprovider, using Python 3.13 development dependencies, checkout-pinned core imports and explicit Hypothesis pytest integration. The broad command wasuv run pytest -q -p no:cacheprovider tests/core, run once after the focused files. Unrelated pytest and Hypothesis plugin discovery was disabled; property tests remained enabled. An initial deleted-input invocation with startup diagnostics exited 139 before reporting any cases. The rerun without diagnostic dumps passed all 21 cases, and the subsequent broad suite passed.Documentation review
The public export and subsample docstrings describe recorded input tiers, sampling fallback, structural leaves, native entity totals and branch recreation; the existing API autodoc exposes them. The existing single towncrier fragment covers the behavior change. No generated documentation was edited. A documentation build is outside this validation run because the generator and templates are unchanged. Impact: medium. Confidence rests on the hub validation below.
Remaining review notes
Review r2 P3-2 (datasets without
time_period) and P3-3 (parameter-based abolition in sampling-weight source selection) are unchanged and outside this merge reconciliation. The hub's validation of that change's downstream effects is below.Hub validation (2026-10-10, at this head
372b328638)All runs use the default PolicyEngine-US dataset on PE-US main
75cdd8019e, one at a time under the machine's heavy-job lock.Full-sample control (no subsample), 2026. Core master
78a6c503caagainst this head:household_net_income,income_tax,state_income_taxandhousehold_weightare identical in every record.Marginal tax rates, 2026. Core
a934dc3465(master before #560) against this head, which contains #560 and this PR:marginal_tax_rateandhousehold_net_incomeare identical in every record. Wall time was 543 s against 566 s.Subsample A/B, 2026, n = 10,000 households, three seeds. Core master
78a6c503caagainst this head. Ratios are the subsample total over the full-sample total.*
family_weightis zero on both sides (no data and no formula) and is excluded.household_weight. In PolicyEngine-US,person_weight,tax_unit_weight,spm_unit_weightandmarital_unit_weightare formulas that copy the household's weight.Partner contract tests. The PolicyEngine-US partner files (
policyengine_us/tests/policy/baseline/partners, 145 files) pass with this head: 623 passed, 0 failed.PolicyEngine-UK. PE-UK 2.122.2 with a cached
populace_uk_2023.h5(a July 2026 build, not the current production file), 2026:Simulation.subsample()raises the sameTypeErrorunder master and under this head, because core callsbuild_from_dataset()with no arguments and PE-UK's override requires a dataset (Simulation.subsample() raises TypeError: build_from_dataset() needs a dataset policyengine-uk#2254). So this PR changes nothing for PE-UK. PE-UK 2.125.1 was not run.