Fix BundledLeontief input usage to respect substitution bundles#67
Open
jose-moran wants to merge 5 commits into
Open
Fix BundledLeontief input usage to respect substitution bundles#67jose-moran wants to merge 5 commits into
jose-moran wants to merge 5 commits into
Conversation
BundledLeontief.compute_intermediate_inputs_used() and compute_capital_inputs_used() ignored the substitution bundle matrix, using fixed Leontief coefficients for each good independently. This caused stock to deplete for expensive goods and accumulate for cheap goods, since buying was adjusted by substitution weights but usage was not. Now distributes total bundle usage proportionally to available stock within each multi-member bundle, so firms use more of whichever substitute they have on hand. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Collaborator
|
My gut is that these changes are promising but there is something in them that is triggering production crashes when subjected to a price shock. |
Member
Author
|
how is the price shock defined precisely? |
Collaborator
|
The price shock is executed through a exogenous pricing function that we are using for the energy bundle which imports a price timeseries for those sectors rather than using the endogenous prices in firms/price.py and row/prices.py. It is useful to set up controlled substitution experiments like this one. Let me know if you'd like more specific details. |
Member
Author
|
@sternluke can you try again? |
Collaborator
Member
Author
|
what's the exact experiment you are doing for with/without and see climbing energy prices? |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



















Summary
My own summary here:
I had Claude look at the issue opened by @sternluke and reproduce the bug. There was problematic behaviour -- goods that became more expensive in the substitution bundle were actually increasing in stock during a simulation. Checking the rules we had, I noticed that the problem was that in the bundled Leontief production function good usage was done as with the standard Leontief. This means that
used_intermediate_inputswas being computed as for the standard Leontief function -- substitution was applied for computing production and deciding how much to purchase, but not to update inventories. Paradoxically this led to the accumulation of stocks of expensive inputs.This is now fixed, and I have added tests that BREAK before the fix and that now pass. I would advise checking that other behaviour is not affected.
LLM summary below:
Fixes #62 —
intermediate_inputs_stockandcapital_inputs_stockbehaved differently for substitutable vs non-substitutable goods.BundledLeontief.compute_intermediate_inputs_used()andcompute_capital_inputs_used()ignored the substitution bundle matrix entirely, computing usage at fixed Leontief rates per good. Meanwhile, buying targets were adjusted by substitution weights (price-based reweighting). This mismatch caused expensive goods' stocks to deplete rapidly and cheap goods' stocks to accumulate, since firms bought less of expensive goods but still "used" them at the original rate.Test plan
test_production.pythat fail before the fix and pass after:test_usage_distributed_by_stock_within_bundle— verifies usage shares match stock shares within a bundletest_usage_total_preserved_within_bundle— verifies total bundle usage is conserved, just redistributeddebug_scripts/reproduce_bug_62.pyconfirms improved behaviorcc @lukehclarke