Repository navigation
Conversation
Creating a Simulation or Microsimulation with a reform and no supplied tax-benefit system rebuilt CountryTaxBenefitSystem from every parameter and variable file. Copy the built default system instead, return it to its state before the reform-dependent steps, and run those steps on the copy. Fall back to a full build when the default system has changed in a way that would make the copy differ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
Draft: do not merge. This PR stays in draft until both required dependencies below are met.
Dependencies
Required
modifiedflags on different ancestors in a cloned parameter tree than in a loaded one, so a derived system does not match a full build.policyengine-coreminimum inpyproject.tomland updateuv.lockto that releasebrackets[1].parent is None, which fails on the core release above.Related, not required
PolicyEngine/policyengine-us#11121 also edits
policyengine_us/tools/per_capita_uprating.pyand changes which structural reforms build. Whichever PR merges second resolves any text conflict. If it merges first, the comparison below is rerun with it included.CI: this branch still installs the locked core version (
uv.lockhas 3.36.0), which has no parent links. Tests that compare a derived system with a full build are expected to fail until the core dependency is met.What and why
Creating a
SimulationorMicrosimulationwithreform=and notax_benefit_system=builds a newCountryTaxBenefitSystem, which reloads about 12,000 parameter files and 12,300 variable files. Almost none of that work depends on the reform._prepare_spm_systemnow asks the built default system to derive the reform's system:_apply_reforms) on the copy, including structural-reform detection atstart_instant.with_parameter_barrier, as before.It uses a full build when derivation cannot give the same result: the default system's variable registry or per-capita parameter nodes changed, a parameter is marked
modified, or the system class has its own constructor.Who is affected: .py passes
reform=without a system, so its household calculations and microsimulations use this path. API v1 society-wide simulations reach it through the simulation API and .py. Household calculations in API v1 and the household API do not: they clone their own system, apply the reform and passtax_benefit_system=.Known limit: changes to the shared default system that set no
modifiedflag are not detected, such asadd_child,merge, assignments tovalues_list[i].value, and metadata or variable attribute edits. A derived system includes them, as simulations sharing the default system already do; a full build would not. Thecan_derive_reform_systemsdocstring records this. A text search of the default branches of API v1, the household API, the simulation API, .py and app-v2 found no code that edits a policyengine-us system in place.Evidence
Comparison with a full build: 846 reforms, no differences. The code compared has the same tree as this PR's first commit (
1269314122). It ran on core commit1ce7fd23, an earlier commit of policyengine-core#660.VariableNameConflictErrorin the simulation stepsThe default system was unchanged throughout. The corpus contains no stored production policies.
Build time per reform system (local macOS):
These are not Modal or Linux CI measurements.
Not yet covered: policyengine-core#660 has moved 4 commits past
1ce7fd23. The 20 new tests pass on its current head (84e4d33e), but the 846-reform comparison has not been rerun there.Test plan
policyengine_us/tests/core/test_derived_reform_system.py, run by node ID against policyengine-core#660 at84e4d33e: all passruff formaton the changed Python fileschangelog.d/Test cost: the new file took 145.8 s elapsed, 124.9 s user CPU and a peak of 4.89 GB resident memory on macOS with Python 3.14. This is not a Linux CI measurement. The file falls in the rest-python
coregroup, which already measured 13.3 GB in CI run 38141803955 against a target of about 10 GB per process, so it may need its own group inREST_PYTHON_GROUPS. That decision waits for this group's CI report.axiom: n/a: changes how the tax-benefit system is constructed, with no policy change
🤖 Generated with Claude Code