Skip to content

Remove flexible capacity balancing for circularities - #1539

Merged
tsmbland merged 4 commits into
circularityfrom
remove_flexible_capacity
Sep 9, 2026
Merged

tsmbland merged 4 commits into
circularityfrom
remove_flexible_capacity

Conversation

@tsmbland

@tsmbland tsmbland commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Description

Removing flexible capacity balancing for circularities, to be replaced with another approach in the future. For now, models with circularities will likely fail, unless the circularity isn't used, or the system already has enough excess capacity to absorb demand imbalances caused by circularities. The example models pass, seemingly due to the latter.

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 force-pushed the remove_flexible_capacity branch from 774a3b1 to 298f8a5 Compare September 9, 2026 10:22
@tsmbland
tsmbland changed the base branch from main to demand_map September 9, 2026 10:23
@tsmbland
tsmbland force-pushed the remove_flexible_capacity branch from 298f8a5 to 28c7b3b Compare September 9, 2026 10:37

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.

🟡 Changes recommended

Documentation and configuration handling need tightening (docs still mention capacity_margin, and legacy capacity_margin in model.toml will be silently ignored without an explicit warning/error).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR removes the “flexible capacity balancing” mechanism that previously helped cycle (circular) market investment runs converge by allowing newly selected assets to temporarily flex capacity during intermediate dispatch rebalances.

Changes:

  • Removed flexible-capacity decision variables and the associated activity-limit formulation from dispatch optimisation.
  • Removed the capacity_margin model parameter (and its schema entry) and simplified cycle dispatch rebalancing to run with fixed capacities only.
  • Updated circularity test fixtures/expected outputs (flows, prices, and capacities) to match the new optimisation behaviour.
File summaries
File Description
tests/data/circularity/commodity_prices.csv Updates expected commodity prices for the circularity example after removing flexible balancing.
tests/data/circularity/commodity_flows.csv Updates expected dispatch flows for the circularity example after optimisation changes.
tests/data/circularity/asset_capacities.csv Updates expected installed capacities (no longer adjusted by flexible balancing).
tests/data/circularity_npv/commodity_prices.csv Same as above, for the NPV circularity fixture.
tests/data/circularity_npv/commodity_flows.csv Same as above, for the NPV circularity fixture.
tests/data/circularity_npv/asset_capacities.csv Same as above, for the NPV circularity fixture.
src/simulation/optimisation/constraints.rs Simplifies activity constraints (removes flexible-capacity special casing) and includes all assets in equal-utilisation constraints.
src/simulation/optimisation.rs Removes capacity-variable plumbing from the optimisation model and solution API.
src/simulation/market.rs Removes cycle-stage capacity flexing and post-cycle capacity mutation; dispatch failures now surface without capacity-margin guidance.
src/model/parameters.rs Removes capacity_margin from ModelParameters and defaults/validation.
schemas/input/model.yaml Removes capacity_margin from the input schema.
Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/model/parameters.rs
Comment on lines 112 to 116
pub max_ironing_out_iterations: u32,
/// The relative tolerance for price convergence in the ironing out loop
#[serde(deserialize_with = "deserialise_finite_non_negative")]
pub price_tolerance: Dimensionless,
/// Slack applied during cycle balancing, allowing newly selected assets to flex their capacity
/// by this proportion.
///
/// Existing assets remain fixed; this gives newly selected assets the wiggle-room to absorb
/// small demand changes before we would otherwise need to break for re-investment.
#[serde(deserialize_with = "deserialise_finite_non_negative")]
pub capacity_margin: Dimensionless,
/// Number of years an asset can remain unused before being decommissioned
Comment thread src/simulation/market.rs
Comment on lines 236 to +241
/// Iterates through the a pre-ordered set of markets forming a cycle, selecting assets for each
/// market in turn.
///
/// Dispatch optimisation is performed after each market is visited to rebalance demand.
/// While dispatching, newly selected (`Ready`) assets are given flexible capacity (bounded by
/// `capacity_margin`) so small demand shifts caused by later markets can be absorbed. After all
/// markets have been visited once, the final set of assets is returned, applying any capacity
/// adjustments from the final full-system dispatch optimisation.
/// Dispatch optimisation is performed after each market is visited.
///
/// Dispatch may fail at any point if new demands are encountered for previously visited markets,
/// and the `capacity_margin` is not sufficient to absorb the demand shift. At this point, the
/// simulation is terminated with an error prompting the user to increase the `capacity_margin`.
/// A longer-term solution (TODO) may be to trigger re-investment for the affected markets. Other
/// yet-to-implement features may also help to stabilise the cycle, such as capacity growth limits.
/// Dispatch may fail at any point if new demands are encountered for previously visited markets.
@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.63%. Comparing base (f0c1049) to head (892ee42).
⚠️ Report is 5 commits behind head on circularity.

Files with missing lines Patch % Lines
src/simulation/market.rs 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           circularity    #1539      +/-   ##
===============================================
- Coverage        90.83%   90.63%   -0.21%     
===============================================
  Files               61       61              
  Lines             9014     8870     -144     
  Branches          9014     8870     -144     
===============================================
- Hits              8188     8039     -149     
- Misses             507      516       +9     
+ Partials           319      315       -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 mentioned this pull request Sep 9, 2026
11 tasks
Base automatically changed from demand_map to main September 9, 2026 15:14
@tsmbland
tsmbland changed the base branch from main to circularity September 9, 2026 15:21
@tsmbland
tsmbland marked this pull request as ready for review September 9, 2026 15:21
@tsmbland
tsmbland merged commit ed1561d into circularity Sep 9, 2026
7 checks passed
@tsmbland
tsmbland deleted the remove_flexible_capacity branch September 9, 2026 15:21
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