Fix availabilities validation for non-milestone years#935
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the validation logic for process availabilities to correctly handle cases where processes can be commissioned before the simulation's milestone years. The fix ensures that only milestone years (years >= base_year) require availability entries, while pre-milestone years are checked lazily when needed.
- Split validation into separate functions for milestone years and time slices
- Modified validation to only require entries for milestone years, not all process years
- Updated function signatures to pass the base_year parameter through the call chain
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/input/process/availability.rs | Core validation logic split and fixed to handle non-milestone years correctly |
| src/input/process.rs | Updated to pass base_year parameter to availability reading functions |
| src/input/process/flow.rs | Minor formatting fix removing trailing comma |
| src/asset.rs | Improved error message clarity for missing process availabilities |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| .years | ||
| .iter() | ||
| .copied() | ||
| .filter(|&year| year >= base_year); |
There was a problem hiding this comment.
The filtering logic for milestone years should be documented to clarify why only years >= base_year are considered milestone years, especially since this is a key part of the bug fix.
| time_slice_info | ||
| .iter_ids() | ||
| .filter(|ts| !map_for_region_year.contains_key(ts)) | ||
| .map(|ts| (region_id, year, ts)), |
There was a problem hiding this comment.
The tuple construction uses year directly, but year is of type &Year from the iterator. This should be *year to dereference the borrowed value for consistency with the tuple type expected.
| .map(|ts| (region_id, year, ts)), | |
| .map(|ts| (region_id, *year, ts)), |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #935 +/- ##
==========================================
- Coverage 84.93% 84.88% -0.06%
==========================================
Files 50 50
Lines 5323 5364 +41
Branches 5323 5364 +41
==========================================
+ Hits 4521 4553 +32
- Misses 574 579 +5
- Partials 228 232 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dalonsoa
left a comment
There was a problem hiding this comment.
This looks good to me.
Just to make sure I understand the implications, in your modified example, as the process start year is 2000 but the asset commission year is 2010, in the old way you would have needed to provide process availabilities for the whole range 2000-2010 + milestones, but now only is needed from 2010, right?
| model_dir: &Path, | ||
| processes: &ProcessMap, | ||
| time_slice_info: &TimeSliceInfo, | ||
| base_year: u32, |
There was a problem hiding this comment.
Oops! It's a pity there doesn't seem to be any Rust tooling to check these doc comments...
| iter: I, | ||
| processes: &ProcessMap, | ||
| time_slice_info: &TimeSliceInfo, | ||
| base_year: u32, |
There was a problem hiding this comment.
Same here. This function is missing details in the docstring, anyway.
Not quite. Imagine you have a simulation with milestone years [2020, 2030], a process with
Eventually we want to be able to include assets commissioned between milestone years and after the simulation too for completeness (#859). |
Description
Processes are required to have availabilities, flows and parameters defined for every combination of region and milestone year in which they can be commissioned. However, assets in
assets.csvare allowed to have acommission_yearbefore the simulation's start, provided it is not before a the process'sstart_yearand if this is the case then it makes validation tricky. You can provide availabilities for every year by puttingallin theyearcolumn, but if you want to supply entries for individual years instead and the process can be commissioned before the time horizon then you have to provide an entry for all of the possible years, which is horrid (e.g. if the simulation starts in 2020 but your process'sstart_yearis 2000, then you need entries for 2000, 2001, etc.). There's an analogous problem for flows (#934), but I think we need to improve the validation for flows anyway (#931) so I thought it made sense to hold off on tackling it until later.I originally thought I'd fixed this in #868 but clearly didn't test it properly. Oops.
I verified the fix worked by modifying the
simpleexample like so:Do we think it would be worth having one or more examples to exercise this part of the code? We could just have one example that has assets commissioned before the time horizon. We could later add assets commissioned between milestone years and after the time horizon when we've done #859. Thoughts? @tsmbland: this may relate to #655.
Fixes #866.
Type of change
Key checklist
$ cargo test$ cargo docFurther checks