Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

A simulation built from a situation keeps the old system's defaults after apply_reform

オープン
#614 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
57/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

Start with SimulationBuilder, Simulation.apply_reform, and _invalidate_all_caches, then read the changes in #613 to understand _build_from_situation and skip_rejected_inputs. Reproduce the examples in the issue with the stated Python command, including a set_input call after construction. Done when applying a reform rebuilds situation inputs under the new system while preserving inputs added afterward, and the three salary calculations match the expected values.

索引モデルが issue の本文から書いたものです。

説明

Problem

A simulation built from a situation keeps, after its system changes, the inputs the situation builder made under the old system. SimulationBuilder gives the people a situation gives no value for a variable it gives others (or sets along axes) that variable's default and stores the whole array as an input, so those people keep the old system's default. #612 is the same leak into a reform simulation's baseline; this is the other direction, into the reformed simulation.

Reproduced on master b909d5a60 (and on #613's branch, which does not change it), from the repository root with uv run --frozen --extra dev python:

import sys; sys.path.insert(0, ".")
from policyengine_core.country_template import CountryTaxBenefitSystem, Simulation
from tests.core.test_reform_baseline_system import change_salary_default  # salary default 0 -> 1000

P = "2022-01"
sit = {"persons": {"a": {"salary": {P: 3000.0}}, "b": {}}, "households": {"h": {"parents": ["a", "b"]}}}
print(Simulation(situation=sit, reform=change_salary_default).calculate("salary", P))  # [3000. 1000.]

s = Simulation(situation=sit)
s.apply_reform(change_salary_default)
print(s.calculate("salary", P))  # [3000.    0.]: the reform's default is 1000

s2 = Simulation(tax_benefit_system=CountryTaxBenefitSystem(), situation=sit, reform=change_salary_default)
print(s2.calculate("salary", P))  # [3000.    0.]
  • apply_reform changes the system in place, and _invalidate_all_caches replays every recorded input, including the arrays the builder filled with the old default.
  • Simulation.__init__ with both tax_benefit_system and reform builds the situation under the system it was given, then applies the reform to that system (apply_reform_set).

policyengine-us applies its structural reforms with apply_reform right after Simulation.__init__, so a structural reform that changes an input variable's default (or neutralizes one the situation gives) reaches its household simulations this way.

Expected

After its system changes, a simulation built from a situation holds what the builder makes of that situation under the new system, plus any inputs set on it afterwards.

Notes

#613 adds Simulation._build_from_situation and SimulationBuilder.skip_rejected_inputs, which build a situation into a simulation under its own system. Rebuilding on apply_reform also needs to keep the inputs set after construction (set_input calls, which _invalidate_all_caches replays today) apart from the builder's.

主要言語
Python
スター
22
フォーク
30
平均マージ
2日 19時間
マージ済み PR(30日)
25

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PolicyEngine/policyengine-core のほかの issue

PolicyEngine/policyengine-core の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。