Skip to content

Allows government consumption and investment to come from multiple sectors - #1192

Open
jdebacker wants to merge 18 commits into
PSLmodels:masterfrom
jdebacker:gov_spend
Open

Allows government consumption and investment to come from multiple sectors#1192
jdebacker wants to merge 18 commits into
PSLmodels:masterfrom
jdebacker:gov_spend

Conversation

@jdebacker

Copy link
Copy Markdown
Member

In the current OG-Core, the M-th industry produces all of the non-consumption goods: capital, government consumption, and infrastructure. This PR relaxes the assumption somewhat, allowing all industries' output to combine in producing government consumption expenditures and infrastructure goods.

Addresses Issue #985

@jdebacker

Copy link
Copy Markdown
Member Author

One important note on the changes in this PR: because each industry contributes to the production of G and I_g we need to know these quantities when solving the firm's problem. But G (under the unbalanced budget parameterization and once the closure rule kicks in) can't be determined without total_tax_revenue, which itself depends on the solution to the firm's problem. Therefore, the changes here modify the solution algorithm by adding G to the "outer loop" variables to be solved for in the GE fixed point algorithm.

This also means that G is now passed to some functions where it wasn't previously (such as SS.inner_loop).

When running local tests, I'm finding that all the tests that run fully through the SS solution (except for one case) pass:

====================================== short test summary info ======================================
FAILED tests/test_SS.py::test_run_SS[Reform, small open use zeta] - RuntimeError: Steady state equilibrium not found
====================== 1 failed, 14 passed, 24 warnings in 16377.51s (4:32:57) ======================

and that all the tests that run fully through the TPI solution (except for the new test added where the IO matrix represents multiple industries contributing to G and I_g) pass:

=========================== short test summary info ============================
FAILED tests/test_TPI.py::test_run_TPI_full_run[Baseline, mixed government IO] - RuntimeError: Steady state aggregate resource constraint not satisfied
============ 1 failed, 12 passed, 11 warnings in 7226.51s (2:00:26) ===========

I'm going to ensure these tests pass. But then for other tests that add a new in put (usually G, such as in SS.inner_loop) I will feel confident changing the expected output to match the new output since we have run the changes through the full SS and transition path solutions and found that they do not affect the results. I will document the cases/tests where expected output changed in this thread.

@codecov-commenter

codecov-commenter commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.00000% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.78%. Comparing base (17556bc) to head (75a84dd).
⚠️ Report is 24 commits behind head on master.

Files with missing lines Patch % Lines
ogcore/TPI.py 11.11% 8 Missing ⚠️
ogcore/SS.py 72.00% 7 Missing ⚠️
ogcore/aggregates.py 90.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1192      +/-   ##
==========================================
+ Coverage   72.71%   72.78%   +0.06%     
==========================================
  Files          22       22              
  Lines        5725     5787      +62     
==========================================
+ Hits         4163     4212      +49     
- Misses       1562     1575      +13     
Flag Coverage Δ
unittests 72.78% <68.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ogcore/fiscal.py 97.14% <ø> (ø)
ogcore/parameters.py 82.38% <100.00%> (+0.62%) ⬆️
ogcore/aggregates.py 99.45% <90.00%> (-0.55%) ⬇️
ogcore/SS.py 79.43% <72.00%> (+0.40%) ⬆️
ogcore/TPI.py 35.06% <11.11%> (-1.24%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jdebacker
jdebacker marked this pull request as ready for review August 7, 2026 15:23
@jdebacker
jdebacker requested a review from rickecon August 7, 2026 15:23
@jdebacker

Copy link
Copy Markdown
Member Author

Just one local test failing right now:

=========================== short test summary info ============================
FAILED tests/test_SS.py::test_run_SS[Reform, small open use zeta] - RuntimeError: Steady state equilibrium not found
=========== 1 failed, 643 passed, 77 warnings in 34569.87s (9:36:09) ===========

@arihantlodha-cmd arihantlodha-cmd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Focused on the new parameters and their docs and validation here, not the full production-sector derivation, so treat this as a partial review.

The io_matrix changes look clean and the docs match the code. I traced the row indexing: the description says the first I rows are consumption goods, row I is government consumption, and row I+1 is infrastructure, and that lines up exactly with how it gets used (io_matrix[:p.I] for C, io_matrix[p.I] for G, io_matrix[p.I+1] for I_g in both SS.py and aggregates). Nice that the new shape validation in parameters.py, checking (I+2, M) and that each row sums to 1, makes a bad matrix fail loudly instead of flowing through silently.

Two small things:

The row-sum check is good, but it doesn't verify entries are non-negative. A hand-built io_matrix could have a negative coefficient and still sum to 1 per row, which would be economically off but pass validation. Worth a >= 0 check while you're already validating shape and sums?

Minor: when the row-sum check fails the error just says each row must sum to 1. Naming the offending row index would make a mis-entered matrix faster to fix, but not important.

Also looked at the new p_g and p_Ig entries in model_variables.json. Labels are escape-clean and the trailing-newline fix on that file is a nice touch.

Looks good from the parameter side.

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.

3 participants