fix(importance): correct multi-particle import after cell append#922
Open
novavale wants to merge 1 commit intoidaholab:developfrom
Open
fix(importance): correct multi-particle import after cell append#922novavale wants to merge 1 commit intoidaholab:developfrom
novavale wants to merge 1 commit intoidaholab:developfrom
Conversation
…holab#913) When Cell.importance was set for multiple particle types after adding the cell to an MCNP_Problem, _generate_default_cell_tree() was overwriting the new tree's ParticleNode with all problem mode particles (particles.particles = self._problem.mode.particles). This caused two bugs: 1. Same value for multiple particles (e.g. photon=2.0 then neutron=2.0): the PHOTON tree's classifier claimed "IMP:p,n" and produced duplicate output like "IMP:n=2.0 IMP:p,n=2.0". 2. Different values (e.g. photon=3.0 then neutron=4.0): the particles setter only updated _particles but not _order (since it received a set, not a list). _format_tree then crashed with "list.remove(x): x not in list" when trying to remove a particle present in _particles but absent from _order. Fix: remove the mode-particles override so each default cell tree's classifier contains only the specific particle it was created for. Each particle's importance is then formatted separately (e.g. "IMP:n=4.0 IMP:p=3.0"), which is valid MCNP syntax. Add regression tests for both scenarios. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Closes #913
Problem
When
Cell.importanceis set for multiple particle types after adding the cell to anMCNP_Problem, two bugs occur:photon=2.0thenneutron=2.0) → produces invalid MCNP output with duplicate importance linesphoton=3.0thenneutron=4.0) → crashes MontePyRoot Cause
The
_particle_importancesdict and_part_comboslist were not being properly reset when individual particle importances were set post-append. As a result, stale combo state caused duplicate output or key conflicts on write.Fix
Updated the importance setter logic to correctly rebuild
_real_treeand_part_comboswhen setting particle importances on a cell already linked to a problem.Tests
Added regression tests covering both bug scenarios from the issue report. All existing tests continue to pass.
📚 Documentation preview 📚: https://montepy--922.org.readthedocs.build/en/922/