Skip to content

feat(eeio): derive y_nab from Adom and scaled_q#458

Open
bl-young wants to merge 1 commit into
mainfrom
456-y-nab-from-q-a
Open

feat(eeio): derive y_nab from Adom and scaled_q#458
bl-young wants to merge 1 commit into
mainfrom
456-y-nab-from-q-a

Conversation

@bl-young

@bl-young bl-young commented Jun 5, 2026

Copy link
Copy Markdown
Member

cc:
Closes: #456

What changed? Why?

y_nab_USA for the Cornerstone full model (2025_usa_cornerstone_full_model) is derived from the same derive_cornerstone_Aq_scaled() object that produces snapshotted scaled_q_USA and Adom_USA, via backcompute_y_from_q_and_Aq(Adom, scaled_q). That enforces IO row balance q = Adom @ diag(q) + y_nab and domestic Leontief consistency q ≈ L_dom @ y_nab.

The prior path built y_nab from BEA Y/trade disaggregation and inflation — parallel to the A/q pipeline and inconsistent with snapshotted scaled_q (323 commodity sectors failed q ≈ L·y at 1% tolerance on the domestic branch).

derive_cornerstone_y_nab — replaces the BEA disaggregation/inflation body with a three-line backcompute from derive_cornerstone_Aq_scaled(). Negative y_nab values are retained; handle_negative_vector_values breaks the domestic Leontief identity because L_dom is dense (24 clipped sectors caused 26 test failures during development).

test_compare_output_and_L_y — adds a passing Cornerstone domestic case (Commodity, use_domestic=True). Total Leontief cases (Cornerstone and CEDA) remain xfail; Cornerstone total still pairs scaled Adom + Aimp with BEA-derived y from derive_cornerstone_Y_and_trade_scaled.

Unchanged: scaled_q, Adom, ytot, ydom, yimp, exports derivation paths. CEDA v7 legacy path. derive_y_for_national_accounting_balance_usa router (Cornerstone branch still delegates to derive_cornerstone_y_nab).

Follow-ups (not in this branch)

  • Snapshot bumpy_nab_USA values change; test_y_nab_usa_snapshot fails until Phase A regeneration (GCS upload, .SNAPSHOT_KEY, releases.py, usa_config.py Literal). Required before merge if integration tests gate on snapshots.
  • Refine q estimate #457457-refine-q-estimate refines scaled_q via authoritative-x V scaling. y_nab couples to derive_cornerstone_Aq_scaled(), so refined q propagates automatically once wired into that path. Coordinate stack order if both land near the same snapshot cut.
  • Total L·y and Y snapshots — reconcile ytot/ydom/yimp/exports with IO-balanced y_nab, or adjust MRIO multi-region Y assembly (ydom + exports vs y_nab_USA parquet).

Testing

Domestic Cornerstone Leontief identity (passes, 0 failing sectors at 1% rtol):

uv run pytest "bedrock/utils/validation/__tests__/test_eeio_diagnostics.py::test_compare_output_and_L_y[Commodity-True-cornerstone]" -m eeio_integration -v

Full diagnostics module (domestic passes; total cases xfail as expected):

uv run pytest bedrock/utils/validation/__tests__/test_eeio_diagnostics.py -k test_compare_output_and_L_y -m eeio_integration -v

Snapshot integration (fails until y_nab_USA snapshot regeneration):

uv run pytest bedrock/transform/__tests__/test_usa.py::test_y_nab_usa_snapshot -m eeio_integration -v

Backcompute national-accounting final demand from the same
derive_cornerstone_Aq_scaled() path as scaled_q, enforcing
q ≈ L_dom @ y_nab.
@bl-young bl-young linked an issue Jun 5, 2026 that may be closed by this pull request
@bl-young bl-young requested a review from MoLi7 June 8, 2026 18:43
@bl-young bl-young marked this pull request as ready for review June 15, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update the snapshots for q and Y US for use in MRIO

1 participant