Repository navigation
Add a readiness lookup: calibration and scorecard evidence for a reform in a state - #242
Conversation
…rm in a state scripts/readiness_lookup.py answers, without a microsimulation, whether the data is good enough to score a reform in a state. It reaches model variables from the reform's parameter paths through App v3's traced dependency map, matches them to the state's calibration targets in the Microcosm release (ACS local-area by default), flags the inputs and totals no target measures, and lists the nearest scorecard claims with their ratios. --all-kinds runs every bill kind in scripts/data/readiness_kinds.yaml for a list of states and writes a gap list with proposed owners (Teamverse p304). Tests run on saved slices of the live sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at 8011dbc
This PR adds scripts/readiness_lookup.py, a lookup that tells, without a microsimulation, how well the data supports a reform in a state. It traces the reform's parameter paths through App v3's dependency map, matches the variables to the state's calibration targets in the ACS local-area release, and lists comparable scorecard claims. --all-kinds writes a gap list with owners. Of the 4,114 added lines, 2,716 (66%) are test fixtures cut from live sources, 170 are the hand-written kinds file, 993 are code and 235 are tests. The PR stands alone on main (#240 is merged). It shares no files with #239, #241, #243, #244 or policyengine-app-v2#1646, and it does not need them. It reads parameterDependencies.json from the app-v2 main branch, which exists today.
The structure is clear and the tests run offline. Two output problems can mislead the people who act on the gap list.
Verdict: REQUEST_CHANGES
CRITICAL
None.
SHOULD ADDRESS
1. A target group mixes return counts and dollar totals, so the "Gross capital gains" miss is a count miss, not a dollar miss.
scripts/readiness_lookup.py:436-448 groups targets by variable_label only. The dashboard gives each target a measure field (count or total). The two measures go into one group and one worst error.
- Case: Georgia.
net_capital_gains_returns(measurecount) misses by 26.8%.net_capital_gains_amount(measuretotal) fits within 0.2%. The table shows "Gross capital gains, worst 27%", and the PR description says "capital gains miss by 27%". - Across all 51 states in the release, the capital gains return count misses by more than 10% in every state (median 31%). The dollar total misses by more than 10% in no state. So the "Gross capital gains, 23 states" gap row is about the number of returns with gains, not the amount of gains. That changes what a retirement-exclusion or rate-cut owner must fix.
- The same mix is in other rows. For example, "Medical expense deduction" has misses in both measures.
- Fix: group by
(variable_label, measure), or show the measure in the label (for example "Gross capital gains (returns)"). Carry the measure into the gap subject. Add a test that the Georgia count and total are separate rows. Correct the description text.
2. A reform whose paths match no kind and no traced reader gives an empty report with no warning.
scripts/readiness_lookup.py:337-342 and :798-802. When kinds_for_paths finds no kind and readers_of_path finds no reader, readers is empty, the walks reach nothing, and the result has 0 target groups, 0 untargeted items and 0 gaps. The markdown says that "the kind's fallback variables are used", but there are none.
- Case:
{"gov.contrib.states.ct.refundable_ctc.in_effect": {...}}for CT. The tracker uses this path today. The output has no kind, no targets and no gaps. A reader can take this as "no gaps". - Case: a mistyped or nonexistent path, for example
gov.states.ks.tax.income.rates.single[0].rate(Kansas usesrates.other). The result is the same: a fallback to nothing, or to the kind's fallback variables with the message "The state may not have this program in the model". The model has the program; the path is wrong. - Fix: when no reader and no kind are found, stop with a clear message, or mark the result as "not resolved" and print the unmatched paths. In the markdown, tell "the trace did not record this path" apart from "no kind matched". Add a test for each case.
3. The income_tax_rate patterns miss Indiana, so the lookup says Indiana may not have an income tax.
scripts/data/readiness_kinds.yaml:24-27. Indiana's rate is gov.states.in.tax.income.agi_rate. No pattern (rate, rates*, main.*) matches it. On the live dependency map, income_tax_rate is untraced in AK, FL, IN, NV, NH, SD, TN, TX, WA and WY. Indiana is the only one of these with a wage income tax.
- Fix: add
"gov.states.{st}.tax.income.agi_rate", or a broader rate pattern. Add a check that every state with a modeled income tax resolvesincome_tax_rateas traced.
SUGGESTION
4. The gap list counts gaps for kinds that a state does not have. scripts/readiness_lookup.py:589-679 and :959-963. --all-kinds runs every kind for every state and records the gaps even when the kind falls back (traced is false). For example, the renter's credit is traced in only 9 states, but "rent" is an uncalibrated input in "23 states". The state_income_tax outcome gap also appears for a no-income-tax state such as Texas. Each gap is true as a data fact, but the state count overstates the reach. Mark untraced gaps, or skip them in the state count.
5. Two of the four sources are not pinned, and the output does not record their versions. scripts/readiness_lookup.py:71-78 and :934-938. The dependency map and the scorecard feed come from main of their repositories. The national release is the dashboard's default. The local release is pinned, which is good. The JSON keeps the dependency map's model block, but it does not keep the national release id, the dependency map's generatedAt, or a scorecard date. A gap list from a later day can differ with no sign of why. Add these to the payload and the markdown header. As an option, accept a commit SHA for the two GitHub sources.
6. The local release id is a second copy of the scoring dataset. scripts/readiness_lookup.py:61-63 repeats DATASETS["acs-local-766b7c7"] and DEFAULT_STATE_DATASET from scripts/compute_impacts.py:175-198. When scoring moves to a new release, the lookup will keep the old one. Move the release id to a small shared module that both scripts import, or add a test that the two agree.
7. The fixtures have no script that makes them. The 2,716 fixture lines match the live sources today (I compared all 89 local targets, the dependency map readers and the scorecard rows). But the next person cannot cut a new slice in the same way. Add a small --save-fixtures option or a script, or describe the cut in the test docstring.
8. Small items.
--statewith--all-kindsis ignored with no message (:949-957). Reject it or use it as--states.load_targetsloops forever if the API returnshas_next: truewithreturned: 0(:216-219). Stop when a page is empty._roletakes the role of the first variable in a group by alphabetical order (:456). A group with more than one variable can get the wrong role.- The gap table in the description has columns (Detail, no Kinds, no Evidence) and text ("worst error") that differ from what
gaps_markdownprints ("worst |error|"). Paste the real output, or change the code to match. - No CI job runs the Python tests in
scripts/. This is true for the repository in general, not only for this PR.
What I checked
- Read the description, the full diff, the kinds file and the tests. There are no comments or reviews yet.
pytest scripts/test_readiness_lookup.py: 14 passed, offline.ruff checkandruff format --checkon the two new Python files: clean (ruff 0.14.14).npm run build: passes (this PR changes no front-end code).- Live run of
--state GA --kind retirement_exclusion: the output matches the description. - Fixtures against live sources: all 89 local targets have the same values. The dependency map readers in the fixture are the same as live (
generatedAt2026-10-15, policyengine-us 2.2.1). The scorecard rows have the same values. The national release ispopulace-us-2024-spm-20260915in both. - Spot checks: the Georgia capital gains rows (count 26.8%, total 0.2%), which gave item 1. The NY rent and royalty amount (relative error 72.03, that is 7,203%), which matches the description.
- Edge cases on live data: an unknown path, an empty reform, a federal CTC path, two
gov.contribpaths, Texas and Washington with tax kinds, an unknown kind (gives a clearValueError), and which states each kind traces in. - Dependencies: the files of #239, #241, #243, #244 and policyengine-app-v2#1646. There is no overlap.
…cord sources Addresses the review of #242: - Target groups are keyed by variable and measure, so a return count and a dollar total are separate rows ("Gross capital gains (returns)" misses by 27% in Georgia; "(amount)" fits within 0.2%). The measure is in the gap subject. - A reform whose paths the trace never recorded is "not resolved" (exit 1) and lists each path: no kind matched it, or the trace records other parameters of its kind in the state (likely mistyped, with examples), or none (the kind's fallback variables stand in). Partly traced reforms list the unrecorded paths. - income_tax_rate matches Indiana's agi_rate; a test checks that all 41 states and DC with a wage income tax resolve it as traced. - Gaps carry a traced flag; a state counts toward a calibration gap only when the kind is traced there ("+N untraced" in the table). - Results and the gap list record the national release id, the dependency map's ref and generatedAt, and the scorecard feed's ref and build date. --app-ref and --scorecard-ref take a commit SHA. - A test checks LOCAL_AREA_RELEASE against compute_impacts.py's default state dataset (read with ast, not imported). - --save-fixtures cuts the test slices (cut_fixtures says what each keeps); the fixtures are regenerated with it and a test checks they still match. - --state with --all-kinds (and --states without it) is an error; target paging stops on an empty page; a group's role is its most direct variable's; table cells say "worst abs. error" and escape pipes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, Pavel. Fixed in 1c1b333; line numbers refer to that commit.
The description is replaced: the Georgia and 23-state output in it is what the lookup printed today. #246, which is stacked on this branch, takes these changes next. |
After #242's review, the readiness lookup marks a reform whose paths the dependency trace never recorded as "not resolved" (or "partly traced"). The comparison step's markdown for the review PR now says so, so an empty check doesn't read as no gaps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at 1c1b333
This PR adds scripts/readiness_lookup.py, a lookup that tells, without a microsimulation, how well the data supports a reform in a state. It traces the reform's parameter paths through App v3's dependency map, matches the variables to the state's calibration targets, and lists comparable scorecard claims. --all-kinds writes a gap list with owners. Commit 1c1b333 answers the review at 8011dbc. It splits targets by measure, reports unresolved reform paths, adds Indiana's rate path, marks untraced gaps, records source versions, and adds a fixture cutter and 17 tests.
All three SHOULD ADDRESS items are fixed. I checked each fix on live data. Two small items remain, both suggestions.
Verdict: APPROVE
Earlier items
| # | Item | Status |
|---|---|---|
| 1 | Count and dollar targets in one group | Fixed |
| 2 | Empty report for an unresolved reform | Fixed |
| 3 | Indiana income tax rate not traced | Fixed |
| 4 | Gaps counted for kinds a state does not have | Fixed, with one remaining case (new item A) |
| 5 | Sources not pinned or recorded | Fixed |
| 6 | Second copy of the local release id | Fixed |
| 7 | No script for the fixtures | Fixed |
| 8 | Small items (8a to 8d) | Fixed; 8e (CI) stays out of scope, as agreed |
- Fixed. Groups now use
(variable_label, measure)(readiness_lookup.py:551-566). Live Georgia retirement run: "Gross capital gains (returns)" 27% and "Gross capital gains (amount)" 0.2% are two rows. In the gap list, the subject is "Gross capital gains (returns)". I checked all 4,765 targets in the local release: no two (label, measure) pairs give the same printed label. The description text is corrected. - Fixed.
resolvenow gives a status (:374-418), and the CLI exits 1 with a line on stderr. Live runs:- CT
gov.contrib.states.ct.refundable_ctc.in_effect: "not resolved", exit 1, and a note thatgov.contribpaths are recorded only when a baseline formula reads them. - KS
rates.single[0].rate: "not resolved", exit 1. The output lists the 4 KS rate parameters that the trace records and says the path may be mistyped. - KS
rates.other[0].rate: traced, exit 0, a full table.
- CT
- Fixed.
agi_rateis inincome_tax_rate(readiness_kinds.yaml:30). On the live map,income_tax_ratefalls back only in AK, FL, NV, NH, SD, TN, TX, WA and WY. Indiana resolves togov.states.in.tax.income.agi_ratewith readersin_agi_taxandin_withheld_income_tax. The new test checks the 41 states and DC. - Fixed, with one remaining case. Untraced gaps now show as "+N untraced" and do not count toward the reach. In a seven-state run (GA, TX, IN, NY, CO, KS, WA), rent shows "IN, NY, TX (+4 untraced)" and the ACA PTC rows show "none (+1 untraced)". The Texas example from the earlier review still counts, by a different route. See item A.
- Fixed. The payload and each markdown header record both release ids, the map's ref,
generatedAtand model, and the feed's ref and build date.--app-refand--scorecard-reftake a branch or a full commit SHA. A bad SHA fails with the URL and HTTP 404. - Fixed. A test reads
STATE_DATASETS[DEFAULT_STATE_DATASET]fromcompute_impacts.pywithastand compares it toLOCAL_AREA_RELEASE. - Fixed.
--save-fixtures DIRwrites the four slices. I cut them again from today's live sources: all four files are byte-for-byte equal to the committed fixtures. - Fixed.
--statewith--all-kindsand--stateswithout it are now errors (I ran both).load_targetsstops on an empty page._roletakes the most direct role in a group. The output prints "worst abs. error", and table cells escape|.
CRITICAL
None.
SHOULD ADDRESS
None.
SUGGESTION
A. A traced kind still adds its outcome gap in a state where the outcome does not apply.
scripts/readiness_lookup.py:714-728 sets traced for each result from the kind's trace. The kind's outcomes come from the kinds file and do not depend on the state.
- Case: Texas.
property_tax_homesteadis traced in TX through the school district homestead exemption. That trace reaches 2 variables, and neither is an income tax variable. But the kind listsstate_income_taxas its outcome ("a refundable credit lowers net collections"). So the "untargeted outcome: state_income_tax" row counts TX as a traced state. In the seven-state run, the row shows "7 states" and includes TX and WA. - WA is a weaker case: its traced
eitc(Working Families Tax Credit) does reachhousehold_state_income_tax. - Fix: count an outcome gap only where the traced readers reach an income tax variable, or only where
income_tax_rateis traced in the state. Another option: giveproperty_tax_homesteadper-state outcomes. Add a TX test.
B. An empty reform dict gives a "not resolved" report with no path.
scripts/readiness_lookup.py:1472-1478. With {}, stderr says "not resolved: the trace recorded no reader for " and the markdown lists no path. Reject an empty reform dict with a clear message, for example "the reform dict has no parameter paths".
What I checked
- Read the author's reply, the diff 8011dbc..1c1b333 (code, kinds file, tests) and the new description. The branch contains the current
main. pytest scripts/test_readiness_lookup.py: 31 passed, offline.pytest scripts/test_compute_impacts_datasets.py: 29 passed.ruff checkandruff format --checkon the two Python files: clean (ruff 0.14.14).npm run build: passes.- Live runs on fresh downloads: Georgia retirement exclusion; CT contrib, KS mistyped, KS correct and empty reform dicts (with exit codes);
income_tax_ratein all 50 states and DC;--all-kindsfor GA, TX, IN, NY, CO, KS and WA; the two argument errors; a nonexistent--app-refSHA;--save-fixturescompared to the committed fixtures. - Label check across all 4,765 local-release targets for clashes between measures.
- Callers: only the PR's own files use the lookup on this branch. The stacked PR that uses it takes these changes next, as the author says.
readiness_lookup reports an empty reform dict as "not resolved" with no path (Pavel's review of #242, suggestion B). calibration_check strips the _ keys, so a reform with only those reached lookup() empty. It now returns None before any download, as with --no-calibration, and says why on stderr. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Readiness lookup follow-ups from the #242 review: outcome gaps, empty reform dict
A lookup that says, without running a microsimulation, how well the data supports scoring a reform in a state. It covers Teamverse milestone p304 ("Baseline checked for each kind of bill") and will be the calibration and scorecard half of the comparison step when bills are scored through App v3 (p451).
What it does
scripts/readiness_lookup.pytakes a state and either a kind of bill or a reform dict (reform_impacts.reform_params), and reports two views:policyengine-app-v2app/src/data/flagship/parameterDependencies.json, used by its calibration panel). The variables that read a path, what they move downstream, and the inputs upstream are matched to the state's targets in the Microcosm release, which is ACS local-area by default (the release a state report runs on). Each target group, a variable in one measure (a count of returns or a dollar amount), gets its fit. The inputs and totals no target measures are flagged, with the national release's coverage beside them. No target in either release is held out, so the output says a close fit is expected by construction.scripts/data/readiness_kinds.yamladds what a trace can't say: each kind's parameter patterns, the key inputs that decide who a reform reaches (each with the reason), the totals a target could anchor, and the words that find comparable bills. There are 10 kinds: income tax rate, brackets, standard deduction and exemptions, EITC, CTC, retirement income exclusion, property tax and homestead credit, renter's credit, child and dependent care credit, and SNAP. A kind the trace never read for a state falls back to listed variables, and the output says so. A reform dict whose paths the trace never recorded is marked not resolved, and each path is listed with its cause: no kind matched it, or the trace records other parameters of its kind in the state, so the path is likely mistyped.--all-kindsruns every kind for a list of states, by default the states of the published bills (read from Supabase, read only). It writes a gap list: each uncalibrated input or total, each target that misses by more than 10%, and each comparable claim outside 0.75 to 1.25. Every gap has a proposed owner and an evidence link. A state counts toward a calibration gap only where the trace records the kind's parameters. Each result and gap list records the version of every source: the release ids, the dependency map's ref and generation date, and the scorecard feed's build date.How to run it
It needs
pyyamlonly. Downloads are cached for a day under~/.cache/policyengine-tracker/readiness(--refreshrefetches). The dependency map and the scorecard feed come frommainunless--app-refor--scorecard-refnames a commit.--all-kindswithout--statesneedsSUPABASE_URLandSUPABASE_KEYin the environment or the gitignored.env. An unresolved reform exits 1.Example: Georgia retirement income exclusion
Readiness: GA, Retirement income exclusion
Release
microcosm-us-2024-local/populace-us-2024-buildo-acs-local-766b7c7-20261017T030317Z: 85 state targets, 0 held out. Every target in this release was fitted, so a close fit is expected by construction: it shows these inputs are anchored, not that a reform's result is right.Sources: local release
microcosm-us-2024-local/populace-us-2024-buildo-acs-local-766b7c7-20261017T030317Z; national releasemicrocosm-us-2024-national/populace-us-2024-spm-20260915; dependency map at policyengine-app-v2main, generated 2026-10-15 on policyengine-us 2.2.1; scorecard feed at policyengine-scorecardmain, built 2026-11-26.Not targeted in this release:
state_income_tax(outcome): collections, the total an exclusion lowers. The national release has 1 state target(s) for it.age(key input): eligibility starts at an age threshold (62 or 65 in most states). The national release has 18 state target(s) for it.social_security(key input): total benefits, not only the federally taxable part.Taxable pensions, IRA distributions and taxable Social Security fit within 0.3% in both measures. Capital gains split by measure: the number of returns with gains misses by 27%, while the dollar amount fits within 0.2%. The ACS local-area release has no age targets, while the national release has 18 for Georgia, and it has no state income tax target. Colorado's retirement bill, the nearest comparable, is 1.32 times its fiscal note on ACS-local.
Baseline gaps across 23 states
Sources: local release
microcosm-us-2024-local/populace-us-2024-buildo-acs-local-766b7c7-20261017T030317Z; national releasemicrocosm-us-2024-national/populace-us-2024-spm-20260915; dependency map at policyengine-app-v2main, generated 2026-10-15 on policyengine-us 2.2.1; scorecard feed at policyengine-scorecardmain, built 2026-11-26.A state counts toward a calibration gap only when the trace records the kind's parameters there. "+N untraced" counts the states where every kind behind the gap fell back to its listed variables: the state may not have the program in the model.
This is
--all-kinds --states AL,CT,DC,GA,HI,ID,IL,KS,MI,MN,MS,NC,ND,NE,NJ,NY,OK,OR,RI,UT,VA,WI,WV, the 23 states with published bills on 2 December, run on 3 December: 35 gaps on the ACS local-area release.The calibration owner is Microcosm. The SNAP gaps go to the SNAP PRs (microcosm #1714, #1835); no target counts SNAP recipients, which p304 names. A comparable bill outside the band needs a diagnosis, since the cause can be the rules (policyengine-us) or the data (Microcosm).
The capital gains gap is about the number of returns: the return count misses by 17% to 36% in all 23 states, and the dollar total misses by more than 10% in none. Rent counts 14 states; in the other 9, neither the renter's credit nor the property tax credit is traced. Child care expenses count 11 states and total Social Security 16. Four target rows (Assigned ACA PTC in both measures, the North Carolina EITC total and the Utah medical expense return count) come only from kinds untraced in those states, so they count no state. One row needs a look at the target before it counts as a data gap: NY rent and royalty income misses by 7,203%, with a target of $40M against an estimate of $2.9B.
Checks
pytest scripts/test_readiness_lookup.py: 31 passed, with no network, on slices of the live sources that--save-fixturescut on 3 December. A test checks that the fixtures are still what it cuts.ruff checkandruff format --checkon the changed Python files.--all-kindsrun above, Indiana income tax rate, and two unresolved reform dicts (CTgov.contrib.states.ct.refundable_ctc.in_effect, and a Kansasrates.singlepath that does not exist).Not in this PR
/encode-billand the review PR (p451).app/scripts/build-parameter-dependency-map.pyin app-v2.scripts/; none runs today, for this file or the others.🤖 Generated with Claude Code