A reform applied after holders exist leaves them on the old variable, so a variable's default depends on who else is in the simulation
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in simulations/simulation.py at apply_reform (around line 927) and _invalidate_all_caches, then populations/population.py at get_holder (around line 169) to see why existing holders keep their old variable. Compare the holder.default_array() path with the np.where(mask, array, variable.default_value) path in _calculate. Done means one reform gives the same result whether every row or only some rows fail defined_for, with a regression test added.
由索引模型根据 Issue 内容生成。
描述
Problem
Simulation.apply_reform replaces variables on the tax-benefit system but leaves any holder that already exists pointing at the old variable. Holder.default_array() then returns the old default, while Simulation._calculate reads the new one, so one calculation can use both.
We traced this in policyengine-core 3.33.12 and confirmed the lines below at 3.34.1, in simulations/simulation.py unless noted:
apply_reform(line 927) runs the reform, then_invalidate_all_caches(line 940). That clears stored values and keeps eachHolder.variable.Population.get_holder(populations/population.py, line 169) returns an existing holder unchanged.- When every row fails
defined_for,_calculatereturnsholder.default_array()(line 1779), which reads the holder's old variable. - When only some rows fail,
_calculatereachesnp.where(mask, array, variable.default_value)(line 1933), which reads the system's new variable.
policyengine-uk exposes this because Simulation.get_known_variables creates a holder for every variable before its after-data reform runs.
Example
We ran policyengine-uk 2da212abc on Core 3.33.12 with a reform that gives pension_credit_entitlement a default of £2,000, applied after data load. A man aged 40 fails that variable's defined_for.
| Simulation | The man's pension_credit_entitlement |
|---|---|
| Alone, reform applied after data load | £0 |
| With two men aged 63, reform applied after data load | £2,000 |
| Alone, reform applied before data load | £2,000 |
Alone, reform applied after data load, then _bind_to_tax_benefit_system() |
£2,000 |
His result depends on who else the simulation holds, and the system's default reads £2,000 throughout.
What to change
- Rebind holders after a reform: have
apply_reformcall_bind_to_tax_benefit_system()(line 1307), or haveget_holderreplace a holder whose variable has left the system. - Add a test: apply a reform that changes a
defined_forvariable's default after a holder exists, and assert one result for a population where every row fails and for a population where some do.
Related: #612, #632.
🤖 Generated with Claude Code
- 主要语言
- Python
- 星标
- 22
- 派生
- 30
- 平均合并
- 4 天 20 小时
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PolicyEngine/policyengine-core 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
PolicyEngine/policyengine-core#605 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
PolicyEngine/policyengine-core#549 ·
维护者通常 2 天内回复
-
`restore_simulation` silently drops memberless group entities可能已有人在做 @Adelagric 于 55 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
PolicyEngine/policyengine-core#547 ·
维护者通常 2 天内回复
-
Parameter loader turns __pycache__ directories into parameter nodes可能已有人在做 @anth-volk 于 6 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 35/100
PolicyEngine/policyengine-core#638 ·
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
PolicyEngine/policyengine-core#636 ·
维护者通常 2 天内回复
查看 PolicyEngine/policyengine-core 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
huggingface/deep-rl-class#723 ·
-
[tool] bug: Qwen3 XML tool parser raises on `...` argument values (Ellipsis is not JSON serializable)可能已有人在做 @super-yuki 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 87/100
verl-project/verl#8559 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
TencentCloud/octop-harness#228 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
google/osv-scalibr#2585 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
NousResearch/hermes-agent#149323 ·
维护者通常 1 天内回复