Allow cost-based pricing for circular markets#1322
Open
tsmbland wants to merge 12 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## select_assets_for_cycle_fix #1322 +/- ##
===============================================================
+ Coverage 89.52% 89.63% +0.11%
===============================================================
Files 58 58
Lines 8542 8609 +67
Branches 8542 8609 +67
===============================================================
+ Hits 7647 7717 +70
Misses 580 580
+ Partials 315 312 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Enables cost-based (marginal/full) pricing strategies for models with circular commodity dependencies by removing the prior validation restriction and introducing cycle-aware pricing logic.
Changes:
- Remove the validation-time restriction that prevented cost-based pricing strategies in
InvestmentSet::Cycle. - Refactor price calculation to handle
InvestmentSetvariants explicitly, adding aprice_cyclepathway and allowing price overwrites during cycle iteration. - Update circularity example/regression datasets to reflect the new pricing behavior.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/data/circularity/commodity_prices.csv | Updated expected commodity price outputs for circularity regression scenario. |
| tests/data/circularity/commodity_flows.csv | Updated expected flow outputs for circularity regression scenario. |
| tests/data/circularity/assets.csv | Updated expected assets snapshot for circularity regression scenario. |
| tests/data/circularity/asset_capacities.csv | Updated expected asset capacities snapshot for circularity regression scenario. |
| src/simulation/prices.rs | Adds cycle-aware pricing path and allows overwriting prices to support iterative updates. |
| src/input.rs | Adjusts model loading to accommodate non-Result investment-order solving. |
| src/graph/investment.rs | Removes pricing-strategy restriction in SCC compression and simplifies APIs to return non-Result. |
| examples/circularity/commodities.csv | Updates example commodities to use default (cost-based) pricing rather than shadow pricing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
015bb12 to
c994f8c
Compare
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.
Description
See #1318 for full context. Adam suggested a solution of iterating over the commodities in cycles just once, in the reverse of the investment order. This will inevitably lead to some price inconsistency between commodities, but prevents the risk of price spiralling that could happen if we iterate multiple times.
The implementation here does exactly this (one pass through the commodities in the reverse of the investment order), although I've left the code flexible enough that we can experiment with iterating multiple times (via a hard-coded variable in the code, rather than an input parameter).
I've run for the "circularity" example (using the default "full_average" pricing strategy) and it works nicely. (Hydrogen prices are atmittedly very high in the first year, but I think that's down to #1325)
Main changes:
compress_cyclesthat was disallowing circular markets to use cost-based pricing strategiesResultInvestmentSets, similar to the investment algorithm just in reverse order. ForInvestmentSet::Cycle, this calls the newprice_cyclefunction.CommodityPrices::insertandCommodityPrices::extend_selection_pricesto allow for price overwriting. This was necessary since prices for circular markets need to be updated multiple times (even if just running for one iteration, since we seed with shadow prices beforehand), and this was the easiest way to do it (slightly lazy - I can change if we really need this check in other contexts, but it didn't seem hugely important to me)Other notes:
price_markets, while set up to solve multiple markets in batch, is in practice only ever called on one market at a time. There are potentially some performance gains that could be had by solving independent markets in batch (particularly within the same layer), but this didn't work with the recursive approach ofprice_investment_set.If we don't want to go down the route of solving markets in batch then we could simplifyprice_marketsand some other functions. I'll leave it for now though.InvestmentSetinto something a bit more generic is we're now using this outside the context of investments.Fixes #1168
Type of change
Key checklist
$ cargo test$ cargo docpresent in the previous release
Further checks