Repository navigation
Conversation
subsample rebuilds the simulation from a person-level frame of recorded inputs plus the structural leaves retain_structure adds. retain_structure skipped any leaf the tax-benefit system had no variable for, so a system without person_<entity>_role rebuilt every member with the default role (silently on master; as a capacity error once #595 lands), and a system without person_id or person_<entity>_id variables failed to subsample. retain_structure now carries person IDs, memberships and role keys whether or not a variable backs them. An integer role variable cannot hold "no role", so subsample raises before changing anything instead of writing role index 0. The loader records the columns it reads for structure and no longer reports them as ignored. Found in review P3-1 on #595. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For any households of bounded, unbounded and unmatched role keys, person order, weights, default role, role source and sample, every kept household is a whole source household whose role counts (by key and nb_persons) equal the source's, with or without a role variable, through a second subsample too, and no structural column is reported as ignored. An integer role variable keeps the roles or raises before changing anything. Move the household-table oracle into the shared fixture module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clarify structural input precedence during subsampling and cover loaded role keys across dataset formats. Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
|
Agent review for Max, written by Codex and posted by Antigravity for Max Ghenis (exact reviewed head VERDICT: REQUEST_CHANGES Subsampling makes simulations with string household IDs fail to restore from a dump, and the revised role-preservation claim still fails for unbacked integer roles. Merge base with fetched master was Findings
Earlier findings and description checks
The original-load parent and child counts were The annual example uses unchanged synthetic template values. January income is Verification
|
Problem
Simulation.subsample()rebuilds the simulation from a person-level frame. Before this change, the frame could omit structural fields that had no backing variable. The loader uses those fields to identify people, group them into households, and assign roles. Missing role columns could cause the reload to assign the default role to every member, or raise when the default was absent or at capacity. Missing ID columns could also make the rebuild fail.policyengine_core/simulations/simulation.py:1119,:3688.The case was found during review of PolicyEngine/policyengine-core#595.
Before and after
The country template example removes
person_household_role, setsdefault_role = "first_parent", and loads memberships[0, 0, 0, 1]and roles[first_parent, child, child, first_parent]. It then runssubsample(n=2, seed=0).tests/core/test_subsample_explicit_roles.py:57.| Stage | First parents per household | Children per household |
|---|---|
| Original load |
[1, 1]|[2, 0]|| Historical subsample on
1cccc278e|[3, 1]|[0, 0]|| Historical subsample with #595 applied | Capacity
ValueError| Rebuild interrupted || Subsample with this PR |
[1, 1]|[2, 0]|With no backing ID variables, the array tests load people
[100, 101, 102]with memberships[10, 10, 20]. Both samples and a fresh load of the sampled flat file retain those labels.tests/core/test_subsample_explicit_roles.py:397.Changes
__eternitysuffix. The sampled flat file uses its membership labels as group IDs.policyengine_core/simulations/simulation.py:3688,:1216,:3870.""as a role.policyengine_core/simulations/simulation.py:3752.policyengine_core/simulations/simulation.py:3725.policyengine_core/simulations/simulation.py:1161,:1284,tests/core/test_subsample_explicit_roles.py:329,:341.Invariants
Recorded structural inputs take precedence over the loaded values and can change the roles or household partition that the sample uses. For flat files, the loader takes the first matching column in dataset order. Subsampling exports recorded periods in sorted order, so the reload can select a different period. For example, a source with its 2025 role column before its 2024 column loads the 2025 roles and can rebuild with the 2024 roles.
policyengine_core/simulations/simulation.py:1124,:3458,:3651,tests/core/test_subsample_explicit_roles.py:253,:264.policyengine_core/simulations/simulation.py:3725,:3752.policyengine_core/simulations/simulation.py:3708,:3810.nb_persons(role)returns the same counts. The integer regression checks this with twoadultslots.tests/core/test_subsample_explicit_roles.py:205.tests/core/test_subsample_explicit_roles.py:96.tests/core/test_subsample_explicit_roles.py:116,:397.ValueErrorbefore replacing the dataset or populations.policyengine_core/simulations/simulation.py:3737,tests/core/test_subsample_explicit_roles.py:153.tests/core/test_subsample_explicit_roles.py:304,:316,:379.Tests
Ran with Python 3.13.5 in an editable install.
timeout 900 python -m pytest -q -p no:cacheprovider <file>for each of 29 focused filestimeout 900 make test-country-templatetimeout 1500 python -m pytest -q -p no:cacheprovider testsAll commands in the table exited 0. The focused runs included all subsample modules, default roles, dataset warnings, the simulation builder, role projectors, dump and restore, and the YAML runners. The explicit-role module now has 41 example cases. The two Hypothesis properties run with 200 and 100 generated examples, plus their explicit examples.
tests/core/test_subsample_explicit_roles.py,tests/core/test_subsample_explicit_roles_property.py:81,:143.ruff format --checkandruff checkpassed on the changed Python files and the PR’s shared role fixture.towncrier check --compare-with origin/masterfound the.fixed.mdfragment. The branch already contains the pinned master tip, and both explicit-role modules passed on the merge-check branch.The PE-US Core gate and full-sample controls require real-data runs and remain with the maintainer.
axiom: n/a (Core engine infrastructure).
🤖 Generated with Claude Code