Skip to content
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

Implement more detailed __lt__ for components. #1882

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft

Conversation

mgjarrett
Copy link
Contributor

@mgjarrett mgjarrett commented Sep 16, 2024

What is the change?

Fall back to getCircleInnerDiameter for comparison when sorting components when getBoundingCircleOuterDiameter is equivalent.

Why is the change being made?

Components on a block are sorted by their getBoundingCircleOuterDiameter. Sometimes, two components have the same outer diameter, in which case the sorting done by __lt__ will depend on the order of comparison. i.e.,

a < b evaluates to False
b < a also evaluates to False
b == a evaluates to True, even though the two components are not necessarily identical, they only have one identical dimension.

sorted([a, b]) != sorted([b, a]) even though b and a are not identical.

Close #1875


Checklist

  • The release notes have been updated if necessary.
  • The documentation is still up-to-date in the doc folder.
  • The dependencies are still up-to-date in pyproject.toml.

Copy link
Contributor

@drewj-tp drewj-tp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of the 21 files changed here, maybe three of them are actually related to the heart of this PR and touch the __lt__ changes.

They're not bad changes per se, but they are nearly entirely import related changes: sorting of imports, breaking multiple imports, importing just the module not the things needed in the module. They just added extraneous diffs to this PR.

What can we collectively do to avoid this? There's probably some linter / formatting config we can add, maybe some "blessed" vs code related settings we can advertise. But, these changes make it hard to agree that "this PR has one idea or purpose" with the extra, unrelated changes

armi/reactor/blocks.py Outdated Show resolved Hide resolved
armi/reactor/__init__.py Outdated Show resolved Hide resolved
armi/reactor/components/__init__.py Outdated Show resolved Hide resolved
Comment on lines 190 to 205
def getCircleInnerDiameter(self, Tc=None, cold=False):
"""
Approximate the component as circular; i.e., inner diameter is zero.

Parameters
----------
Tc : float
Ignored for this component
cold : bool, optional
If True, compute the area with as-input dimensions, instead of thermally-expanded.

Notes
-----
Tc is not used in this method for this particular component.
"""
return 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an okay thing for a shaped component to have to define on their own. Maybe a DerivedShape is the only exception.

Saying this because we try/catch a NotImplementedError below so if Component.getCircleInnerDiameter is required for components, we'd be okay in that context.

But that could be a larger change that is likely better served outside this PR.

Non-blocking comment. If there's traction I can make a ticket

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption for the unshaped component is to return the smallest possible bounding circle outer diameter, i.e., assume the component has a disk shape. It seems consistent with that assumption to assume that the inner diameter is 0.0.

The exception is caught in __lt__, but only for the purpose of producing a clearer error message. The error is still raised and the code crashes. So we still need to be able to sort UnshapedComponents.

armi/reactor/components/volumetricShapes.py Show resolved Hide resolved
armi/reactor/tests/test_components.py Outdated Show resolved Hide resolved
armi/reactor/tests/test_components.py Outdated Show resolved Hide resolved
armi/reactor/tests/test_components.py Outdated Show resolved Hide resolved
armi/reactor/tests/test_components.py Outdated Show resolved Hide resolved
armi/reactor/tests/test_components.py Outdated Show resolved Hide resolved
@mgjarrett
Copy link
Contributor Author

Of the 21 files changed here, maybe three of them are actually related to the heart of this PR and touch the __lt__ changes.

They're not bad changes per se, but they are nearly entirely import related changes: sorting of imports, breaking multiple imports, importing just the module not the things needed in the module. They just added extraneous diffs to this PR.

What can we collectively do to avoid this? There's probably some linter / formatting config we can add, maybe some "blessed" vs code related settings we can advertise. But, these changes make it hard to agree that "this PR has one idea or purpose" with the extra, unrelated changes

Sorry, I'm in the middle of working on this. The root of the problem is that I ran into a circular import, and all of the import changes are related to fixing the circular import. It started small and then I went down a rabbit hole -- I'll probably break those changes out into a separate PR now.

@mgjarrett mgjarrett marked this pull request as draft September 16, 2024 15:34
Fix getBoundingCircleOuterDiameter to return a diameter instead of a
radius.
@john-science john-science added the feature request Smaller user request label Sep 16, 2024
@@ -20,8 +20,7 @@
"""
import math

from armi.reactor.components import ShapedComponent
from armi.reactor.components import componentParameters
from armi.reactor.components.component import ShapedComponent, componentParameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mike, can we fix your IDE?

I don't particularly like these changes, and they make your PRs more muddled to read. Like... you didn't actually touch this file.

#sorry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. I was able to turn it off, so I'll go through and revert these import changes.

doc/release/0.4.rst Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Smaller user request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement more detailed __lt__ for component sorting
3 participants