Fix manually set default importances not printed#921
Merged
Conversation
…n-newly-created-cells
tjlaboss
reviewed
Mar 9, 2026
Collaborator
Author
|
Doc build is failing due to a security restriction of a linkcheck. The URL is still valid. |
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.
Pull Request Checklist for MontePy
Description
This fixes the bug where cells made from scratch almost never prints their importance in the output no matter if the importance were manually set (#892). Turns out that the parameter
self._explicilty_setis set toTruewhen the official setters are used, however, this value is never checked for formatting. To fix this was rather trivial.However this issue brought up a question of behavior. In the test case
cell.importance.all=1.0is used on an unattached cell. It's assumed that this would set all importance. However, the documentation says that this only works on the particles in the problem. The code assumed that if the cell is not attached to a problem thatcell.importance.allhas no effect. This is rather intuitive. So I decided on the following behavior. Is this correct?importance.allsets the importance for every (~37) particle types.problem.modebefore printing. This is to avoid ~37 separateimp:X=1clauses.Finally, I noticed that in the tests for cell 4 onlyimportance.neutronis set but the expected behavior is to print the default value forimportance.photon. I decided to ignore this for now, and we can discuss.I threw in a test to replicate #913, and found it passed. So two birds one stone.
All or Nothing infrastructure
As we discussed below cell importances have to be an all or nothing affair. How I decided to implement this was to make it an infrastructure that could be, but probably shouldn't be, used by any
CellModifierclass.montepy.print_in_data_blockhas private getters and setters to set a boolean flag in a dictionary by class prefix.Importance._explicitly_setto be a property that update that problem level flag whenever changed.CellModifierlogic to allow this flag to override the other logic.Dict like behavior update
In developing I thought
Importance.items()would be helpful, so I addedImportance.keys(),Importance.values()andImportance.items().Fixes #892, fixes #913
General Checklist
blackversion 25 or 26.LLM Disclosure
Are you?
Were any large language models (LLM or "AI") used in to generate any of this code?
Documentation Checklist
First-Time Contributor Checklist
pyproject.tomlif you wish to do so.Additional Notes for Reviewers
Ensure that:
📚 Documentation preview 📚: https://montepy--921.org.readthedocs.build/en/921/