PolicyEngine / PolicyEngine/policyengine.py

UK: structural reforms gated on `*.in_effect=True` silently no-op via `simulation_modifier` path

Open
#302 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7
Forks
9
Avg merge
15h 51m
Merged PRs (30d)
9

Description

Flagged during subagent review of #300.

The UK model applies reforms via simulation_modifier_from_parameter_values after Microsimulation construction (src/policyengine/tax_benefit_models/uk/model.py:190,198), using p.update() on parameters. This means any UK structural reform that is gated on a *.in_effect=True parameter — where the structural reform class only activates inside Microsimulation.__init__'s call to create_structural_reforms_from_parameters — would silently no-op.

US recently hit this class of bug (#300) when gov.contrib.ctc.*.in_effect=True reforms crashed because the structural reform's variables were registered on the per-sim system but populations were built from the module-level system. The UK variant is subtly different: the structural reform never gets applied at all because p.update() happens post-construction.

Evidence

  • policyengine_uk/reforms/reforms.py contains at least one in_effect gate (confirmed via grep).
  • UK uses simulation_modifier at src/policyengine/tax_benefit_models/uk/model.py:187-202, which runs after Microsimulation.__init__ has already decided which structural reforms to apply (based on base-parameter in_effect=False).

What to check

  1. Enumerate UK gov.contrib.*.in_effect parameters. If any exist and activate structural reforms, this is a real latent bug.
  2. Write a regression test along the lines of tests/test_us_microsim_structural_reforms.py::test__gov_contrib_gate_runs_cleanly for a UK gate.
  3. If confirmed, the fix is to pass UK reforms at Microsimulation(reform=...) construction time (same pattern US uses) instead of via post-construction p.update().

Not blocking v4.0.1; file as a v4.0.2 / v4.1 candidate.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with policyengine_uk/reforms/reforms.py and src/policyengine/tax_benefit_models/uk/model.py:187-202; enumerate gov.contrib.*.in_effect gates and trace when create_structural_reforms_from_parameters runs in Microsimulation.init. Compare the UK path with tests/test_us_microsim_structural_reforms.py::test__gov_contrib_gate_runs_cleanly. Done means a UK regression test demonstrates the gate works through the intended construction path, with the implementation adjusted if the latent bug is confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.