Clean up how we specify default values for model parameters#1260
Clean up how we specify default values for model parameters#1260
Conversation
Let's make it consistent with other parameters. This way is less ambiguous.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1260 +/- ##
==========================================
+ Coverage 89.74% 89.76% +0.01%
==========================================
Files 57 57
Lines 8195 8210 +15
Branches 8195 8210 +15
==========================================
+ Hits 7355 7370 +15
Misses 544 544
Partials 296 296 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Refactors how model.toml parameter defaults are defined by moving from per-field default macros to a Default implementation on ModelParameters, and aligns capacity_margin with the codebase’s unit-typed parameters (Dimensionless) for consistency.
Changes:
- Replace macro-based per-field defaults in
ModelParameterswith#[serde(default)]+ a customDefaultimpl, while validating requiredmilestone_yearspost-deserialization. - Change
capacity_marginfromf64toDimensionlessin model parameters and propagate the type change into dispatch optimisation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/simulation/optimisation.rs |
Updates DispatchRun/capacity variable plumbing to accept Dimensionless capacity_margin, converting to f64 only at the solver-boundary. |
src/model/parameters.rs |
Introduces ModelParameters: Default to centralize defaults, removes old default macros, improves the milestone_years validation message, and makes capacity_margin unit-typed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6a006c0 to
6684455
Compare
Aurashk
left a comment
There was a problem hiding this comment.
Looks like an improvement to me
Description
I started work on #420, but thought the code could use a little clean-up first, so I've opened this as a separate PR.
The way we currently define default values for model parameters (as read from
model.toml) is with a couple of macros insrc/model/parameters.rs, but this ends up being a bit verbose and ugly. I've cleaned it up by using a customDefaultimplementation for theModelParametersstruct instead, which lets us list the default values in a more natural way. The downside of this approach is that it does mean we need to define a "default" value formilestone_years, even though this parameter is not optional, then verify that a value was provided after the fact. I think it's worth it overall though.While I was at it I changed the
capacity_marginparameter to be aDimensionlessrather than anf64, to make it consistent with the other parameters. It's good to be explicit that it represents a ratio, not some physical value.Type of change
Key checklist
$ cargo test$ cargo docpresent in the previous release
Further checks