Implement commodity constraints - #1513
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1513 +/- ##
==========================================
+ Coverage 90.35% 90.82% +0.47%
==========================================
Files 61 61
Lines 8850 8996 +146
Branches 8850 8996 +146
==========================================
+ Hits 7996 8171 +175
+ Misses 529 506 -23
+ Partials 325 319 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds support for explicit commodity consumption/production constraints in the full-system dispatch optimisation, with diagnostic reruns to help pinpoint infeasibility causes, while intentionally excluding these constraints from partial dispatch during investment/cycle steps.
Changes:
- Implement commodity production/consumption constraint rows in dispatch optimisation (optional per dispatch run).
- Extend infeasibility diagnostics to separately test unmet demand vs. commodity-constraint-caused infeasibility and surface clearer error messages.
- Gate loading/usage of
commodity_constraints.csvbehindplease_give_me_broken_results, and document the feature + add an integration test for the diagnostic messaging.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/model.rs | Adds an integration test asserting commodity-constraint infeasibility is diagnosed and reported clearly. |
| src/simulation/optimisation/constraints.rs | Adds commodity constraint rows to the HiGHS problem, toggled by a new flag. |
| src/simulation/optimisation.rs | Adds dispatch-run flag + diagnostic reruns for unmet demand and commodity constraints to improve infeasibility reporting. |
| src/simulation/market.rs | Disables commodity constraints for partial dispatch used during market/cycle selection. |
| src/simulation/investment.rs | Disables commodity constraints for partial dispatch used during investment. |
| src/input/commodity/constraints.rs | Reads optional commodity_constraints.csv, validates it, and enforces the experimental-feature gate. |
| src/commodity.rs | Refactors commodity constraint storage to be keyed by year and stores region on the constraint itself. |
| schemas/input/commodity_constraints.yaml | Documents the experimental nature and required please_give_me_broken_results setting. |
| docs/model/dispatch_optimisation.md | Documents commodity constraints and the new infeasibility diagnostic approach. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Description
Implements the commodity constraints in the dispatch. This is only a partial solution, included for testing purposes, and expected to fail in many/most cases - this is what Adam has asked for.
The reason it's only a partial solution is that we also need a way to constrain commodity consumption/production in the investment stage, and this is much harder. Without this, an agent may invest in assets to produce a commodity, then find that in the full system dispatch they can only produce that commodity up to a limit, at which point dispatch will fail. Similarly, they currently have no extra incentive to invest in assets producing commodities with minimum production constraints, but if they don't then dispatch will later fail. We don't currently have a solution for this problem, and it will need further thought/investigation.
In the meantime, I wanted to make sure the implementation is correct in the full system dispatch, and that error messages are clear in the case where it (inevitably) fails. I've made commodity constraints optional according to the caller (so we can exclude commodity constraints for partial system dispatch during investment). For the full system dispatch it will first run with commodity constraints (if provided), then run without commodity constraints if that fails, to see if the commodity constraints are responsible. I've reworked the diagnostics code a bit to make it easier to do multiple diagnostic runs (previously it was just the unmet demand diagnostic). We may want to think about more potential diagnostics, if useful.
I've gated commodity constraints behind the
please_give_me_broken_resultsoption so that casual users don't try to use this.Other small changes:
CommodityConstraintto storeRegionIDread_commodity_constraints_successto testread_commodity_constraints_from_iterrather thanread_commodity_constraints, as the latter now requires changingplease_give_me_broken_resultswhich is difficult to do in testsFixes #1449
Type of change
Key checklist
$ cargo test$ cargo docpresent in the previous release
Further checks