Clean up how we specify default values for model parameters#1260
Open
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:
|
Contributor
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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