Skip to content

Add RegionGroupStrategy for union-of-regions scoping#477

Merged
anth-volk merged 5 commits into
mainfrom
feat/region-group-strategy
Jul 20, 2026
Merged

Add RegionGroupStrategy for union-of-regions scoping#477
anth-volk merged 5 commits into
mainfrom
feat/region-group-strategy

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #476

Summary

Adds RegionGroupStrategy — a scoping strategy that runs one simulation over the union of several RowFilterStrategy regions (e.g. multiple whole states). This is the reusable .py capability for segmenting a national macro run into ~20 parallel region-group simulations that reconstruct the national result exactly via map-reduce.

Changes (commit by commit)

  • Characterization tests locking the existing household-filter cascade before touching it.
  • Refactor filter_dataset_by_household_variable into a household-ID-set boundary — matching_household_ids (which households) + filter_dataset_by_household_ids (the entity cascade). Keyed on the stable household_id, not a positional mask; public behavior unchanged.
  • RegionGroupStrategy — unions members' household-id sets, reuses the shared cascade, joins the ScopingStrategy discriminated union. Disjoint by construction (member regions never overlap); cache_key is member-order independent.
  • Changelog fragment (added).

Why

Validated end-to-end on staging: concatenating 20 balanced region-group runs reproduces the national macro output bit-for-bit — per-household net_income/tax/weight identical, Gini and budget exact — at ~160s vs ~1,414s for the monolithic national run.

Tests

52 targeted tests pass (7 new RegionGroupStrategy + 5 new cascade characterization + 40 existing entity/scoping); ruff format --check and ruff check clean; run_record serializes the new strategy; towncrier --draft renders. Full local suite was 90% green (all passing) at open time; CI runs the authoritative full suite.

🤖 Generated with Claude Code

anth-volk and others added 4 commits July 20, 2026 15:23
Lock the exact multi-entity cascade of filter_dataset_by_household_variable
(households -> persons -> all group entities) before refactoring it, using the
synthetic CA/CA/NJ fixture.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Split filter_dataset_by_household_variable into matching_household_ids (which
households) and filter_dataset_by_household_ids (the entity cascade), keyed on
the stable household_id rather than a positional mask. Public behavior is
unchanged; the cascade now lives in one place so a union/group filter can reuse
it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Scope a single simulation to the union of several RowFilterStrategy regions
(e.g. multiple whole states) by unioning their household-id sets and reusing the
shared cascade. Members never overlap, so the union is a disjoint concatenation.
cache_key is member-order independent; the strategy joins the ScopingStrategy
discriminated union.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@anth-volk

Copy link
Copy Markdown
Contributor Author

Update: the full local suite is green724 passed in 27m51s (the model-heavy US microsim tests just needed time to finish). ruff format --check + ruff check clean.

…rage

- Fix scoping_strategy module docstring (two -> three strategies; document
  RegionGroupStrategy).
- Clarify that the wrapper's variable-specific empty-message and the id-set
  entry-point's generic guard front different callers (the specific message is
  test- and incident-referenced, so both are kept intentionally).
- Move the shared US/UK group-entity lists + entity_data helper into conftest
  fixtures (us_entity_data / us_group_entities / uk_*), de-duplicating them
  across the filter and region-group tests.
- Add coverage: direct filter_dataset_by_household_ids (explicit ids, any
  iterable, empty -> ValueError); a UK country group; overlapping members not
  double-counted; per-member additional_filters; empty union raises.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review July 20, 2026 14:31
@anth-volk
anth-volk merged commit 0635faf into main Jul 20, 2026
12 checks passed
@anth-volk
anth-volk deleted the feat/region-group-strategy branch July 20, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RegionGroupStrategy for union-of-regions scoping (segmented national runs)

1 participant