Skip to content

num_units column in assets.csv - #1480

Open
tsmbland wants to merge 4 commits into
mainfrom
assets_n_units
Open

num_units column in assets.csv#1480
tsmbland wants to merge 4 commits into
mainfrom
assets_n_units

Conversation

@tsmbland

@tsmbland tsmbland commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Description

This is the first step on the way to making all assets divisible (#1441). This PR makes all assets provided in assets.csv divisible (changing capacity from Continuous to Discrete). Since not all processes have a defined unit_size (and we want to keep this optional), we need an extra column (num_units) specifying how many units to split the capacity into. For processes with a defined unit_size, num_units takes precedence. If n_units is not specified, the behaviour is essentially equivalent to how it currently is: split processes with unit_size according to this, and processes without n_units remain non-divisible (i.e. discrete capacity with a single unit).

This does affect the output files, but only because it changes the num_units column in asset_capacities.csv. Total capacities, flows and prices should be unchanged.

Eventually I want to drop AssetCapacity::Continuous entirely, but it's currently also used by assets invested in by MUSE. This is the next thing to change (#1483)

This PR doesn't make much sense to merge without #1483, but I still figured I'd keep it separate to make it slightly easier to review (#1483 is pretty big so anything to break it up).

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 changed the title n_units column in assets.csv num_units column in assets.csv Aug 12, 2026
@tsmbland
tsmbland requested a lite review from Copilot August 12, 2026 09:41

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 PR introduces an explicit num_units field for user-provided assets to support making all assets.csv assets representable as discrete “units”, as an incremental step toward making all assets divisible (Issue #1441). It also standardises naming by renaming AssetCapacity::n_units() to AssetCapacity::num_units() and updates call sites accordingly.

Changes:

  • Add optional num_units parsing from assets.csv and derive discrete AssetCapacity from either explicit num_units, process unit_size, or default to a single unit.
  • Rename AssetCapacity::n_units()AssetCapacity::num_units() and update usages in optimisation/output/asset logic.
  • Update the input schema (schemas/input/assets.yaml) to document the new num_units column.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/simulation/optimisation.rs Updates capacity constraint logic to use AssetCapacity::num_units().
src/output.rs Outputs num_units via the renamed AssetCapacity::num_units() accessor.
src/input/asset.rs Adds num_units CSV field and constructs discrete AssetCapacity for user assets based on num_units/unit_size.
src/asset/pool.rs Updates tests/construction to pass explicit AssetCapacity for UserAsset::new.
src/asset/capacity.rs Renames n_units() to num_units() and updates related tests.
src/asset.rs Changes UserAsset::new to accept an explicit AssetCapacity and updates internal/tests accordingly.
schemas/input/assets.yaml Documents the new optional num_units column for assets.csv.

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

Comment thread src/input/asset.rs
Comment thread src/input/asset.rs
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.91%. Comparing base (f3af853) to head (6cef7f2).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
src/simulation/optimisation.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1480   +/-   ##
=======================================
  Coverage   89.91%   89.91%           
=======================================
  Files          60       60           
  Lines        8556     8560    +4     
  Branches     8556     8560    +4     
=======================================
+ Hits         7693     7697    +4     
  Misses        543      543           
  Partials      320      320           

☔ 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 Aug 12, 2026
11 tasks
@tsmbland
tsmbland marked this pull request as ready for review August 13, 2026 14: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