Skip to content

Exclude mothballed assets from main dispatch - #1458

Merged
alexdewar merged 6 commits into
mainfrom
exclude-mothballed-from-main-dispatch
Jul 30, 2026
Merged

Exclude mothballed assets from main dispatch#1458
alexdewar merged 6 commits into
mainfrom
exclude-mothballed-from-main-dispatch

Conversation

@alexdewar

Copy link
Copy Markdown
Member

Description

MUSE2 has a feature where assets can be mothballed instead of being decommissioned immediately, with the assets eventually decommissioned after a period indicated by mothball_years if they remain unused. In the interim, they can be revived if selected for investment.

During investment, we include mothballed assets during dispatch runs as we want them to contribute to prices and flows. For the main dispatch run in run_dispatch_for_year, however, we shouldn't be including them, as they are technically inactive and so should not contribute to flows and prices. Of course, if they have been mothballed, the model has deemed them superfluous, so we wouldn't expect them to contribute much, but it would be better to exclude them explicitly. With local testing, I found that mothballed assets were contributing a non-negligible amount to flows and prices.

The way the code is currently written, selected assets remain in a mothballed state until they are added back to the AssetPool, at which point they are unmothballed. However, by virtue of having been selected, they are effectively no longer mothballed and so should be included in the dispatch run. I decided the cleanest way to implement this was to instead unmothball assets at the point they are selected and then unconditionally exclude mothballed assets in run_dispatch_for_year.

By default, the mothballing feature is disabled (mothball_years defaults to zero) and none of the existing regression tests exercise this part of the code, so I've added a new regression test to cover this case. If you want to see how excluding mothballed assets from dispatch affects results, see 6ec71bd. A regression test is also useful for all the refactoring I'll be doing for #1123, which involves a lot of fiddling with the mothballing-related code.

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 July 30, 2026 10:40
@alexdewar alexdewar added this to MUSE Jul 30, 2026
@alexdewar alexdewar moved this to 🏗 In progress in MUSE Jul 30, 2026
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.52%. Comparing base (163fe51) to head (13e2fd2).

Files with missing lines Patch % Lines
src/simulation/investment.rs 25.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1458      +/-   ##
==========================================
- Coverage   89.66%   89.52%   -0.15%     
==========================================
  Files          60       60              
  Lines        8523     8542      +19     
  Branches     8523     8542      +19     
==========================================
+ Hits         7642     7647       +5     
- Misses        560      573      +13     
- Partials      321      322       +1     

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI 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.

Pull request overview

This pull request fixes dispatch correctness when the mothballing feature is enabled by ensuring mothballed (inactive) assets do not contribute to the main annual dispatch run, while still allowing assets revived via investment selection to participate.

Changes:

  • Unmothball commissioned assets at the point they are selected during investment so they are treated as active immediately.
  • Filter mothballed assets out of run_dispatch_for_year so the main dispatch run uses only active assets for flows/prices.
  • Add a new patched regression scenario (simple_mothball) and expected outputs to exercise mothballing behaviour.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/regression.rs Registers the new patched regression test case.
tests/data/simple_mothball/commodity_prices.csv Expected prices for the new mothball regression scenario.
tests/data/simple_mothball/commodity_flows.csv Expected flows for the new mothball regression scenario.
tests/data/simple_mothball/assets.csv Expected asset list for the new mothball regression scenario.
tests/data/simple_mothball/asset_capacities.csv Expected capacities for the new mothball regression scenario.
src/simulation/investment.rs Unmothballs commissioned assets immediately when selected for retention.
src/simulation.rs Excludes mothballed assets from the main dispatch run and documents the behaviour.
src/example/patches.rs Adds the simple_mothball patched example (sets mothball_years = 10).
src/asset/pool.rs Adjusts mothballing/extension behaviour to align with unmothball-at-selection.
src/asset.rs Makes mothball state queryable via is_mothballed() and makes get_mothballed_year() non-panicking.

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

Comment thread src/simulation.rs

@tsmbland tsmbland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good. Good idea adding a patch test. Looks like most mothballed assets weren't being used anyway, apart from one which has some knock on consequences when excluded.

Do you think it might still be worth including mothballed assets in commodity_flows.csv (showing zero activity?).

Also, beyond the scope of this PR, but some way of representing mothballing decisions in the output data so it's clear to users (maybe splitting mothballed/non-mothballed capacity in asset_capacities.csv, although there's probably a nicer way)?

@alexdewar

Copy link
Copy Markdown
Member Author

Looks good. Good idea adding a patch test. Looks like most mothballed assets weren't being used anyway, apart from one which has some knock on consequences when excluded.

Good point.

Do you think it might still be worth including mothballed assets in commodity_flows.csv (showing zero activity?).

Also, beyond the scope of this PR, but some way of representing mothballing decisions in the output data so it's clear to users (maybe splitting mothballed/non-mothballed capacity in asset_capacities.csv, although there's probably a nicer way)?

These are both good ideas, but I think I'll open issues rather than trying to tackle them now. I'm just finishing up a bigger refactor of the mothballing code to support partially mothballed assets, which we (unfortunately) need for #1123.

@dc2917 dc2917 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.

Seems sensible to me

@alexdewar

Copy link
Copy Markdown
Member Author

New issues: #1460 and #1461

@alexdewar
alexdewar merged commit bf78fb3 into main Jul 30, 2026
7 of 8 checks passed
@alexdewar
alexdewar deleted the exclude-mothballed-from-main-dispatch branch July 30, 2026 14:45
@github-project-automation github-project-automation Bot moved this from 🏗 In progress to ✅ Done in MUSE Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants