Problem
economic_impact_analysis() in both us/analysis.py and uk/analysis.py is broken and untested. The API (policyengine-api-v2-alpha) bypasses it entirely, reimplementing all orchestration in computation_modules.py (818 lines) with workarounds for library bugs.
What's broken today
| Issue |
Detail |
| Wrong US program names |
payroll_tax → employee_payroll_tax, state_income_tax not a program |
Wrong US entity for ssi |
Uses person, should be spm_unit |
| Too many US programs |
11 programs; API only uses 6 that work |
Missing model_rebuild() |
ProgrammeStatistics (UK) never rebuilt |
calculate_decile_impacts() creates new sims |
Wasteful when caller already has run simulations |
| No intra-decile computation |
API computes this; library skips it |
| No budget summary |
No class exists; API has workaround for double-weighting |
| No poverty by demographics |
API computes age/gender/race breakdowns; library skips them |
StopIteration on missing variables |
Crashes instead of clear error |
Solution
- Add
CountryConfig strategy class with US_CONFIG/UK_CONFIG — eliminates country conditionals
- Add
compute_budget_summary(), compute_decile_impacts(), compute_program_statistics() as individual functions
- Add
PolicyReformAnalysis unified result container
- Rewrite
economic_impact_analysis() for both countries to use individual compute functions
- Fix
model_rebuild() in both __init__.py files
- Fix error handling in
Aggregate/ChangeAggregate (StopIteration → ValueError)
This is Phase 1 of consolidating logic from policyengine-api-v2-alpha back into policyengine.py.
Problem
economic_impact_analysis()in bothus/analysis.pyanduk/analysis.pyis broken and untested. The API (policyengine-api-v2-alpha) bypasses it entirely, reimplementing all orchestration incomputation_modules.py(818 lines) with workarounds for library bugs.What's broken today
payroll_tax→employee_payroll_tax,state_income_taxnot a programssiperson, should bespm_unitmodel_rebuild()ProgrammeStatistics(UK) never rebuiltcalculate_decile_impacts()creates new simsStopIterationon missing variablesSolution
CountryConfigstrategy class withUS_CONFIG/UK_CONFIG— eliminates country conditionalscompute_budget_summary(),compute_decile_impacts(),compute_program_statistics()as individual functionsPolicyReformAnalysisunified result containereconomic_impact_analysis()for both countries to use individual compute functionsmodel_rebuild()in both__init__.pyfilesAggregate/ChangeAggregate(StopIteration→ValueError)This is Phase 1 of consolidating logic from
policyengine-api-v2-alphaback intopolicyengine.py.