A dataset reform simulation's baseline loses inputs the reform neutralizes
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Run the reproduction script to confirm the reform baseline returns [0.0, 0.0] instead of [10.0, 20.0]. Read Simulation.__init__ and _bind_to_tax_benefit_system in simulations/simulation.py around lines 405-413, then Holder.set_input in holders/holder.py:460 to see where neutralized inputs are dropped. Compare with the situation-path fix in #613; the dataset path still needs to load the dataset under the baseline system. Done means the reform simulation returns defaults while reformed.baseline returns the dataset's original values.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
When a simulation built from a dataset applies a reform that neutralizes an input variable, its baseline loses that input as well. The baseline then reads the variable's default, so reform-vs-baseline comparisons describe the wrong baseline.
Simulation.__init__ builds the reform simulation from the dataset under the reform's system. Holder.set_input ignores a value for a neutralized variable (holders/holder.py:460). The baseline is then get_branch("baseline"), rebound to the baseline system by _bind_to_tax_benefit_system (simulations/simulation.py:405-413 in 3.32.27). So the branch inherits holders that never received the column. The rebinding makes the variable un-neutralized again, but there is no data left to read.
#613 fixes the same gap for situations: it builds the baseline from the situation under the baseline system. It keeps the old binding when there is no situation (a dataset, or populations given), so the dataset path still has the bug.
Reproduction (core 3.32.27; master 037960cab has the same set_input and baseline code)
import warnings
import numpy as np
from policyengine_core.entities import build_entity
from policyengine_core.model_api import Variable, YEAR
from policyengine_core.simulations import Simulation
from policyengine_core.taxbenefitsystems import TaxBenefitSystem
Person = build_entity("person", "persons", "Person", is_person=True)
class person_id(Variable):
value_type = int
entity = Person
definition_period = YEAR
label = "Person ID"
class hours(Variable):
value_type = float
entity = Person
definition_period = YEAR
label = "Hours, an input"
class System(TaxBenefitSystem):
def __init__(self, reform=None):
super().__init__([Person])
self.add_variables(person_id, hours)
if reform is not None:
self.apply_reform_set(reform)
class Sim(Simulation):
default_tax_benefit_system = System
default_tax_benefit_system_instance = System()
class Data:
name = "repro"
data_format = "arrays"
time_period = "2024"
file_path = None
def load(self):
return {"person_id": np.array([1, 2]), "hours": np.array([10.0, 20.0])}
class NeutralizeHours:
def apply(self, system):
system.neutralize_variable("hours")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
reformed = Sim(dataset=Data(), reform=NeutralizeHours())
print("plain simulation: ", Sim(dataset=Data()).calculate("hours", 2024).tolist())
print("reform: ", reformed.calculate("hours", 2024).tolist())
print("reform's baseline: ", reformed.baseline.calculate("hours", 2024).tolist())
Output:
plain simulation: [10.0, 20.0]
reform: [0.0, 0.0]
reform's baseline: [0.0, 0.0]
The baseline should read [10.0, 20.0], as the plain simulation does.
Possible fix
Build a dataset reform simulation's baseline branch by loading the dataset under the baseline system, as #613 does for situations. Alternatively, keep the dataset's values for neutralized variables, without exposing them to the reform, so the baseline branch can read them.
Found while reviewing PolicyEngine/policyengine-us#10447. A reform that neutralizes unemployment_compensation_start_month makes both the reform and its baseline treat the column as unsupplied.
🤖 Generated with Claude Code
- Ngôn ngữ chính
- Python
- Star
- 22
- Fork
- 30
- Merge trung bình
- 4 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 35
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PolicyEngine/policyengine-core
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
PolicyEngine/policyengine-core#605 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PolicyEngine/policyengine-core#549 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
`restore_simulation` silently drops memberless group entitiesCó thể đã có người làm @Adelagric đã nhận 48 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PolicyEngine/policyengine-core#547 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 28/100
PolicyEngine/policyengine-core#634 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Remove the Reform and chart functions that call the Public APICó thể đã có người làm @anth-volk đã nhận 6 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
PolicyEngine/policyengine-core#628 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của PolicyEngine/policyengine-core
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
btclib-org/btclib-node#2132 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
freelawproject/juriscraper#2367 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
infra tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
docs(k8s-api-proxy): name the service-account-token Secret path in the read-write mode commentĐang mởneeds-triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
gke-labs/kube-agents#4190 ·
Maintainer thường phản hồi trong vòng 1 ngày