Skip to content

Refactor to allow multiple simulation modes - #1592

Draft
tsmbland wants to merge 11 commits into
remove_shadow_scarcity_strategiesfrom
simulation_mode_refactor_v2
Draft

tsmbland wants to merge 11 commits into
remove_shadow_scarcity_strategiesfrom
simulation_mode_refactor_v2

Conversation

@tsmbland

@tsmbland tsmbland commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The new approach will be do do-away with full-system dispatch and use agent-level activities directly, but I didn't want to remove all this code yet. The aim here is to refactor the code so it can support multiple simulation "modes". One mode will use full-system dispatch to get activities (and partial system dispatch to get intermediate demands), and the other one (#1593) will use agent-level activities directly.

This PR just does the necessary refactoring so that #1593 can slot in a second mode.

Fixes # (issue)

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

@tsmbland
tsmbland added this pull request to stack #1594 November 11, 2026 16:30
@tsmbland
tsmbland force-pushed the simulation_mode_refactor_v2 branch from 8c50734 to e3f7ea3 Compare November 16, 2026 08:57
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.86643% with 106 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.80%. Comparing base (d9d727a) to head (88a3311).

Files with missing lines Patch % Lines
src/simulation/system_dispatch.rs 76.19% 32 Missing and 18 partials ⚠️
src/simulation/market.rs 33.33% 19 Missing and 1 partial ⚠️
src/optimisation.rs 71.18% 17 Missing ⚠️
src/simulation/system_dispatch/output.rs 93.33% 0 Missing and 14 partials ⚠️
src/simulation/system_dispatch/optimisation.rs 70.00% 2 Missing and 1 partial ⚠️
src/simulation/investment.rs 91.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@                          Coverage Diff                          @@
##           remove_shadow_scarcity_strategies    #1592      +/-   ##
=====================================================================
+ Coverage                              82.67%   82.80%   +0.13%     
=====================================================================
  Files                                     69       72       +3     
  Lines                                   9986    10115     +129     
  Branches                                9986    10115     +129     
=====================================================================
+ Hits                                    8256     8376     +120     
- Misses                                  1452     1465      +13     
+ Partials                                 278      274       -4     

☔ 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.

@tsmbland
tsmbland force-pushed the simulation_mode_refactor_v2 branch 5 times, most recently from 2e0ea01 to 49a9b70 Compare November 16, 2026 13:32
tsmbland and others added 9 commits November 16, 2026 14:51
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the partial dispatch runs out of the shared investment and market
code into a PartialDispatch implementation, and remove shadow prices
from Prices.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
output.rs no longer depends on dispatch internals.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tsmbland
tsmbland force-pushed the simulation_mode_refactor_v2 branch from 49a9b70 to ecf145d Compare November 16, 2026 15:00

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.

🟢 Approval recommended

No active review issues remain for the simulation-protocol refactor.

No open issues 🎉

What changed in this PR

Refactors MUSE2’s simulation code to support multiple protocols, preparing for agent-level dispatch in #1593 while retaining system_dispatch as the only available mode and default behaviour.

Changes:

  • Adds the simulation_protocol setting and moves the existing simulation loop into a dedicated module.
  • Introduces FlowEstimator to separate demand propagation from dispatch, and extracts shared optimisation helpers.
  • Relocates dispatch debug output and tests, updates benchmark references, and documents protocol selection.
File Description
src/​simulation/​system_dispatch/​output.rs Houses dispatch debug output and its tests.
src/​simulation/​system_dispatch/​optimisation/​constraints.rs Uses the shared asset-grouping helper.
src/​simulation/​system_dispatch/​optimisation.rs Uses shared solver helpers and relocated debug output.
src/​simulation/​system_dispatch.rs Encapsulates the existing simulation loop and partial dispatch.
src/​simulation/​prices.rs Separates shared prices from dispatch-specific shadow prices.
src/​simulation/​market.rs Delegates cycle flow estimation to FlowEstimator.
src/​simulation/​investment/​portfolio/​optimisation.rs Imports shared solver helpers.
src/​simulation/​investment/​portfolio.rs Generalises the price parameter documentation.
src/​simulation/​investment/​competitive/​optimisation.rs Imports shared optimisation helpers.
src/​simulation/​investment/​competitive/​constraints.rs Imports the shared asset-grouping helper.
src/​simulation/​investment/​competitive.rs Generalises the price parameter documentation.
src/​simulation/​investment.rs Defines and integrates the flow-estimation interface.
src/​simulation.rs Defines protocol selection and delegates execution.
src/​output.rs Removes dispatch-specific output responsibilities.
src/​optimisation.rs Centralises solver and asset-grouping helpers.
src/​model/​parameters.rs Adds the protocol setting, default and parsing tests.
src/​lib.rs Registers the shared optimisation module.
src/​graph/​investment.rs Uses shared solver helpers.
schemas/​input/​model.yaml Documents protocol selection and related settings.
docs/​release_notes/​upcoming.md Announces the optional protocol setting.
docs/​model/​README.md Explains the shared lifecycle and system-dispatch protocol.
docs/​model/​dispatch_optimisation.md Identifies the protocol using this formulation.
docs/​developer_guide/​custom_highs_options.md Clarifies the scope of dispatch solver options.
benches/​assets.rs Updates dispatch imports and price-result handling.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants