From 08aab06434140aba78e79b15190ab65961a2214f Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Wed, 2 Dec 2026 00:05:53 +0400 Subject: [PATCH 1/7] Test that a Stage 12 cliff calculation gives policyengine-us's cliffs One household at a time, built as a .py US dataset, runs through the service's cliff calculation (the planned cliff columns, .py's Simulation(dataset=...), and the weighted totals) and must give the cliff gap and share policyengine-us calculates for the same household given as a situation. On .py 6.20.4 a retiree with Social Security gets a gap of $22,644.95 instead of $0, and a parent of two on a real cliff $5,224.68 instead of $460.95: .py lists none of the dataset's columns in input_variables, so marginal_tax_rate's copies lose them. Co-Authored-By: Claude Opus 5.5 --- .../test_stage12_cliff_dataset_inputs.py | 209 ++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py diff --git a/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py b/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py new file mode 100644 index 000000000..bb398d99f --- /dev/null +++ b/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py @@ -0,0 +1,209 @@ +"""A cliff calculation keeps every dataset input in its extra-earnings copies. + +API v2's cliff gap and cliff share come from Stage 12's cliff calculation: +``resolve_cliff_output_plan`` plans the cliff columns, the worker builds .py's +``Simulation(dataset=…)``, ``apply_output_plan`` adds the columns, and +``cliff_totals_from_frames`` sums the rows. ``cliff_gap`` reads policyengine-us's +``marginal_tax_rate``, which recalculates each household's net income in a copy +of the simulation that keeps only the values listed in the simulation's +``input_variables``. From 6.0.0 to 6.20.4, .py stored a US dataset's columns +after constructing the country simulation, so that list named none of them: +the copies lost age, location, Social Security and every other dataset input, +and the income they lost was reported as cliff gaps. + +These tests run one household through the service's cliff calculation and +expect the cliff gap and share that policyengine-us calculates for the same +household given as a situation, whose inputs it lists at construction. On +.py 6.20.4 (policyengine-us 2.2.2) the retiree gets a gap of $22,644.95 +instead of $0, and the parent, whom policyengine-us does place on a cliff at +$50,000 of earnings, $5,224.68 instead of $460.95. + +The worker calls ``ensure()``, which adds loading and saving stored outputs +around the same ``run()``; these tests call ``run()``, so nothing is read from +or written to disk. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING, NamedTuple + +import pandas as pd +import pytest +from microdf import MicroDataFrame +from policyengine.core import Simulation +from policyengine.tax_benefit_models.us import PolicyEngineUSDataset, USYearData +from policyengine_simulation_contract.stage12_execution import SimulationRole +from policyengine_simulation_executor.simulation_runtime import _country_module +from policyengine_simulation_executor.stage12_runtime.cliff_results import ( + CliffTotals, + cliff_totals_from_frames, +) +from policyengine_simulation_executor.stage12_runtime.output_planning import ( + apply_output_plan, + resolve_cliff_output_plan, + validate_output_frames, +) +from policyengine_us import Simulation as PolicyEngineUSSimulation +from stage12_runtime_support import simulation_execution_input + +if TYPE_CHECKING: + from policyengine_simulation_contract.stage12_execution import Stage12OutputPlan + +YEAR = 2026 +NORTH_CAROLINA_STATE_FIPS = 37 +WAKE_COUNTY_FIPS = "37183" +GROUP_ENTITIES = ("tax_unit", "spm_unit", "family") + + +class OneHousehold(NamedTuple): + """One household in Wake County, North Carolina: each person's inputs.""" + + people: tuple[dict[str, float], ...] + + +RETIREE_WITH_SOCIAL_SECURITY = OneHousehold( + people=( + { + "age": 67, + "employment_income": 15_000.0, + "social_security_retirement": 24_000.0, + }, + ) +) +PARENT_OF_TWO_ON_A_CLIFF = OneHousehold( + people=( + {"age": 30, "employment_income": 50_000.0}, + {"age": 3}, + {"age": 6}, + ) +) + + +@pytest.fixture(scope="module") +def cliff_output_plan() -> Stage12OutputPlan: + """Return the columns a US cliff calculation stores, as the worker plans them.""" + return resolve_cliff_output_plan( + simulation_execution_input(SimulationRole.BASELINE) + ) + + +@pytest.mark.parametrize( + "household", + [ + pytest.param(RETIREE_WITH_SOCIAL_SECURITY, id="retiree-with-social-security"), + pytest.param(PARENT_OF_TWO_ON_A_CLIFF, id="parent-of-two-on-a-cliff"), + ], +) +def test_a_cliff_calculation_gives_policyengine_us_cliffs_for_a_dataset_household( + household: OneHousehold, cliff_output_plan: Stage12OutputPlan +) -> None: + calculated = _stage12_cliff_totals(household, cliff_output_plan) + + expected = _policyengine_us_cliff_totals(household) + assert calculated.cliff_gap == pytest.approx(expected.cliff_gap, abs=0.01) + assert calculated.cliff_share == pytest.approx(expected.cliff_share) + + +def _stage12_cliff_totals( + household: OneHousehold, output_plan: Stage12OutputPlan +) -> CliffTotals: + """Calculate the household's cliffs as a Stage 12 cliff worker does.""" + simulation = Simulation( + dataset=_one_household_dataset(household), + tax_benefit_model_version=_country_module("us").model, + policy=None, + ) + apply_output_plan(simulation, output_plan) + simulation.run() + entity_data = simulation.output_dataset.data.entity_data + frames = {entity: pd.DataFrame(frame) for entity, frame in entity_data.items()} + validate_output_frames(frames, output_plan) + return cliff_totals_from_frames(frames, output_plan) + + +def _policyengine_us_cliff_totals(household: OneHousehold) -> CliffTotals: + """Calculate the household's cliffs in policyengine-us, from a situation.""" + names = [f"person_{index}" for index in range(len(household.people))] + simulation = PolicyEngineUSSimulation( + situation={ + "people": { + name: {variable: {YEAR: value} for variable, value in inputs.items()} + for name, inputs in zip(names, household.people, strict=True) + }, + **{ + f"{entity}s": {entity: {"members": names}} + for entity in ("tax_unit", "spm_unit") + }, + "families": {"family": {"members": names}}, + "marital_units": { + f"marital_unit_{index}": {"members": [name]} + for index, name in enumerate(names) + }, + "households": { + "household": { + "members": names, + "state_fips": {YEAR: NORTH_CAROLINA_STATE_FIPS}, + "county_fips": {YEAR: WAKE_COUNTY_FIPS}, + } + }, + } + ) + adults = float(simulation.calculate("is_adult", YEAR).sum()) + return CliffTotals( + cliff_gap=float(simulation.calculate("cliff_gap", YEAR).sum()), + cliff_share=float(simulation.calculate("is_on_cliff", YEAR).sum()) / adults, + ) + + +def _one_household_dataset(household: OneHousehold) -> PolicyEngineUSDataset: + """Return the household as a .py US dataset: one tax unit, SPM unit and family. + + Each person is their own marital unit, and every weight is 1. + """ + person_count = len(household.people) + person_ids = list(range(1, person_count + 1)) + input_names = sorted({name for inputs in household.people for name in inputs}) + person = pd.DataFrame( + { + "person_id": person_ids, + "person_household_id": [1] * person_count, + **{f"person_{entity}_id": [1] * person_count for entity in GROUP_ENTITIES}, + "person_marital_unit_id": person_ids, + "person_weight": [1.0] * person_count, + **{ + name: [inputs.get(name, 0.0) for inputs in household.people] + for name in input_names + }, + } + ) + groups = { + entity: _weighted(pd.DataFrame({f"{entity}_id": [1]}), entity) + for entity in GROUP_ENTITIES + } + marital_units = pd.DataFrame({"marital_unit_id": person_ids}) + households = pd.DataFrame( + { + "household_id": [1], + "state_fips": [NORTH_CAROLINA_STATE_FIPS], + "county_fips": [WAKE_COUNTY_FIPS], + } + ) + return PolicyEngineUSDataset( + id="stage12-cliff-one-household", + name="stage12-cliff-one-household", + description="One household in Wake County, North Carolina", + filepath=None, + year=YEAR, + data=USYearData( + person=MicroDataFrame(person, weights="person_weight"), + marital_unit=_weighted(marital_units, "marital_unit"), + household=_weighted(households, "household"), + **groups, + ), + ) + + +def _weighted(frame: pd.DataFrame, entity: str) -> MicroDataFrame: + """Return ``frame`` with a weight of 1 for each row, as ``_weight``.""" + weight = f"{entity}_weight" + return MicroDataFrame(frame.assign(**{weight: 1.0}), weights=weight) From c9dd4223317d2fc169d3ac36118b3435b0209896 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Wed, 2 Dec 2026 00:06:15 +0400 Subject: [PATCH 2/7] Add the changelog fragment for running .py 6.20.5 6.20.5 is the version the .py release that lists a US dataset's inputs in input_variables is expected to have; the pin and lock move to it once it is on PyPI. Co-Authored-By: Claude Opus 5.5 --- changelog.d/update-policyengine-6.20.5.changed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/update-policyengine-6.20.5.changed.md diff --git a/changelog.d/update-policyengine-6.20.5.changed.md b/changelog.d/update-policyengine-6.20.5.changed.md new file mode 100644 index 000000000..7612642d7 --- /dev/null +++ b/changelog.d/update-policyengine-6.20.5.changed.md @@ -0,0 +1 @@ +Updated policyengine.py from 6.20.4 to 6.20.5 in the simulation runtime. 6.20.5 lists every column it stores from a US dataset in the simulation's `input_variables`. policyengine-us's `marginal_tax_rate` recalculates each household's net income in copies of the simulation that keep only those inputs, so until now the copies lost each household's age, location, Social Security and other dataset inputs, and US cliff gaps and cliff shares counted the income they lost as cliffs: a retiree with $15,000 of earnings and $24,000 of Social Security got a cliff gap of $22,644.95 instead of $0. API v1 sends its own .py version with each request, so its reports, and API v2's, move to 6.20.5 only when API v1 raises its own pin. From 1b34c74d9e677290cba834a16305921ad6bd51d3 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Wed, 2 Dec 2026 00:29:57 +0400 Subject: [PATCH 3/7] Check the reform side, and that the parent is still on a cliff Review round 1. The parent of two now runs under a raised Child Tax Credit, which .py builds from the dataset twice (the reform and its baseline), so the test covers the reform side API v2 also calculates cliffs for. The test also checks that policyengine-us still gives that household a cliff gap, so a later model change can't turn the case into a second zero-gap check unnoticed. On .py 6.20.4 the parent's gap is $6,824.68 instead of $460.95. Co-Authored-By: Claude Opus 5.5 --- .../test_stage12_cliff_dataset_inputs.py | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py b/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py index bb398d99f..77d25a964 100644 --- a/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py +++ b/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py @@ -13,10 +13,14 @@ These tests run one household through the service's cliff calculation and expect the cliff gap and share that policyengine-us calculates for the same -household given as a situation, whose inputs it lists at construction. On -.py 6.20.4 (policyengine-us 2.2.2) the retiree gets a gap of $22,644.95 -instead of $0, and the parent, whom policyengine-us does place on a cliff at -$50,000 of earnings, $5,224.68 instead of $460.95. +household and policy given as a situation, whose inputs it lists at +construction. Each household lives in Wake County, North Carolina, in 2026. +A retiree under current law covers a run with no policy, which .py builds once +from the dataset. A parent of two, whom policyengine-us places on a cliff, +runs under a raised Child Tax Credit, which .py builds twice from the dataset +(the reform and its baseline). On .py 6.20.4 (policyengine-us 2.2.2) the +retiree gets a gap of $22,644.95 instead of $0, and the parent $6,824.68 +instead of $460.95. The worker calls ``ensure()``, which adds loading and saving stored outputs around the same ``run()``; these tests call ``run()``, so nothing is read from @@ -32,7 +36,9 @@ from microdf import MicroDataFrame from policyengine.core import Simulation from policyengine.tax_benefit_models.us import PolicyEngineUSDataset, USYearData +from policyengine_core.reforms import Reform from policyengine_simulation_contract.stage12_execution import SimulationRole +from policyengine_simulation_executor.request_policy import normalise_policy from policyengine_simulation_executor.simulation_runtime import _country_module from policyengine_simulation_executor.stage12_runtime.cliff_results import ( CliffTotals, @@ -56,9 +62,16 @@ class OneHousehold(NamedTuple): - """One household in Wake County, North Carolina: each person's inputs.""" + """One household in Wake County, North Carolina, and the policy it runs under. + + ``policy`` is a request's policy, as API v2 sends it (None for current + law). ``on_a_cliff`` says policyengine-us gives the household a cliff gap, + so the case checks a nonzero gap. + """ people: tuple[dict[str, float], ...] + policy: dict[str, dict[str, float]] | None + on_a_cliff: bool RETIREE_WITH_SOCIAL_SECURITY = OneHousehold( @@ -68,14 +81,20 @@ class OneHousehold(NamedTuple): "employment_income": 15_000.0, "social_security_retirement": 24_000.0, }, - ) + ), + policy=None, + on_a_cliff=False, ) -PARENT_OF_TWO_ON_A_CLIFF = OneHousehold( +PARENT_OF_TWO_ON_A_CLIFF_UNDER_A_REFORM = OneHousehold( people=( {"age": 30, "employment_income": 50_000.0}, {"age": 3}, {"age": 6}, - ) + ), + policy={ + "gov.irs.credits.ctc.amount.base[0].amount": {"2026-01-01.2100-12-31": 3_000} + }, + on_a_cliff=True, ) @@ -91,7 +110,10 @@ def cliff_output_plan() -> Stage12OutputPlan: "household", [ pytest.param(RETIREE_WITH_SOCIAL_SECURITY, id="retiree-with-social-security"), - pytest.param(PARENT_OF_TWO_ON_A_CLIFF, id="parent-of-two-on-a-cliff"), + pytest.param( + PARENT_OF_TWO_ON_A_CLIFF_UNDER_A_REFORM, + id="parent-of-two-on-a-cliff-under-a-reform", + ), ], ) def test_a_cliff_calculation_gives_policyengine_us_cliffs_for_a_dataset_household( @@ -100,6 +122,11 @@ def test_a_cliff_calculation_gives_policyengine_us_cliffs_for_a_dataset_househol calculated = _stage12_cliff_totals(household, cliff_output_plan) expected = _policyengine_us_cliff_totals(household) + if household.on_a_cliff: + assert expected.cliff_gap > 0, ( + "policyengine-us no longer places this household on a cliff; " + "choose one it does, so the case still checks a nonzero gap" + ) assert calculated.cliff_gap == pytest.approx(expected.cliff_gap, abs=0.01) assert calculated.cliff_share == pytest.approx(expected.cliff_share) @@ -111,7 +138,7 @@ def _stage12_cliff_totals( simulation = Simulation( dataset=_one_household_dataset(household), tax_benefit_model_version=_country_module("us").model, - policy=None, + policy=normalise_policy(household.policy), ) apply_output_plan(simulation, output_plan) simulation.run() @@ -124,7 +151,13 @@ def _stage12_cliff_totals( def _policyengine_us_cliff_totals(household: OneHousehold) -> CliffTotals: """Calculate the household's cliffs in policyengine-us, from a situation.""" names = [f"person_{index}" for index in range(len(household.people))] + reform = ( + None + if household.policy is None + else Reform.from_dict(household.policy, country_id="us") + ) simulation = PolicyEngineUSSimulation( + reform=reform, situation={ "people": { name: {variable: {YEAR: value} for variable, value in inputs.items()} @@ -146,7 +179,7 @@ def _policyengine_us_cliff_totals(household: OneHousehold) -> CliffTotals: "county_fips": {YEAR: WAKE_COUNTY_FIPS}, } }, - } + }, ) adults = float(simulation.calculate("is_adult", YEAR).sum()) return CliffTotals( From 191ec662b9fe52ddec3cffa873d2636b0f4acacd Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Wed, 2 Dec 2026 00:29:57 +0400 Subject: [PATCH 4/7] Correct when API v2 moves to 6.20.5 in the changelog fragment Review round 1. API v2's requests name no .py version: they run on the v2 default worker, which this deployment moves, and need API v1's catalog for that version, which API v1 publishes only when it deploys it. The fragment now says API v2 refuses new calculations with unknown_catalog_version until then, gives the example's place and year, and says labor-supply responses change too and stored results are not recalculated. Co-Authored-By: Claude Opus 5.5 --- changelog.d/update-policyengine-6.20.5.changed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/update-policyengine-6.20.5.changed.md b/changelog.d/update-policyengine-6.20.5.changed.md index 7612642d7..f5197be9c 100644 --- a/changelog.d/update-policyengine-6.20.5.changed.md +++ b/changelog.d/update-policyengine-6.20.5.changed.md @@ -1 +1 @@ -Updated policyengine.py from 6.20.4 to 6.20.5 in the simulation runtime. 6.20.5 lists every column it stores from a US dataset in the simulation's `input_variables`. policyengine-us's `marginal_tax_rate` recalculates each household's net income in copies of the simulation that keep only those inputs, so until now the copies lost each household's age, location, Social Security and other dataset inputs, and US cliff gaps and cliff shares counted the income they lost as cliffs: a retiree with $15,000 of earnings and $24,000 of Social Security got a cliff gap of $22,644.95 instead of $0. API v1 sends its own .py version with each request, so its reports, and API v2's, move to 6.20.5 only when API v1 raises its own pin. +Updated policyengine.py from 6.20.4 to 6.20.5 in the simulation runtime. 6.20.5 lists every column it stores from a US dataset in the simulation's `input_variables`. policyengine-us's `marginal_tax_rate` recalculates each household's net income in copies of the simulation that keep only those inputs, so until now the copies lost each household's age, location, Social Security and other dataset inputs, and US cliff gaps and cliff shares counted the income they lost as cliffs: a retiree in Wake County, North Carolina, with $15,000 of earnings and $24,000 of Social Security in 2026 got a cliff gap of $22,644.95 instead of $0. US labor-supply responses, which read the same marginal tax rates, change too. Results already stored for 6.20.4 are not recalculated. API v2's reports and household calculations run on the version this deployment makes the v2 default, but need API v1's catalog for that version, which API v1 publishes when it deploys 6.20.5: until then API v2 refuses them with `unknown_catalog_version`. API v1 sends its own .py version with each request, so its reports move to 6.20.5 when API v1 raises its own pin. From 6587038dc931585818d92b177008221494cc2f76 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Wed, 2 Dec 2026 00:46:19 +0400 Subject: [PATCH 5/7] Compare the Child Tax Credit, so a dropped reform can't pass Review round 2. policyengine-us gives the parent the same cliff gap with and without the raised credit, so the cliff comparison alone would pass if the policy never reached .py. The test now also compares the tax unit's ctc, a column the cliff plan already stores, and the docstring says every compared value comes from .py's reform simulation. Co-Authored-By: Claude Opus 5.5 --- .../test_stage12_cliff_dataset_inputs.py | 55 +++++++++++++------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py b/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py index 77d25a964..c80f5783c 100644 --- a/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py +++ b/projects/policyengine-simulation-executor/tests/test_stage12_cliff_dataset_inputs.py @@ -15,12 +15,13 @@ expect the cliff gap and share that policyengine-us calculates for the same household and policy given as a situation, whose inputs it lists at construction. Each household lives in Wake County, North Carolina, in 2026. -A retiree under current law covers a run with no policy, which .py builds once -from the dataset. A parent of two, whom policyengine-us places on a cliff, -runs under a raised Child Tax Credit, which .py builds twice from the dataset -(the reform and its baseline). On .py 6.20.4 (policyengine-us 2.2.2) the -retiree gets a gap of $22,644.95 instead of $0, and the parent $6,824.68 -instead of $460.95. +A retiree under current law covers a run with no policy. A parent of two, whom +policyengine-us places on a cliff, runs under a raised Child Tax Credit: .py +then builds a reform simulation and a baseline simulation beside it from the +dataset, and every compared value comes from the reform simulation, whose tax +unit's Child Tax Credit is compared too, to show the policy took effect. On +.py 6.20.4 (policyengine-us 2.2.2) the retiree gets a gap of $22,644.95 +instead of $0, and the parent $6,824.68 instead of $460.95. The worker calls ``ensure()``, which adds loading and saving stored outputs around the same ``run()``; these tests call ``run()``, so nothing is read from @@ -98,6 +99,13 @@ class OneHousehold(NamedTuple): ) +class HouseholdResults(NamedTuple): + """A household's cliff totals, and its tax unit's Child Tax Credit.""" + + cliffs: CliffTotals + child_tax_credit: float + + @pytest.fixture(scope="module") def cliff_output_plan() -> Stage12OutputPlan: """Return the columns a US cliff calculation stores, as the worker plans them.""" @@ -119,21 +127,26 @@ def cliff_output_plan() -> Stage12OutputPlan: def test_a_cliff_calculation_gives_policyengine_us_cliffs_for_a_dataset_household( household: OneHousehold, cliff_output_plan: Stage12OutputPlan ) -> None: - calculated = _stage12_cliff_totals(household, cliff_output_plan) + calculated = _stage12_results(household, cliff_output_plan) - expected = _policyengine_us_cliff_totals(household) + expected = _policyengine_us_results(household) if household.on_a_cliff: - assert expected.cliff_gap > 0, ( + assert expected.cliffs.cliff_gap > 0, ( "policyengine-us no longer places this household on a cliff; " "choose one it does, so the case still checks a nonzero gap" ) - assert calculated.cliff_gap == pytest.approx(expected.cliff_gap, abs=0.01) - assert calculated.cliff_share == pytest.approx(expected.cliff_share) + assert calculated.child_tax_credit == pytest.approx( + expected.child_tax_credit, abs=0.01 + ) + assert calculated.cliffs.cliff_gap == pytest.approx( + expected.cliffs.cliff_gap, abs=0.01 + ) + assert calculated.cliffs.cliff_share == pytest.approx(expected.cliffs.cliff_share) -def _stage12_cliff_totals( +def _stage12_results( household: OneHousehold, output_plan: Stage12OutputPlan -) -> CliffTotals: +) -> HouseholdResults: """Calculate the household's cliffs as a Stage 12 cliff worker does.""" simulation = Simulation( dataset=_one_household_dataset(household), @@ -145,10 +158,13 @@ def _stage12_cliff_totals( entity_data = simulation.output_dataset.data.entity_data frames = {entity: pd.DataFrame(frame) for entity, frame in entity_data.items()} validate_output_frames(frames, output_plan) - return cliff_totals_from_frames(frames, output_plan) + return HouseholdResults( + cliffs=cliff_totals_from_frames(frames, output_plan), + child_tax_credit=float(frames["tax_unit"]["ctc"].sum()), + ) -def _policyengine_us_cliff_totals(household: OneHousehold) -> CliffTotals: +def _policyengine_us_results(household: OneHousehold) -> HouseholdResults: """Calculate the household's cliffs in policyengine-us, from a situation.""" names = [f"person_{index}" for index in range(len(household.people))] reform = ( @@ -182,9 +198,12 @@ def _policyengine_us_cliff_totals(household: OneHousehold) -> CliffTotals: }, ) adults = float(simulation.calculate("is_adult", YEAR).sum()) - return CliffTotals( - cliff_gap=float(simulation.calculate("cliff_gap", YEAR).sum()), - cliff_share=float(simulation.calculate("is_on_cliff", YEAR).sum()) / adults, + return HouseholdResults( + cliffs=CliffTotals( + cliff_gap=float(simulation.calculate("cliff_gap", YEAR).sum()), + cliff_share=float(simulation.calculate("is_on_cliff", YEAR).sum()) / adults, + ), + child_tax_credit=float(simulation.calculate("ctc", YEAR).sum()), ) From 00d3589b72f2d33fbf047138015d9db5dc87e2d7 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Wed, 2 Dec 2026 00:46:19 +0400 Subject: [PATCH 6/7] Say which API v2 requests are refused, and hedge the response wording Review round 2. The fragment now names new reports, re-runs and household calculations as what API v2 refuses until API v1 publishes the 6.20.5 catalog, and says labor-supply and capital-gains responses may change, since neither has been measured with the fix. Co-Authored-By: Claude Opus 5.5 --- changelog.d/update-policyengine-6.20.5.changed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/update-policyengine-6.20.5.changed.md b/changelog.d/update-policyengine-6.20.5.changed.md index f5197be9c..51e6a3342 100644 --- a/changelog.d/update-policyengine-6.20.5.changed.md +++ b/changelog.d/update-policyengine-6.20.5.changed.md @@ -1 +1 @@ -Updated policyengine.py from 6.20.4 to 6.20.5 in the simulation runtime. 6.20.5 lists every column it stores from a US dataset in the simulation's `input_variables`. policyengine-us's `marginal_tax_rate` recalculates each household's net income in copies of the simulation that keep only those inputs, so until now the copies lost each household's age, location, Social Security and other dataset inputs, and US cliff gaps and cliff shares counted the income they lost as cliffs: a retiree in Wake County, North Carolina, with $15,000 of earnings and $24,000 of Social Security in 2026 got a cliff gap of $22,644.95 instead of $0. US labor-supply responses, which read the same marginal tax rates, change too. Results already stored for 6.20.4 are not recalculated. API v2's reports and household calculations run on the version this deployment makes the v2 default, but need API v1's catalog for that version, which API v1 publishes when it deploys 6.20.5: until then API v2 refuses them with `unknown_catalog_version`. API v1 sends its own .py version with each request, so its reports move to 6.20.5 when API v1 raises its own pin. +Updated policyengine.py from 6.20.4 to 6.20.5 in the simulation runtime. 6.20.5 lists every column it stores from a US dataset in the simulation's `input_variables`. policyengine-us's `marginal_tax_rate` recalculates each household's net income in copies of the simulation that keep only those inputs, so until now the copies lost each household's age, location, Social Security and other dataset inputs, and US cliff gaps and cliff shares counted the income they lost as cliffs: a retiree in Wake County, North Carolina, with $15,000 of earnings and $24,000 of Social Security in 2026 got a cliff gap of $22,644.95 instead of $0. US labor-supply and capital-gains responses, whose measurements use the same kind of copies, may change too. Results already stored for 6.20.4 are not recalculated. API v2's new reports, re-runs and household calculations run on the version this deployment makes the v2 default, but need API v1's catalog for that version, which API v1 publishes when it deploys 6.20.5: until then API v2 refuses them with `unknown_catalog_version`. API v1 sends its own .py version with each request, so its reports move to 6.20.5 when API v1 raises its own pin. From 9e37e8bdae9b3c801cf957d0935c08e3fc1cd6fd Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 3 Dec 2026 00:50:37 +0400 Subject: [PATCH 7/7] Run .py 6.20.5 in the simulation service Both policyengine[models] pins in the executor (its dependencies and the modal-simulation-image group) and uv.lock move from 6.20.4 to 6.20.5, which lists a US dataset's stored columns in input_variables (PolicyEngine/policyengine.py#783). Its bundle changes only version labels: policyengine-core, policyengine-us, policyengine-uk and the data releases are unchanged. The Stage 12 cliff test now gives policyengine-us's cliff gap and share for both households. Co-Authored-By: Claude Opus 5.5 --- .../policyengine-simulation-executor/pyproject.toml | 4 ++-- projects/policyengine-simulation-executor/uv.lock | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/policyengine-simulation-executor/pyproject.toml b/projects/policyengine-simulation-executor/pyproject.toml index c67e88502..e2328e37e 100644 --- a/projects/policyengine-simulation-executor/pyproject.toml +++ b/projects/policyengine-simulation-executor/pyproject.toml @@ -24,7 +24,7 @@ dependencies = [ "policyengine-stage12-persistence", # PolicyEngine.py's models extra is the only selector for core, country # models, and the SPM calculator. Do not duplicate those versions here. - "policyengine[models]==6.20.4", + "policyengine[models]==6.20.5", "tables>=3.10.2", # 1.6.4 is the first release whose containers reload Secret values when # they restore from a memory snapshot. Every app deployed or run from this @@ -58,7 +58,7 @@ packages = ["src/policyengine_simulation_executor"] # certified datasets and writes their receipt. [dependency-groups] modal-simulation-image = [ - "policyengine[models]==6.20.4", + "policyengine[models]==6.20.5", "fastapi>=0.115.0", "tables>=3.10.2", "policyengine-observability[fastapi,google,otlp-grpc]>=3.0.7,<4", diff --git a/projects/policyengine-simulation-executor/uv.lock b/projects/policyengine-simulation-executor/uv.lock index c8be4780b..b4e1b31d2 100644 --- a/projects/policyengine-simulation-executor/uv.lock +++ b/projects/policyengine-simulation-executor/uv.lock @@ -1769,7 +1769,7 @@ wheels = [ [[package]] name = "policyengine" -version = "6.20.4" +version = "6.20.5" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "h5py" }, @@ -1781,9 +1781,9 @@ dependencies = [ { name = "pydantic" }, { name = "requests" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/32/77/e2970d5839f497d6fefd06aeef99774859ca2f30bb5ee1691dfb458a7e2c/policyengine-6.20.4.tar.gz", hash = "sha256:4f253587872230fd55e8c045622ccd913ada304c1ead9b60dbc33cf4315685cf", size = 1868173, upload-time = "2026-12-01T01:43:30.923Z" } +sdist = { url = "https://files.pythonhosted.org/packages/c3/25/06d21a495fdb08d5ca28c2fce7a3c02fa054a65647d3a64f5d882261590c/policyengine-6.20.5.tar.gz", hash = "sha256:9ae71e19ba440bedede2e0b61b42a64cb969749df808dba50c28ef14874a441f", size = 1871654, upload-time = "2026-12-02T20:46:20.663Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/fc/92/02d046bf927873476ebf3e54e3efd23acd7270b221bca00d972f69086312/policyengine-6.20.4-py3-none-any.whl", hash = "sha256:0b93ec55feab0edfde61dcf27ecb81c68e1f7a271bd328a0ddf0e92f54933301", size = 775042, upload-time = "2026-12-01T01:43:28.788Z" }, + { url = "https://files.pythonhosted.org/packages/53/a0/6dcb72b7925453eeb322d340f9c5de4a5ffbfd0b711c12f57cb757ed0193/policyengine-6.20.5-py3-none-any.whl", hash = "sha256:ed35016f2bc62a6176e2da3c8ad34dd6f386b424369fc71a9ea3d05e387cfc54", size = 775369, upload-time = "2026-12-02T20:46:18.59Z" }, ] [package.optional-dependencies] @@ -1982,7 +1982,7 @@ requires-dist = [ { name = "openapi-python-client", marker = "extra == 'build'", specifier = ">=0.21.6" }, { name = "opentelemetry-instrumentation-fastapi", specifier = ">=0.65b0,<0.66" }, { name = "opentelemetry-instrumentation-sqlalchemy", specifier = ">=0.65b0,<0.66" }, - { name = "policyengine", extras = ["models"], specifier = "==6.20.4" }, + { name = "policyengine", extras = ["models"], specifier = "==6.20.5" }, { name = "policyengine-fastapi", editable = "../../libs/policyengine-fastapi" }, { name = "policyengine-observability", extras = ["fastapi", "google", "otlp-grpc"], specifier = ">=3.0.7,<4" }, { name = "policyengine-simulation-contract", extras = ["modal"], editable = "../../libs/policyengine-simulation-contract" }, @@ -2012,7 +2012,7 @@ modal-simulation-image = [ { name = "fastapi", specifier = ">=0.115.0" }, { name = "google-cloud-storage", specifier = ">=2" }, { name = "huggingface-hub", specifier = ">=1,<2" }, - { name = "policyengine", extras = ["models"], specifier = "==6.20.4" }, + { name = "policyengine", extras = ["models"], specifier = "==6.20.5" }, { name = "policyengine-observability", extras = ["fastapi", "google", "otlp-grpc"], specifier = ">=3.0.7,<4" }, { name = "psycopg", extras = ["binary"], specifier = ">=3.2,<4" }, { name = "pyarrow", specifier = ">=20,<24" },