Fix warning about assets commissioned before simulation start#1259
Fix warning about assets commissioned before simulation start#1259
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the warning emitted when a user-defined asset is already decommissioned by the time it would be commissioned, so the warning reports the decommission year (rather than an often-misleading lifetime) per issue #1220.
Changes:
- Rewrite the warning message in
AssetPool::commission_newto include the asset’s decommission year (max_decommission_year). - Remove the lifetime value from that warning to avoid confusion when
max_decommission_yearoverrides lifetime.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "User asset '{}' with commission year {} was decommissioned in {}, before \ | ||
| the start of the simulation", | ||
| asset.process_id(), |
There was a problem hiding this comment.
The warning text says "before the start of the simulation", but this branch can also trigger in later milestone years (e.g., an asset with commission_year == year and max_decommission_year == year). In that case the message would be misleading/contradictory. Consider wording it relative to the current milestone year (include year in the message), e.g. "... was decommissioned in {max_decommission_year}, so it is not active in milestone year {year}".
There was a problem hiding this comment.
I guess this would happen if the user set commission_year and max_decommission_year for an asset to the same year, which would be a strange thing to do, but we don't ban in - maybe we should?
There was a problem hiding this comment.
I guess technically we don't know the year that the asset was decommissioned, as we're not modelling the years before the simulation - we only know the maximum decommission year. So maybe soften this a bit, e.g. "Asset x with maximum decommission year y was decommissioned before the start of the simulation"
There was a problem hiding this comment.
I guess this would happen if the user set
commission_yearandmax_decommission_yearfor an asset to the same year, which would be a strange thing to do, but we don't ban in - maybe we should?
True! I can't think of a sensible reason why a user would want to do this. There may be historical data where assets are commissioned and decommissioned within a year, but these will never have any affect on the MUSE2 simulation, so there's no point in including them. This is different to assets decommissioned before the simulation start, where they also won't have an affect, but could do if you decide to look at a different set of milestone years. So let's just forbid it. I'll do that now.
I guess technically we don't know the year that the asset was decommissioned, as we're not modelling the years before the simulation - we only know the maximum decommission year. So maybe soften this a bit, e.g. "Asset x with maximum decommission year y was decommissioned before the start of the simulation"
The thing is, we kind of do know the year it was decommissioned. Assets commissioned before the simulation start are only counted as decommissioned if max_decommission_year is less than or equal to the first milestone year, so we're treating them as if they can't be decommissioned by agents until the simulation begins. Basically, the semantics of max_decommission_year are slightly different depending on whether it's before or after the simulation start. It's a bit weird, but I think this is the approach we came up with with @martinstringer in #916.
There was a problem hiding this comment.
The thing is, we kind of do know the year it was decommissioned. Assets commissioned before the simulation start are only counted as decommissioned if
max_decommission_yearis less than or equal to the first milestone year, so we're treating them as if they can't be decommissioned by agents until the simulation begins. Basically, the semantics ofmax_decommission_yearare slightly different depending on whether it's before or after the simulation start. It's a bit weird, but I think this is the approach we came up with with @martinstringer in #916.
I was basically saying that, for example, if a simulation starts in 2030 and we have an asset with a max_decommission_year of 2010, we don't know for sure that the asset was definitely decommissioned in 2010 and not before (nor does it matter), just that it can't possibly be around in 2030. But you're saying that if the max_decommission_year is before the start of the simulation then that is the decommission year - right?
I don't really have an issue with this, just that if the only reason to have a slightly complicated definition of max_decommission_year is for the purposes of this message, then maybe we can get around this by softening the language of the message.
| asset.process_id(), | ||
| asset.commission_year, | ||
| asset.process_parameter.lifetime | ||
| asset.max_decommission_year |
There was a problem hiding this comment.
This uses direct field access (asset.max_decommission_year) while nearby code uses the getter max_decommission_year(). For consistency (and to avoid bypassing any future logic in the accessor), use the method in the warning args as well.
| asset.max_decommission_year | |
| asset.max_decommission_year() |
6de75f8 to
2eccf45
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1259 +/- ##
=======================================
Coverage 89.74% 89.74%
=======================================
Files 57 57
Lines 8195 8195
Branches 8195 8195
=======================================
Hits 7355 7355
Misses 544 544
Partials 296 296 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tsmbland
left a comment
There was a problem hiding this comment.
Looks good! Just some small nitpicks
| "User asset '{}' with commission year {} was decommissioned in {}, before \ | ||
| the start of the simulation", | ||
| asset.process_id(), |
There was a problem hiding this comment.
I guess this would happen if the user set commission_year and max_decommission_year for an asset to the same year, which would be a strange thing to do, but we don't ban in - maybe we should?
| "User asset '{}' with commission year {} was decommissioned in {}, before \ | ||
| the start of the simulation", | ||
| asset.process_id(), |
There was a problem hiding this comment.
I guess technically we don't know the year that the asset was decommissioned, as we're not modelling the years before the simulation - we only know the maximum decommission year. So maybe soften this a bit, e.g. "Asset x with maximum decommission year y was decommissioned before the start of the simulation"
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "User asset '{}' with commission year {} was decommissioned in {}, before \ | ||
| the start of the simulation", | ||
| asset.process_id(), | ||
| asset.commission_year, |
There was a problem hiding this comment.
The warning still hard-codes "before the start of the simulation", but commission_new is called for every milestone year. If a user asset has commission_year between milestone years, it can first be considered in a later milestone year and still hit this branch (when max_decommission_year <= year), even though that later year is not the simulation start. Consider wording this relative to the current milestone year (include year in the message) and/or refer to the max decommission year rather than asserting it "was decommissioned in" that year.
| "User asset '{}' with commission year {} was decommissioned in {}, before \ | |
| the start of the simulation", | |
| asset.process_id(), | |
| asset.commission_year, | |
| "Skipping user asset '{}' with commission year {} in milestone year {} \ | |
| because its max decommission year is {}", | |
| asset.process_id(), | |
| asset.commission_year, | |
| year, |
| let max_decommission_year = | ||
| max_decommission_year.unwrap_or(commission_year + process_parameter.lifetime); | ||
| ensure!( | ||
| max_decommission_year >= commission_year, | ||
| "Max decommission year must be after/same as commission year" | ||
| max_decommission_year > commission_year, | ||
| "Max decommission year must be greater than commission year" | ||
| ); |
There was a problem hiding this comment.
This changes validation to reject max_decommission_year == commission_year (previously allowed). Since this is user-facing input validation, it would be good to add a regression test asserting that creating an asset with max_decommission_year equal to commission_year returns an error (and ideally checks the error message), so the intended constraint doesn’t get loosened unintentionally later.
| <!-- TODO --> | ||
|
|
||
| ## Bug fixes | ||
|
|
||
| - Fix misleading warning message for assets decommissioned before simulation start ([#1259]) |
There was a problem hiding this comment.
Release notes mention the warning-message change, but this PR also tightens validation by rejecting assets where max_decommission_year == commission_year. Since that can cause previously accepted inputs to error, consider noting it explicitly here (and potentially under "Breaking changes" if you consider it a breaking input change).
| <!-- TODO --> | |
| ## Bug fixes | |
| - Fix misleading warning message for assets decommissioned before simulation start ([#1259]) | |
| - Assets where `max_decommission_year == commission_year` are now rejected during validation. Inputs | |
| that were previously accepted with equal commission and max decommission years may now error | |
| ([#1259]) | |
| ## Bug fixes | |
| - Fix misleading warning message for assets decommissioned before simulation start, and tighten | |
| validation to reject assets where `max_decommission_year == commission_year` ([#1259]) |
Description
Users are permitted to define assets in
assets.csvthat are decommissioned before the simulation starts. If this happens, users are warned, in case it was a mistake, but the warning message reports the process lifetime, which is misleading asmax_decommission_yearmay be set to more or less than this value.Instead of correcting the lifetime stated in the warning, I thought it was clearer to rewrite the message to include the decommission year directly.
(I just went through this issue with @mjademitchell and @AdrianDAlessandro as a demo.)
Fixes #1220.
Type of change
Key checklist
$ cargo test$ cargo docpresent in the previous release
Further checks