Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/modal-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ jobs:
run: uvx --from "modal==$MODAL_VERSION" --with "typer<0.16" --with "click<8.2" modal deploy --env main modal_app.py
# The smoke test uses only the standard library, so any Python runs it.
# It waits until this commit's containers answer each check.
# --no-config skips .python-version: its 3.11 is the local setup's, and
# under only-system uv won't download it on a runner that lacks it.
- name: Smoke-test the calculator
id: calculator
run: uv run --no-project scripts/smoke_test_api.py "$API_URL" --commit "$GITHUB_SHA"
run: uv run --no-project --no-config scripts/smoke_test_api.py "$API_URL" --commit "$GITHUB_SHA"
- name: Roll back to the previous version if the calculator fails
if: failure() && steps.calculator.outcome == 'failure'
run: uvx --from "modal==$MODAL_VERSION" --with "typer<0.16" --with "click<8.2" modal app rollback aca-calc-api --env main
# Calls the Anthropic API unless this household's answer is cached.
- name: Smoke-test AI explanations
run: uv run --no-project scripts/smoke_test_api.py "$API_URL" --commit "$GITHUB_SHA" --explain
run: uv run --no-project --no-config scripts/smoke_test_api.py "$API_URL" --commit "$GITHUB_SHA" --explain
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
1 change: 1 addition & 0 deletions changelog.d/bhp-coverage.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The local setup locks policyengine-us 2.138.2 and policyengine-core 3.36.0, the Modal image's versions, on Python 3.11 (`.python-version`, which the deploy's smoke tests skip to use the runner's Python), so `uv run` and the precompute scripts use the API's model. The Methodology tab notes the $1 differences from the model's unrounded share of income (policyengine-us#11060), and the exploratory uprating test is marked as an expected failure.
1 change: 1 addition & 0 deletions changelog.d/bhp-coverage.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The calculator API reports Basic Health Program eligibility (MinnesotaCare, New York's Essential Plan, OHP Bridge and the Healthy DC Plan), and the "Your household" cards and explanations name the program for the members it covers, in place of a Marketplace premium those members can't buy. With an answer from an API that doesn't report this coverage, the results instead name the state's program and say they don't include it. In New York, where the 2026 card has the Essential Plan and the 2027 card no program, the explanation says the 2026 card applies the 250% FPL limit to the whole year, though it fell to 200% on July 1, 2026. The full premium prices only members no program covers. A cent above 400% FPL no longer gets the credit and a cent below no longer loses it, where the model's float32 income can't hold the cent, and the cards report the credit's income to the cent. $0 of earnings gets cards. The payment chart breaks where the model prices no plan, its credit matches the cards' to the dollar, and its % FPL rounds down as the cards' does. The data check compares each example's benchmark premium and credit as well as its payment, and requires every Overview household. Where the model prices no plan for members aged 65 or older, the explanation says Medicare rules out the credit, and it names a Basic Health Program only for members aged 19 to 64 in answers that don't report the program.
2 changes: 1 addition & 1 deletion changelog.d/bhp-note-wording.fixed.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
In Minnesota, New York, Oregon and DC, the calculator's results name the state's Basic Health Program, which covers adults aged 19 to 64 with incomes above Medicaid's limit up to 200% FPL (250% in New York until June 30, 2026), and say the results don't include it yet. Where the model gives no credit because the program covers the household, the explanation names the program as the reason, but only for members aged 19 to 64; members aged 65 or older are told that Medicare rules out the credit. The explanation of Medicaid's work requirement says it applies to the expansion group and that the estimate assumes no exemption, and three explanations now name their year.
The explanation of Medicaid's work requirement says it applies to the expansion group and that the estimate assumes no exemption, and three explanations now name their year.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"streamlit>=1.28.0",
"policyengine-us>=1.459.0",
"policyengine-us>=2.138.2",
"numpy>=1.24.0",
"pandas>=2.0.0",
"plotly>=5.17.0",
Expand Down
34 changes: 26 additions & 8 deletions scripts/check_data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,16 @@ if (sweepAt >= 0 && pennsylvania) {
}
}

// 7. Each example's "Your household" cards, which the API calculated at its
// earnings, match the Overview's table, to the dollar a month.
// 7. The calculator offers the Overview's households, every one of them, and
// each example's "Your household" cards, which the API calculated at its
// earnings, match the Overview's table: the benchmark premium, the credit and
// the payment each to the dollar a month, so errors in two can't offset.
const calculatorKeys = data.calculator.examples.map((example) => example.key).sort();
const overviewKeys = Object.keys(overview).sort();
check(
calculatorKeys.join() === overviewKeys.join(),
`the calculator's examples (${calculatorKeys.join(", ")}) aren't the Overview's (${overviewKeys.join(", ")})`
);
for (const example of data.calculator.examples) {
const table = overview[example.key];
const answer = example.at_income;
Expand All @@ -127,12 +135,22 @@ for (const example of data.calculator.examples) {
[`hr1834_${year}`]: answer.ira,
};
for (const [scenario, card] of Object.entries(cards)) {
const value = card ? net(card.benchmark, card.credit) : NaN;
const expected = table.scenarios[scenario].net_premium / 12;
check(
Math.abs(value - expected) < 1,
`${example.key}, ${scenario}: the card pays $${value.toFixed(2)}/month, the Overview $${expected.toFixed(2)}`
);
const row = table.scenarios[scenario];
if (!card || !row) {
problems.push(`${example.key}, ${scenario}: ${card ? "the Overview" : "the card"} has no values`);
continue;
}
const pairs = [
["benchmark premium", card.benchmark, row.slcsp],
["credit", card.credit, row.ptc],
["payment", 12 * net(card.benchmark, card.credit), row.net_premium],
];
for (const [label, value, expected] of pairs) {
check(
Math.abs(value - expected) / 12 < 1,
`${example.key}, ${scenario}: the card's ${label} is $${(value / 12).toFixed(2)}/month, the Overview's $${(expected / 12).toFixed(2)}`
);
}
}
}

Expand Down
60 changes: 43 additions & 17 deletions src/aca_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
# Also part of every cache key: change it when this API's answers change for
# the same request and model version, so the caches drop the old ones.
# 2: the credit at exactly 400% FPL, and the credit's income on the axis.
ANSWER_VERSION = 2
# 3: Basic Health Program coverage, and the credit's income to the cent.
ANSWER_VERSION = 3

# Each scenario: the request flag that turns it on, the response field for its
# credits, and the reform that models it.
Expand Down Expand Up @@ -245,20 +246,31 @@ def scenario_simulation(situation: dict, create_reform) -> Simulation:
return Simulation(situation=situation, reform=create_reform())


def credit_at_400_percent(sim: Simulation, year: int, credit: np.ndarray) -> np.ndarray:
"""Current law's credit, with the tax units whose income is exactly 400% FPL
given theirs.
def credit_at_400_percent(
sim: Simulation, year: int, credit: np.ndarray, magi: np.ndarray | None = None
) -> np.ndarray:
"""Current law's credit, with the tax units the model reads as exactly at
400% FPL, whose income doesn't exceed it, given theirs.

A tax unit whose income "does not exceed 400 percent" of the poverty line
qualifies (26 U.S.C. 36B(c)(1)(A)), and Form 8962 Worksheet 2 decides
"more than" 400% on dollars. policyengine-us 2.138.2 makes exactly 400%
ineligible (draft fix: PolicyEngine/policyengine-us#10312), so there this
applies the model's own formula (aca_ptc_before_filing_gate and the filing
condition of files_return_for_aca_ptc). It changes nothing else: a dollar
above, income exceeds the limit.
qualifies (26 U.S.C. 36B(c)(1)(A)). policyengine-us 2.138.2 makes exactly
400% ineligible (draft fix: PolicyEngine/policyengine-us#10312), so there
this applies the model's own formula (aca_ptc_before_filing_gate and the
filing condition of files_return_for_aca_ptc). It changes nothing else: a
cent above, income exceeds the limit.

`magi` is the credit's income at full precision, where the caller has it.
The model's float32 values can't hold a cent at these incomes (above
$262,144 they move in steps of 3.125 cents), so a cent either side of the
limit reads as exactly at it: the model's income picks the tax units it
gives nothing at the limit, and the full-precision one decides which of
them qualify.
"""
magi = sim.calculate("aca_magi", period=year)
at_limit = magi == 4 * sim.calculate("aca_fpg", period=year)
model_magi = sim.calculate("aca_magi", period=year).astype(float)
if magi is None:
magi = model_magi
limit = 4 * sim.calculate("aca_fpg", period=year).astype(float)
at_limit = (model_magi >= limit) & (magi <= limit + 0.005)
if not at_limit.any():
return credit
benchmark = sim.calculate("aca_ptc_slcsp", period=year)
Expand Down Expand Up @@ -518,20 +530,34 @@ def run_at_income(data: AtIncomeRequest, year: int, enhanced: bool) -> ScenarioA
sim = Simulation(tax_benefit_system=enhanced_system(), situation=situation)
else:
sim = Simulation(situation=situation)
# The credit's income with the earnings exactly as asked: the model's
# float32 income drops cents at high incomes. The rest of it (Alaska's
# dividends) is whole dollars.
earnings = float(sim.calculate("employment_income", period=year)[0])
other_income = round(float(sim.calculate("aca_magi", period=year)[0]) - earnings)
magi = data.income + other_income
credit = sim.calculate("aca_ptc", period=year)
if not enhanced:
credit = credit_at_400_percent(sim, year, credit)
credit = credit_at_400_percent(sim, year, credit, np.array([magi]))
benchmark = float(sim.calculate("slcsp", map_to="household", period=year)[0])
medicaid = sim.calculate("is_medicaid_eligible", period=year)
chip = sim.calculate("is_chip_eligible", period=year)
barred = sim.calculate("is_medicaid_ineligible_due_to_work_requirement", period=year)
basic_health = sim.calculate("is_basic_health_program_eligible", period=year)
coverage = [
PersonCoverage(medicaid=bool(m), chip=bool(c), medicaid_work_requirement=bool(b))
for m, c, b in zip(medicaid, chip, barred)
PersonCoverage(
medicaid=bool(m),
chip=bool(c),
medicaid_work_requirement=bool(b),
basic_health_program=bool(h),
)
for m, c, b, h in zip(medicaid, chip, barred, basic_health)
]
# Only members no program covers can buy a Marketplace plan; Basic Health
# Program enrollees can't (42 U.S.C. 18051(e)).
uncovered = [
name for name, person in zip(situation["people"], coverage)
if not (person.medicaid or person.chip)
if not (person.medicaid or person.chip or person.basic_health_program)
]
full_premium = benchmark
if benchmark == 0 and uncovered:
Expand All @@ -541,7 +567,7 @@ def run_at_income(data: AtIncomeRequest, year: int, enhanced: bool) -> ScenarioA
benchmark=benchmark,
credit=float(credit[0]),
full_premium=full_premium,
magi=float(sim.calculate("aca_magi", period=year)[0]),
magi=magi,
fpl=float(sim.calculate("aca_fpg", period=year)[0]),
coverage=coverage,
)
Expand Down
19 changes: 15 additions & 4 deletions src/aca_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ class PersonCoverage(BaseModel):
medicaid_work_requirement: bool = Field(
description="Would be eligible for Medicaid but for its work requirement"
)
basic_health_program: bool = Field(
default=False,
description=(
"Eligible for the state's Basic Health Program (MinnesotaCare, New "
"York's Essential Plan, OHP Bridge or the Healthy DC Plan), which "
"rules out Marketplace enrollment (42 U.S.C. 18051(e))"
),
)


class ScenarioAtIncome(BaseModel):
Expand All @@ -190,12 +198,15 @@ class ScenarioAtIncome(BaseModel):
credit: float = Field(description="Premium tax credit")
full_premium: float = Field(
description=(
"Benchmark premium for every member without Medicaid or CHIP: the "
"benchmark, except in the coverage gap, where the model assumes no "
"one buys a plan and this is what one would cost without a credit"
"Benchmark premium for every member Medicaid, CHIP and the Basic "
"Health Program don't cover: the benchmark, except in the coverage "
"gap, where the model assumes no one buys a plan and this is what "
"one would cost without a credit"
)
)
magi: float = Field(description="The credit's income (aca_magi)")
magi: float = Field(
description="The credit's income (aca_magi), with the earnings exactly as asked"
)
fpl: float = Field(description="The poverty guideline the credit uses")
coverage: list[PersonCoverage] = Field(description="Each member's coverage, as in people")

Expand Down
4 changes: 4 additions & 0 deletions src/components/Calculator.css
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@
line-height: 1.6;
}

.impact-explanation p + p {
margin-top: var(--pe-space-sm);
}

.impact-placeholder {
text-align: center;
padding: var(--pe-space-2xl);
Expand Down
Loading