-
Notifications
You must be signed in to change notification settings - Fork 249
Correct constant-species index mapping in SimpleReactor #2867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical bug in SimpleReactor.get_const_spc_indices() that prevented constant species from being properly identified and treated as constant during simulation. The original implementation had two major issues: it reused the same loop variable spc in nested loops, and it incorrectly compared a string to a Species object (spc.label == spc instead of spc.label == name). As a result, species listed in const_spc_names were never actually marked as constant.
- Fixed variable shadowing in nested loops by using distinct variable names (
namefor const_spc_names,spcfor core_species) - Corrected the comparison logic to properly match species labels against constant species names
- Added early return for
Noneconst_spc_names and moved initialization outside the loop for clarity - Added a
breakstatement to stop searching once a match is found
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rmgpy/solver/simple.pyx | Fixed the get_const_spc_indices() method by correcting variable naming, comparison logic, and control flow |
| test/rmgpy/solver/simpleTest.py | Added unit test test_get_const_spc_indices() to verify that constant species names are correctly mapped to core species indices |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This is printed many times in the RMG log file
|
A test unrelated to this PR failed: Added another commit to check isclose() for |
Motivation or Problem
SimpleReactor.get_const_spc_indices()was possibly effectively broken:spc.label == spc, i.e. a string to a species object.As a result,
const_spc_indiceswas never populated and species listed inconst_spc_nameswere perhaps not actually treated as constant.Description of Changes
In
SimpleReactor.get_const_spc_indices():const_spc_namesandcore_species.spc.labelinstead ofspcitself.const_spc_indicesonce and append core-species indices when labels match.const_spc_namesisNone.Testing
A small unit test was added.
Reviewer Tips
In a small reactor run with a constant species, check that its amount stays fixed over time.