SimulationBuilder.build_from_dict should clear dataset provenance when rebuilding from a situation
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
調査の方向性
Start with SimulationBuilder.build_from_dict, then trace build_from_entities and build_from_variables in simulation_builder.py alongside provenance initialization in simulation.py. Check how clones and branches copy source state. Done means both rebuild paths clear dataset provenance, record the active situation, and preserve correct provenance in derived clones and branches.
索引モデルが issue の本文から書いたものです。
説明
Found while adopting PolicyEngine/policyengine-uk#1831 (UK hub, 2026-10-20).
PolicyEngine Core version: 3.33.2. Reproduced with synthetic MOCK data and the UK tax-benefit system, without private datasets or downloads.
SimulationBuilder.build_from_dict(system, situation, simulation) supports overwriting an existing simulation. When that simulation was built over a dataset, the method replaces its population structure and inputs but leaves is_over_dataset=True and retains dataset. It also leaves situation_input=None. Its clones and newly created branches inherit this stale provenance.
Reproducer
import pandas as pd
from policyengine_core.simulations import Simulation
from policyengine_core.simulations.simulation_builder import SimulationBuilder
from policyengine_uk.system import system
year = 2026
frame = pd.DataFrame(
{
f"person_id__{year}": [1],
f"person_benunit_id__{year}": [1],
f"person_household_id__{year}": [1],
f"benunit_id__{year}": [1],
f"household_id__{year}": [1],
f"age__{year}": [70],
}
)
situation = {
"people": {"adult": {"age": {year: 70}}},
"benunits": {"family": {"members": ["adult"]}},
"households": {"home": {"members": ["adult"]}},
}
simulation = Simulation(tax_benefit_system=system, dataset=frame)
original_dataset = simulation.dataset
builder = SimulationBuilder()
builder.default_period = year
rebuilt = builder.build_from_dict(system, situation, simulation)
assert rebuilt is simulation
print(rebuilt.persons.ids) # ['adult']
print(rebuilt.is_over_dataset) # True (expected False)
print(rebuilt.dataset is original_dataset) # True (expected cleared)
print(rebuilt.situation_input) # None (no new situation marker)
print(rebuilt.clone().is_over_dataset) # True (expected False)
print(rebuilt.get_branch("rebuilt").is_over_dataset) # True (expected False)
Expected behavior
Rebuilding from a situation should reset is_over_dataset, clear the previous dataset, and record the situation as the active source. The behavior should cover both build_from_entities and build_from_variables, including clones and branches derived after the rebuild. A canonical source marker or population-rebuild hook would also let subclasses keep their own provenance in sync.
Source finding and downstream effect
In Core 3.33.2, Simulation.__init__ sets is_over_dataset (simulation.py:801) and situation_input (simulation.py:897). SimulationBuilder.build_from_dict (simulation_builder.py:66–96) only dispatches the build and refreshes input_variables; build_from_entities (98–192) updates population counts, IDs, memberships and holder inputs without recording a source change. The builder's population bookkeeping is not retained as an independent source marker on the simulation. Population IDs or input variable names are not reliable provenance: either source can use the same IDs and variables, and variable-only situations also use NumPy ID arrays.
The PE-UK provenance probe classifies 20 of 24 routes correctly. Its four failures are a data-built core simulation overwritten by this builder, its clone, its new branch, and a data-built UK simulation overwritten directly by the core builder. PE-UK's supported Simulation.build_from_situation rebuild path resets its own source marker correctly. No supported production caller found by the UK hub uses these four direct core-builder overwrite routes.
This matters for model formulas that distinguish survey runs from explicit household situations. PE-UK currently documents the direct overwrite limitation instead of guessing from IDs, weights or population size.
🤖 Generated with Claude Code
- 主要言語
- Python
- スター
- 22
- フォーク
- 30
- 平均マージ
- 4日 16時間
- マージ済み PR(30日)
- 35
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PolicyEngine/policyengine-core のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
PolicyEngine/policyengine-core#605 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
PolicyEngine/policyengine-core#549 ·
メンテナーはふだん 3 日以内に返信
-
`restore_simulation` silently drops memberless group entities対応中かも @Adelagric が 45 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
PolicyEngine/policyengine-core#547 ·
メンテナーはふだん 3 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 28/100
PolicyEngine/policyengine-core#634 ·
メンテナーはふだん 3 日以内に返信
-
subsample reloads calculated values as inputs, so a reform's baseline reads the reform's resultsオープン
難易度 4/5 3〜5日 初心者へのやさしさ 40/100
PolicyEngine/policyengine-core#633 ·
メンテナーはふだん 3 日以内に返信
PolicyEngine/policyengine-core の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
nansencenter/geodataset#39 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
awslabs/visual-asset-management-system#804 ·
メンテナーはふだん 1 日以内に返信
-
follow-up
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
link-rot
難易度 1/5 1時間未満 初心者へのやさしさ 67/100