US targets: one declared nesting rule across national, state, district and county levels

Open
#1,760 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
json, python
Domain
data

Research direction

Start with microcosm.build.cross_grain, uk/cross_grain_declarations.json, and the US target code listed in the issue, especially us_runtime/fiscal_targets.py and the two local surface tools. First map the eight existing nesting mechanisms and their pinned outputs; Stage A is complete when one US declaration and a static test cover the measured quantity pairs, shared code handles the child rows, and pinned US outputs and UK targets remain unchanged. The issue leaves several family level and source choices undecided, so resolve those before implementing the declaration.

Written by the indexing model from the issue text.

Description

Problem" down)

Title: US targets: one declared nesting rule across national, state, district and county levels

Parent: #1728 (a sub-issue beside #1731).


Problem

A target for a small area must agree with the target of the area that contains it. Today the US code makes child rows from parent rows in eight places. Each place has its own arithmetic, its own tolerance and its own receipt. No declaration says, for a family, which level holds the level value and which levels hold shares.

#1731 lists the district families that can enter the fit. Without one rule, each new family adds one more mechanism.

This issue is about how a child row gets its value from its parent row. Which rows a build keeps is #1728 (work item 1, PR #1755). Which district families enter the fit is #1731.

Where rows nest today

Read at main 5df16cfd2.

In the compile (us_runtime/fiscal_targets.py and the shared package). Every build runs these.

# Relation Code The parent The children
1 National to state and district, capital gains _rebase_stale_soi_capital_gains_distributions The Table 1.4 national control Shares of the national total of their own family. A row with no control is dropped (#1035, #1038)
2 National to state, taxable interest _rebase_stale_soi_taxable_interest_distributions The latest Pub 1304 national value One national factor. The TY2022 state shares stay (#489)
3 State total to state AGI bands _rebase_soi_state_agi_bands The state all-returns row that binds Shares of the published band partition (#940). This is a partition inside one area
4 State to district, the district file Shared reconcile_ledger_target_hierarchy, declared in us/fiscal_target_references.json The district file's own state row Scaled to sum to the parent. A missing district fails the compile

In the local tools (tools/). Only the local build runs these.

# Relation Code The parent The children
5 State to district SOI (--soi-mode state_cd) state_cd_soi_surface in us_acs_local_cd_surface.py The Historic Table 2 state row. For six concepts that only the district file has, a sibling concept bridges the level District file shares. A state and concept whose ratio is more than 25% from the median across states is dropped
6 State to county SOI (--soi-mode state_county) state_county_soi_surface and split_state_rows in us_acs_local_county_surface.py The state row that exists County shares. One declared combined cell covers a county with no IRS row
7 County to state, ACS households acs_household_surface The sum of the county values. It is a new state target Counties divide it
8 State to county, population with_county_populations The state total from the ladder Ladder overlaps, scaled. The rounding residual goes to the largest county

The state and district population totals come from one 2020 ladder.

What differs between the eight:

  • Direction. In row 7 the children make the parent. In the others the parent holds the level.
  • Bounds and tolerances. Row 5 has a factor band (1.25) and two tolerances (1e-6 inside the district file, 1e-9 for the sum). Row 4 has no bound on its factor.
  • The state parent of a district row. In row 4 it is the district file's own state row. In row 5 it is the Historic Table 2 state row. So one district row has a different parent on different surfaces.
  • Receipts. Each mechanism writes its own metadata keys (hierarchy_*, state_cd_*, state_county_*).
  • Place. Rows 1 to 4 are in the package. Rows 5 to 8 are in tools/. PR #1755 moved the other target code of the tools to shared modules and left these four in place for this issue.
  • Two child sets. Districts and counties both divide a state, but they do not nest in each other. No mode holds both (#1731).

Where rows do not nest

  • Two national rows for one quantity. 14 SOI families bind a Historic Table 2 US row beside a newer Table 1.x row. In two of them the state rows sum to more than the smaller national row (#1243). Rows 1 and 2 above are the treatment that #1243 asks for.
  • State age rows and state totals. The national build fits Census age bands for each state. The local build fits state totals from the 2020 ladder and no age row (#1528, #1526, PR #1531). No rule ties the age rows of a state to its total.
  • District age and households from ACS. They are not in the fit (#1731, step 1). Their state parent would come from a different source: the districts from a survey, the states from the Census estimates.
  • Not checked yet: whether the state rows of each program family (SNAP, Medicaid, SSI, TANF, CHIP, ACA) sum to the national row of that family.

What the UK has

The UK has one shared operator for this job: microcosm.build.cross_grain, with uk/cross_grain_declarations.json (#802, #905, #1123, docs/uk-local-cross-grain-reconciliation-802.md).

  • The declaration gives the order of the levels and says which levels hold controls.
  • A bridge ties a lower level to a control, with a declared bound on the factor.
  • A partition ties members to a parent inside one area. The members sum to the parent, or they keep their shares.
  • Each pair of targets that measure one quantity at two levels is reconciled, or it is declared with a reason. A static test refuses a pair that is not declared.
  • The operator changes target values only. It never changes loss weights. It writes one receipt.

The US mechanisms each do a part of this. The US also has needs that the UK operator does not cover today:

  • two source years for one state concept, with a bridge through a sibling concept;
  • a crosswalk between district plans;
  • combined cells;
  • the split of a parent's matrix row among its children after the engine pass (split_carriers_into, split_state_rows).

Decided

Stage A uses the country-agnostic code that the UK already uses (microcosm.build.cross_grain). The US gives its choices as declarations. The US gets no second operator and no copy of the arithmetic (decided on 26 Nov).

One effect to plan for: the UK graph hashes cross_grain (uk_runtime/target_compile_modules.py). So an edit to that module makes the UK target nodes compute again on the next UK run. The UK outputs must stay the same, and a test must show it.

Work

Stage A: one rule and one operator. No target changes.

  1. Write the inventory as data. For each family and level in the compiled registry, declare which level holds the level value, which rows are shares, and the source and year of each. The declaration is a US file in the shape of uk/cross_grain_declarations.json. The code that reads it has no country in it.
  2. Make child rows with cross_grain.
    • Use its bridges, partitions, factor bounds and receipt as they are.
    • Add what the US needs and the operator does not have today (the list above). Each addition has no country code, and the UK declarations do not turn it on.
  3. Move rows 5 to 8 to the operator, with the same bytes.
    • PR #1755 pins the bytes of state_cd.
    • state_county has no pin yet. It needs the pinned county facts file.
  4. Move rows 1 to 4 where the arithmetic is the same.
    • Row 4 is a second shared rule for the same job (reconcile_ledger_target_hierarchy). Fold it into cross_grain, or say why it stays.
    • Keep a row as it is where the move would change a value, and say why.
  5. Write one function for the matrix split. Today the district code and the county code each have one.
  6. Add a static test on the declaration: each quantity that two levels measure is reconciled or declared with a reason. This is the test that the UK has. It is a test of the declaration, not a release gate.

Stage B: apply the rule. These steps change targets.

  1. District age and household rows from ACS, as children of state rows (#1731, step 1).
  2. District SOI rows and county rows in one run (#1731, step 3). This needs the rule for two child sets of one state.
  3. The 14 SOI families of #1243, on the national control. #1243 is a sub-issue of this issue, and it waits for Stage A.
  4. State age rows and state totals on one vintage (#1526, PR #1531).
  5. The full chain where a national control exists: national to state, then state to district and county, with the same state parent on every surface.

Order

  • Stage A is first. It changes no target, so it does not wait for the build of #1719.
  • Stage A comes before #1731 steps 1 and 3. Each of them would otherwise add a mechanism.
  • These do not wait for Stage A: the measured state_cd run (#1731, step 2), which uses the code as it is, and the Chronicle work for new families (PolicyEngine/chronicle#447).
  • Stage B changes the loss. Group it with the other loss changes of #1728 into few builds. Choose λ again after them (#1730).

Decisions needed

  1. Which level holds the level value, for each family. A proposal: the highest level that has a current source with the same concept.
  2. Two sources at two levels. When the district rows are a survey and the state rows are estimates, the district rows are shares of the state row, or they stay as levels (#1731, decision 2).
  3. Row 7. Whether the state households target stays the sum of the county values, or becomes a state level that the counties divide.
  4. The parent row in the loss. When all the children of a parent are in the loss, the parent is their sum, so the loss counts it twice. Decide whether the parent stays, with the weight rule by level of #1729.
  5. The factor bound. One declared bound for each bridge, as in the UK, or the median band of row 5.
  6. Children that are not complete: district plans (117th to 119th today, the 120th in #1526), a county with no IRS row, and a state with one district, where the district row is a copy of the state row.

Done when

  • One declaration states the nesting of each US family and level, and a test reads it.
  • The tools hold no share arithmetic. The operator that the UK uses makes the child rows of both countries, with one receipt format.
  • After Stage A, each pinned US surface has the same bytes as before, and the UK targets are the same.
  • The 14 families of #1243 are on the national control.
  • Each quantity that two levels measure is reconciled, or it is declared with a reason.
  • #1731 steps 1 and 3 use the operator.

Related

#1728, #1731, #1730, #1729, #1243, #1528, #1526, #1038, #1035, #940, #489, #922, #625, #449, #802, #905, #1123, PR #1755, PR #1531, PR #1719, PolicyEngine/chronicle#447.

Dominant language
Python
Stars
0
Forks
6
Avg merge
1d 17h
Merged PRs (30d)
190

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PolicyEngine/microcosm

All issues in PolicyEngine/microcosm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.