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

allowing geometry to be fully made via constructor #2602

Merged

Conversation

shimwell
Copy link
Member

@shimwell shimwell commented Jul 17, 2023

Hoping to contribute to @eepeterson mission of being able to entirely make the classes through the constructor. I thought I should have a go at allowing the geometry class to be specified through the constructor.

Checklist

  • I have performed a self-review of my own code
    - [ ] I have run clang-format on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

I have added tests and run pytest with the pytest tests/unit_tests/test_geometry.py as the openmc.Geometry is the class that has been changed.

@shimwell shimwell requested a review from eepeterson July 17, 2023 12:42
Comment on lines 26 to 27
**kwargs : dict, optional
Any keyword arguments are used to set attributes on the instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

For two parameters, this almost doesn't feel like it's worth it over just explicitly adding merge_surfaces and surface_precision

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe @eepeterson was keen on getting all the classes fully made from constructors as part of the repr, str and then xml to python code idea. But admittedly I could have misunderstood

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I was not clear. I meant rather than adding the catch-all **kwargs as an argument, explicitly add merge_surfaces and surface_precision arguments. So @eepeterson's goal can still be attained.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah sorry, you were clear I just miss read. I changed to explicitly adding these args

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for starting this @shimwell! To follow on to @paulromano's comment: generally I think **kwargs should be used for pass through arguments to the superclass if necessary, whereas explicit keyword arguments are best for the class itself (especially if they are small in number).

@@ -39,11 +39,11 @@ class Geometry:

"""

def __init__(self, root=None):
def __init__(self, root : openmc.UniverseBase = None, merge_surfaces: bool = False, surface_precision: int = 10):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a policy on how to write method/constructor signatures with type annotations yet? With type annotations (and default values in particular) I find this style a bit hard to read unless there are only 1 or 2 parameters. Since this line seems to be getting a bit longer than the 90ish rule, perhaps 1 argument per line, but I'd be curious to hear other perspectives. I think my preference is one per line with whitespace up the the ( but there are good arguments for other styles out there

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed the code to multi line args and it does look better imo but I'm always keen automate this stuff and adopt whatever flake8 or black decides

openmc/geometry.py Outdated Show resolved Hide resolved
@paulromano paulromano enabled auto-merge (squash) July 23, 2023 19:40
@paulromano paulromano merged commit d47e9a1 into openmc-dev:develop Jul 23, 2023
16 checks passed
stchaker pushed a commit to stchaker/openmc that referenced this pull request Oct 25, 2023
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants