fix: correct guard order in OsemosysClass.RYE() to prevent phantom Em…#456
Open
lil-aditya wants to merge 1 commit intoEAPD-DRB:mainfrom
Open
fix: correct guard order in OsemosysClass.RYE() to prevent phantom Em…#456lil-aditya wants to merge 1 commit intoEAPD-DRB:mainfrom
lil-aditya wants to merge 1 commit intoEAPD-DRB:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a data-corruption bug in the OSeMOSYS JSON parser for RYE() by aligning its guard-condition ordering with the established pattern used by sibling pivot/parsing methods in OsemosysClass.
Changes:
- Reordered the
RYE()loop guards so the'EmisId'exclusion check runs before initializingRYE[param][sc][year]. - Prevents creating a phantom
RYE[param][sc]['EmisId'] = {}entry during parsing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
616
to
619
| if (year != 'EmisId'): | ||
| if year not in RYE[param][sc]: | ||
| RYE[param][sc][year] = {} | ||
| RYE[param][sc][year][o['EmisId']] = val |
There was a problem hiding this comment.
PR description references running python scripts/reproduce_rye_bug.py, but that file does not exist in the repository/PR branch. Either add the script to scripts/ or update the validation instructions to point at an existing reproduction path so reviewers can verify the fix.
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.
Existing related work reviewed
RYE()Overlap assessment
RYC()guard order; this PR fixes the same bug pattern in theRYE()method which was missedWhy this PR should proceed
RYE()parser is the only remaining method inOsemosysClasswith the inverted guard order. All sibling methods (RYC,RYT,RYTs,RYTTs,RYCTs, etc.) already use the correct pattern. This is a data-corruption bug that creates a phantom'EmisId'key in the parsed emission data, which causesKeyErrorcrashes ingen_RYE()during solver data file generation.Summary
OsemosysClass.RYE()(line 608) so theyear != 'EmisId'exclusion check runs before the dict-entry creation, matching the canonical pattern used by every other parser method in the class.if year not in RYEbeforeif year != 'EmisId') creates a phantom empty dict entryRYE[param][sc]['EmisId'] = {}which (1) pollutes the data structure, (2) causesKeyErrorcrashes whengen_RYE()iterates year keys, and (3) can produce corrupted solver.datfiles.Validation
Reproduction steps:
python scripts/reproduce_rye_bug.pyfrom theMUIOGO/root[BUGGY]section showing phantom'EmisId'key andKeyErrorcrashes[FIXED]section showing clean year-only keysBefore (buggy):
After (fixed):
Guard order CORRECT — matches RYC, RYT, etc.
if (year != 'EmisId'):
if year not in RYE[param][sc]:
RYE[param][sc][year] = {}
RYE[param][sc][year][o['EmisId']] = val