Skip to content

Fix parent capacity for dispatch#1211

Merged
alexdewar merged 3 commits intomainfrom
fix-parent-capacity-for-dispatch
Mar 19, 2026
Merged

Fix parent capacity for dispatch#1211
alexdewar merged 3 commits intomainfrom
fix-parent-capacity-for-dispatch

Conversation

@alexdewar
Copy link
Copy Markdown
Collaborator

Description

Since #1124, we've been using parent assets to stand in for their children during dispatch, which allows us to avoid having separate variables for each child. Unfortunately, I didn't account for the fact that it is possible that only a subset of a parent's children will be included in the dispatch run. While the capacity of parent assets is permanently reduced at the point where a child is decommissioned, it is also possible that we are running dispatch with a subset of children, because only some have been selected for investment so far. In that case, we should treat the parent asset as if it represents only a number of units representing the selected children.

The way I implemented this was to add a helper to AssetRef to create new objects representing part of a parent's capacity. As we don't include capacity in Assets' hashes, these "fake" assets can be used interchangeably with the real parents when they're a key (or part of a key) in a map.

Fixes #1131.

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc
  • Update release notes for the latest release if this PR adds a new feature or fixes a bug
    present in the previous release

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copilot AI review requested due to automatic review settings March 18, 2026 14:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes dispatch capacity accounting when dispatch is run with only a subset of a divisible parent asset’s children (e.g., during staged investment selection), preventing the parent from being treated as if it represents all children.

Changes:

  • Adjust dispatch asset normalization to create a “partial parent” when only some children are present.
  • Add AssetRef::make_partial_parent to represent a parent with reduced discrete unit count (while keeping Hash/Eq compatible with the original parent).
  • Update golden test output CSVs for the simple_divisible fixture to reflect corrected dispatch results.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/simulation/optimisation.rs Reworks get_parent_or_self to count children per parent and emit a partial-parent AssetRef with matching unit count.
src/asset.rs Adds AssetRef::make_partial_parent to construct an AssetRef representing a subset of a parent’s discrete units.
tests/data/simple_divisible/commodity_flows.csv Updates expected commodity flow outputs to align with corrected dispatch capacity handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.31%. Comparing base (e49dbd7) to head (d237e58).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
src/asset.rs 95.23% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1211   +/-   ##
=======================================
  Coverage   89.31%   89.31%           
=======================================
  Files          57       57           
  Lines        7974     8004   +30     
  Branches     7974     8004   +30     
=======================================
+ Hits         7122     7149   +27     
- Misses        555      558    +3     
  Partials      297      297           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@alexdewar alexdewar requested review from Aurashk and tsmbland March 18, 2026 16:00
@alexdewar
Copy link
Copy Markdown
Collaborator Author

Maybe I should add a test which covers the case where we need a parent asset with less than its full capacity, like the one we have in #1131. Currently those lines appear not to be covered...

Copy link
Copy Markdown
Collaborator

@tsmbland tsmbland left a comment

Choose a reason for hiding this comment

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

Well done for spotting! I think this highlights again why #1123 is a good idea

@alexdewar
Copy link
Copy Markdown
Collaborator Author

Well done for spotting! I think this highlights again why #1123 is a good idea

Indeed! Though we will still need to consider how we represent a subset of an asset's capacity for this sort of case when we do that... but that's a future problem 😆

@alexdewar alexdewar enabled auto-merge March 19, 2026 16:38
@alexdewar alexdewar merged commit b36d823 into main Mar 19, 2026
8 checks passed
@alexdewar alexdewar deleted the fix-parent-capacity-for-dispatch branch March 19, 2026 16:42
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.

Investment appears to decommission too much in this case

3 participants