Skip to content

Open property allowance elections still compute benefits in whole-simulation branches after #2695, so UK microsimulations run about 4× slower than 2.151.0 #2707

Closed

Description

@juaristi22

#2695 halved the cost that #2066 added to uses_property_allowance (#2694). On a Microcosm UK file, though, a standard microsimulation is still about four times slower than on 2.151.0. Income tax alone is about 28 times slower.

Timings

Microcosm UK national cut microcosm-uk-2024-25-national-20261028T061416Z-3c0d11b6, one Mac, policyengine-core 3.33.3. Each run builds a Microsimulation from the H5, then calculates 2025 income_tax, then household_net_income:

policyengine-uk Build income_tax 2025 household_net_income after it
2.151.0 20.1 s 1.9 s 7.2 s
2.162.12 (before #2695) 127.3 s 119.5 s 2.2 s
2.162.14 60.9 s 54.2 s 2.7 s

Where the time goes on 2.162.14

cProfile shows two paths.

Income tax. income_tax_before_winter_fuel_payment_charge → taxable_property_income → property_allowance_deduction → uses_property_allowance takes 53.5 s, with with_route called 72 times. Each branch recomputes the winter fuel payment charge's relevant benefits: winter_fuel_payment_charge → winter_fuel_payment_eligible → is_on_winter_fuel_payment_relevant_benefit → is_on_pension_credit, about 51 s.

The build. scenarios/uc_reform.py:add_universal_credit_reform takes 57 s of the 71 s build. It goes uc_LCWRA_element → uc_limited_capability_for_work → has_own_esa_award → esa_income → esa_exempt_work_earnings → personal_allowance → adjusted_net_income, and on into the same election and its branches.

So the elections the ceiling leaves open still cost a pair of branches of the whole simulation. Every benefit the charge reads is worked out for everyone in each branch, even when only a few households are open.

What restores the speed, and what doesn't

  • The election supplied as an input (set_input("uses_property_allowance", 2025, …) after the build). 2025 income tax takes 3.5 s and is identical. The build is unchanged, because the UC scenario has already run.
  • The election stored in the H5 as a column, at the data year. The build takes 15.5 s and income tax 3.5 s, with weighted totals unchanged. A few records differ in 2025, because a stored election stays at the data year, and it no longer responds to reforms.
  • The charge switched off (gov.hmrc.income_tax.charges.winter_fuel_payment.in_effect false). Income tax takes 10.4 s, but the charge is gone.

None of these is a fix: the first two freeze the election, and the third removes the law.

Why it matters

policyengine.py's UK certification steps, the #574 reform contract and reform responsiveness, run many full simulations. So do the Budget dashboard's reform runs. Each of those simulations pays these costs, so the evidence for a new pair takes several times longer than it did on 2.151.0.

Proposal

Make the open comparisons cost in proportion to the households they concern, and keep every election identical, along with the order, rounds and stopping rule #2695 relies on. Options:

  • A sub-simulation. Compare the open elections on a simulation of only the affected households or benefit units. Settle property allowance elections without the charge where it cannot change them #2695 already relies on one household's routes not moving another's tax.
  • Reuse benefit results. Inside the branches, reuse the main simulation's benefit results wherever the route cannot change them. The route moves a landlord's taxable income, which reaches the charge through total income, not through benefit entitlement.
  • Compute relevant-benefit receipt once, outside the branch loop, if the routes cannot change it.

Testing. Every uses_property_allowance value and income_tax must be unchanged on the existing tests and on a synthetic population. The synthetic population needs landlords with property finance costs near the allowance, plus pensioners above £35,000 who receive a winter payment. The enhanced FRS barely moves here, because it has no property_finance_costs input (#2694).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions