Population.__call__ passes unweighted=True to calculate_add and calculate_divide, which reject it
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Start with policyengine_core/populations/population.py around the Population.__call__ argument handling, then inspect Simulation.calculate_add and calculate_divide in policyengine_core/simulations/simulation.py. Reproduce with the described UKStyleMicrosimulation fixture and cover ADD and DIVIDE reads both directly and through formulas. Done when those reads no longer raise the unexpected unweighted TypeError and the regression tests pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When a simulation class has "micro" in its name and doesn't subclass core's Microsimulation, Population.__call__ adds unweighted=True to a read's keyword arguments (population.py#L152-L154). It sends a read with options=[ADD] or options=[DIVIDE] to calculate_add or calculate_divide with those arguments (#L157-L164). Simulation.calculate_add and calculate_divide take no unweighted argument (simulation.py#L2159-L2164, #L2237-L2242), so Python rejects the call:
TypeError: Simulation.calculate_add() got an unexpected keyword argument 'unweighted'
policyengine-uk's Microsimulation meets both conditions: it subclasses policyengine-uk's Simulation, a core Simulation (microsimulation.py#L14). Its calculate takes unweighted (#L41-L58). policyengine-uk's calculate_add and calculate_divide forward their keyword arguments to core (simulation.py#L1961-L1973). So a formula that read with ADD or DIVIDE would raise the TypeError in a policyengine-uk Microsimulation. We read policyengine-uk's code for this and ran no policyengine-uk simulation.
Nothing fails today. No formula on policyengine-uk main reads with an option. Two test reads use one (test_stored_draw_input_source.py#L343-L347), and both expect the StoredDrawError that policyengine-uk raises before it calls core.
Reproduction
UKStyleMicrosimulation takes unweighted in calculate, as policyengine-uk's class does. Run this from the root of a policyengine-core checkout that has tests/fixtures/microsimulation_option_reads.py:
from policyengine_core.country_template import Simulation
from policyengine_core.data import Dataset
from policyengine_core.model_api import ADD, DIVIDE
from tests.fixtures.microsimulation_option_reads import (
DATASET_YEAR,
Inputs,
dataframe,
tax_benefit_system,
)
class UKStyleMicrosimulation(Simulation):
def calculate(
self,
variable_name,
period=None,
map_to=None,
decode_enums=False,
unweighted=False,
):
return super().calculate(
variable_name, period, map_to=map_to, decode_enums=decode_enums
)
inputs = Inputs(
household_of_person=(0, 0, 1),
household_weight=(10.0, 20.0),
monthly_pay=((1.0,) * 12, (2.0,) * 12, (5.0,) * 12),
yearly_grant=(120.0, 240.0, 600.0),
household_monthly_fee=((0.0,) * 12, (0.0,) * 12),
household_yearly_grant=(0.0, 0.0),
)
def uk_style():
return UKStyleMicrosimulation(
tax_benefit_system=tax_benefit_system(),
dataset=Dataset.from_dataframe(dataframe(inputs), DATASET_YEAR),
)
reads = [
lambda simulation: simulation.populations["person"]("monthly_pay", "2022-06"),
lambda simulation: simulation.populations["person"](
"monthly_pay", "2022", options=[ADD]
),
lambda simulation: simulation.populations["person"](
"yearly_grant", "2022-06", options=[DIVIDE]
),
lambda simulation: simulation.calculate("pay_added", "2022"),
lambda simulation: simulation.calculate("grant_divided", "2022-06"),
]
for read in reads:
try:
print(read(uk_style()))
except TypeError as error:
print("TypeError:", error)
At #647's head it printed the lines below. Master's calculate_add and calculate_divide still take no unweighted argument.
[1. 2. 5.]
TypeError: Simulation.calculate_add() got an unexpected keyword argument 'unweighted'
TypeError: Simulation.calculate_divide() got an unexpected keyword argument 'unweighted'
TypeError: Simulation.calculate_add() got an unexpected keyword argument 'unweighted'
TypeError: Simulation.calculate_divide() got an unexpected keyword argument 'unweighted'
The plain read computes. The ADD read, the DIVIDE read and the two formulas that make them, pay_added and grant_divided, raise.
What a fix would change
Population.__call__would passunweighted=Truetocalculatealone, and send ADD and DIVIDE reads withdecode_enums=Falseonly.Simulation.calculate_addandcalculate_dividewould then read each term with the class's owncalculate. In policyengine-uk'sMicrosimulation, that method skips weights while the tracer's stack holds a calculation, so a read inside a formula would sum or divide plain arrays.- A test would read with ADD and DIVIDE, directly and through a formula, in a
Simulationsubclass that has "micro" in its name and takesunweightedincalculate. It fails today with theTypeError. - #647's signature test checks the keyword calls that
Simulation's calculate methods take, andunweightedisn't one of them, so that test doesn't cover this call.
- Ngôn ngữ chính
- Python
- Star
- 22
- Fork
- 31
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 14
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 1 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 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
PolicyEngine/policyengine-core#666 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
PolicyEngine/policyengine-core#665 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
PolicyEngine/policyengine-core#656 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của PolicyEngine/policyengine-core
Issue tương tự
-
claude-subscription-directsdk: tool calls with raw control characters in string values are droppedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NousResearch/hermes-official-plugins#538 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug(qdiffusion): EnergyModel.score_visible_logits computes biased visible/hidden on-ratios when solver returns variable solution counts per candidateCó thể đã có người làm @houzhongyu đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
qboson/kaiwu-pytorch-plugin#2133 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MakazhanAlpamys/Soup#3415 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ 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 2 ngày