num_units column in assets.csv - #1480
Conversation
There was a problem hiding this comment.
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_unitsparsing fromassets.csvand derive discreteAssetCapacityfrom either explicitnum_units, processunit_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 newnum_unitscolumn.
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.
5fb147d to
02d9e30
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1480 +/- ##
=======================================
Coverage 90.02% 90.02%
=======================================
Files 60 60
Lines 8558 8562 +4
Branches 8558 8562 +4
=======================================
+ Hits 7704 7708 +4
Misses 535 535
Partials 319 319 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
db5b58e to
6cef7f2
Compare
dalonsoa
left a comment
There was a problem hiding this comment.
The code looks OK, so approving, but I do not understand the use case. See my comment below.
| - name: num_units | ||
| type: integer | ||
| description: The number of units comprising the asset | ||
| notes: | | ||
| Optional. For processes with a `unit_size`, if omitted it is calculated by rounding the | ||
| capacity up to the nearest whole unit. For processes without a `unit_size`, if provided it | ||
| determines the unit size; otherwise the asset is represented as one unit. Must be >0. |
There was a problem hiding this comment.
I'm not entirely sure about the purpose of this parameter, to be honest. If a process has unit_size, the number of units can be calculated out of it, as described. And if not, the number of units is one, also as described. So, why giving the option of indicating the number of units manually? It seems like adding another way of confusing the user.
There was a problem hiding this comment.
Agree it's confusing but it's what Adam wants. Two reasons:
- For processes with a defined
unit_size, relying onunit_sizehere requires capacities to be an exact multiple ofunit_size, otherwise the data is incoherent (capacities will be rounded up so that everything works, but this fundamentally changes the system so should be avoided). Definingnum_unitshere allows the data to be coherent without changing overall capacities - For processes without a defined
unit_size,num_units=1is just a default (which we may remove in the future). Specifyingnum_unitsallows these assets to be "divisible", in the sense that they do not have to be decommissioned in one go (which was not possible before)
Perhaps will make more sense in the context of #1483, which also clarifies the documentation a bit.
There was a problem hiding this comment.
OK, I see the second point. But the first one feels a bit dodgy.
Let's take the usual example of wind turbines. You have that each turbine has 10 kW of capacity (a defined process with specific costs, etc). A user might ask for 45 kW of capacity, which means 5 turbines - and hence an actual capacity of 50 kW. If the user then says I want 9 units because of reasons, that results in a unit size of 5 kW, which is not what the process represents. I feel this is way less realistic that rounding up to the closest whole number of units...
There was a problem hiding this comment.
I don't disagree, but at least now we're giving the user a choice between two imperfect solutions 🤷
Description
This is the first step on the way to making all assets divisible (#1441). This PR makes all assets provided in
assets.csvdivisible (changing capacity fromContinuoustoDiscrete). Since not all processes have a definedunit_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 definedunit_size,num_unitstakes precedence. Ifn_unitsis not specified, the behaviour is essentially equivalent to how it currently is: split processes withunit_sizeaccording to this, and processes withoutn_unitsremain non-divisible (i.e. discrete capacity with a single unit). For now, I've omitted this column from the example models, so the results are unchanged (Note: this does affect the output files, but only because it changes thenum_unitscolumn inasset_capacities.csv. Total capacities, flows and prices should be unchanged). In the future, it would probably be worth changing this to make the example models more realistic.Eventually I want to drop
AssetCapacity::Continuousentirely, 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
Key checklist
$ cargo test$ cargo docpresent in the previous release
Further checks