Skip to content

Derive US program-statistics entity from variable metadata#342

Open
vahid-ahmadi wants to merge 2 commits intomainfrom
program-specs-derive-entity
Open

Derive US program-statistics entity from variable metadata#342
vahid-ahmadi wants to merge 2 commits intomainfrom
program-specs-derive-entity

Conversation

@vahid-ahmadi
Copy link
Copy Markdown

Refs #326. Smaller follow-up on top of merged #327. Replaces #334.

Summary

  • Drop the duplicated entity field from US_PROGRAMS. Entity is now derived from model_version.get_variable(name).entity at runtime, so the program list cannot silently drift when policyengine-us moves a variable between entities.
  • Keeps the "missing outputs" check that Fix US program statistics variable mappings #327 added in _validate_program_statistics_config (variable must be both defined in the model and materialized in the simulation outputs).
  • Adds test_us_programs_entities_match_model_metadata so a typo or rename in US_PROGRAMS is caught at test time, not at simulation time.

Why this instead of #334

#334 was authored before #327 landed and (a) is severely behind main, (b) drops the materialized-outputs check from #327, and (c) introduced a programs.py module / ProgramSpec dataclasses that aren't load-bearing for the entity-derivation goal. This PR keeps only the durable improvement and stays minimal.

Test plan

  • pytest tests/test_us_program_statistics.py (covers entity derivation in economic_impact_analysis and the new metadata-match test).
  • pytest tests/test_aggregate.py tests/test_change_aggregate.py still passes.

🤖 Generated with Claude Code

Replace the duplicated entity field in the ``US_PROGRAMS`` dict with a
metadata-driven lookup via ``model_version.get_variable(name).entity``,
so the program list cannot silently drift when policyengine-us moves a
variable between entities. The "missing outputs" check from #327 is
preserved.

Refs #326. Closes #334 (smaller follow-up on top of merged #327).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…tadata

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vahid-ahmadi vahid-ahmadi requested a review from anth-volk May 7, 2026 12:34
@vahid-ahmadi vahid-ahmadi self-assigned this May 7, 2026
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.

1 participant