Avoid running apply_reform on every baseline Simulation.__init__ (unconditional mi_surtax & combined_reform)
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- performance
Research direction
Start in policyengine_us/system.py at the Simulation.__init__ call to create_structural_reforms_from_parameters, then read policyengine_us/reforms/reforms.py around lines 754–761 and policyengine_us/reforms/states/mi/surtax.py. Compare the proposed baseline mi_surtax variable location under policyengine_us/variables/gov/states/mi/tax/income/ with mi_income_tax.adds. Done means a baseline Simulation with no gov.contrib structural reform returns no reform and skips apply_reform, while the Michigan surtax still respects gov.contrib.states.mi.surtax.in_effect.
Written by the indexing model from the issue text.
Description
Summary
Every Simulation(...) construction in policyengine_us currently runs self.apply_reform(reform) even when using the unmodified baseline system and no user-supplied reform. In a cProfile trace of a single-household simulation, apply_reform inside Simulation.__init__ accounts for ~29 ms per call (~18% of Simulation.__init__).
Root Cause
There are two pieces causing apply_reform to run unconditionally on every baseline Simulation:
-
mi_surtaxis unconditionally returned bycreate_structural_reforms_from_parameters(policyengine_us/reforms/states/mi/surtax.py):- Of the ~140 parameter-driven reforms checked in
create_structural_reforms_from_parameters,mi_surtaxis the only reform returned on the default baselinesystem.parameters. - Following #7377 (which moved the
in_effectcheck intomi_surtax.formula) and #10039 (which addedmi_surtaxto the baselinegov.states.household.state_income_tax_before_refundable_creditslist),create_mi_surtax_reformunconditionally returnscreate_mi_surtax()somi_surtaxexists in every system. - Because
mi_surtaxis already part of every baseline system and gates onparameters(period).gov.contrib.states.mi.surtax.in_effectat calculation time, wrapping it in aReformis no longer needed.
- Of the ~140 parameter-driven reforms checked in
-
create_structural_reforms_from_parametersnever returnsNone(policyengine_us/reforms/reforms.py, lines 754–761):Simulation.__init__(policyengine_us/system.py, lines 356–360) checks:reform = create_structural_reforms_from_parameters( self.tax_benefit_system.parameters, start_instant ) if reform is not None: self.apply_reform(reform)- However,
create_structural_reforms_from_parameterscurrently returnscombined_reformeven ifreformsis empty (()), soif reform is not None:would still evaluate toTrue.
Proposed Fix
- Integrate
mi_surtaxas a standard baseline variable underpolicyengine_us/variables/gov/states/mi/tax/income/(and include"mi_surtax"inmi_income_tax.adds), keeping the calculation-timegov.contrib.states.mi.surtax.in_effectcheck insidemi_surtax.formula(short-circuiting to0before evaluatingmi_taxable_income/tax_unit_is_jointwhenin_effectis false). Removemi_surtaxfromcreate_structural_reforms_from_parameters(keeping any backwards-compatible import alias if needed). - Return
Nonewhen no structural reform is active inpolicyengine_us/reforms/reforms.py:reforms = tuple(filter(lambda x: x is not None, reforms)) if not reforms: return None
Expected Impact
- Baseline
Simulation(...)calls skipself.apply_reform(reform)completely when nogov.contribstructural reform is active. - Exact calculation behavior is preserved for both
in_effect = False(baseline) andin_effect = True(parameter-toggled Michigan surtax).
- Dominant language
- Python
- Stars
- 178
- Forks
- 224
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 309
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PolicyEngine/policyengine-us
-
Secondary earnings threshold description names a stale 2035 capPossibly taken @Prabh022 claimed this 1 day ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
PolicyEngine/policyengine-us#11252 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PolicyEngine/policyengine-us#11201 ·
Maintainers usually reply within 2 days
-
Idaho BBCE households without an elderly or disabled member should face the SNAP net income testPossibly taken @DTrim99 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
PolicyEngine/policyengine-us#11199 ·
Maintainers usually reply within 2 days
-
California's Medi-Cal immigration test passes pregnant people but not those in the postpartum periodOpen
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PolicyEngine/policyengine-us#11192 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
PolicyEngine/policyengine-us#11084 ·
Maintainers usually reply within 2 days
All issues in PolicyEngine/policyengine-us
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
bad-antics/lateralus-lang#1140 ·
Maintainers usually reply within 4 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 3 days
-
fixture good first issue help wanted vendor:cisco
Difficulty 1/5 1-3 hours Newbie friendliness 85/100