Skip to content

Revert "Use TimeSliceSelection for demand maps" - #1546

Merged
tsmbland merged 1 commit into
mainfrom
revert-1540-demand_map
Sep 11, 2026
Merged

Revert "Use TimeSliceSelection for demand maps"#1546
tsmbland merged 1 commit into
mainfrom
revert-1540-demand_map

Conversation

@tsmbland

Copy link
Copy Markdown
Collaborator

Reverts #1540

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.84%. Comparing base (f0c1049) to head (bd698e9).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1546   +/-   ##
=======================================
  Coverage   90.83%   90.84%           
=======================================
  Files          61       61           
  Lines        9014     9019    +5     
  Branches     9014     9019    +5     
=======================================
+ Hits         8188     8193    +5     
  Misses        507      507           
  Partials      319      319           

☔ 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 marked this pull request as ready for review September 11, 2026 13:37
Copilot AI lite review requested due to automatic review settings September 11, 2026 13:37
@tsmbland
tsmbland enabled auto-merge September 11, 2026 13:37
@tsmbland
tsmbland disabled auto-merge September 11, 2026 13:38
@tsmbland
tsmbland merged commit c8215b8 into main Sep 11, 2026
10 checks passed
@tsmbland
tsmbland deleted the revert-1540-demand_map branch September 11, 2026 13:38

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

A critical unmet-demand tolerance issue and missing regression coverage remain unresolved.

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

Pull request overview

Reverts #1540, restoring time-slice-keyed demand handling across investment appraisal and market selection.

Changes:

  • Restores per-time-slice demand flattening and appraisal handling.
  • Updates constraints, output, fixtures, benchmarks, and regression data.
  • Restores prior time-slice serialization behavior.
File summaries
File Summary
tests/data/simple/debug_appraisal_results.csv Updates regression expectations.
src/time_slice.rs Restores prior enum serialization behavior.
src/simulation/market.rs Uses time-slice demand lookups.
src/simulation/investment/appraisal/optimisation.rs Computes per-time-slice unmet demand.
src/simulation/investment/appraisal/constraints.rs Aggregates demand for constraints.
src/simulation/investment.rs Restores time-slice demand maps and flattening.
src/output.rs Restores per-slice appraisal output fields.
src/fixture.rs Updates appraisal fixtures.
benches/assets.rs Updates benchmark demand handling.
Review details

Suppressed comments (2)

src/simulation/investment.rs:163

  • This conversion is the only path that turns annual/seasonal input demand into the per-time-slice map consumed by appraisal, but the unit tests in this module only exercise already-flattened maps. Please add parameterised coverage for at least annual and seasonal selections, asserting that each selection's per-slice values sum to the original demand and that separate selections do not overwrite one another; otherwise a regression here can silently change investment demand.
            // We split the demand equally over all time slices in the selection
            // NOTE: since demands will only be balanced to the time slice level of the commodity
            // it doesn't matter how we do this distribution, only the total matters.
            #[allow(clippy::cast_precision_loss)]
            let n_time_slices = time_slice_selection.iter(time_slice_info).count() as f64;
            let demand_per_slice = *demand / Dimensionless(n_time_slices);
            for (time_slice, _) in time_slice_selection.iter(time_slice_info) {
                demand_map.insert(
                    (commodity_id.clone(), region_id.clone(), time_slice.clone()),
                    demand_per_slice,
                );
            }

src/simulation/investment/appraisal/constraints.rs:56

  • This flow lookup is now inside the time-slice loop even though the coefficient is constant for the whole selection. Appraisal runs this constraint construction for every candidate and round, so this adds one IndexMap lookup per time slice unnecessarily; hoist the lookup before the inner loop.
            let flow_coeff = asset.get_flow(&commodity.id).unwrap().coeff;
  • Files reviewed: 9/10 changed files
  • Comments generated: 1
  • 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 on lines +95 to +96
let unmet_per_slice = (demand_for_selection - supply_for_selection).max(Flow(0.0))
/ Dimensionless(time_slices.len() as f64);
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