Skip to content

Apply memoization in get_all_universes - #2995

Merged
paulromano merged 6 commits into
openmc-dev:developfrom
pshriwise:speedy-univ
May 24, 2024
Merged

paulromano merged 6 commits into
openmc-dev:developfrom
pshriwise:speedy-univ

Conversation

@pshriwise

Copy link
Copy Markdown
Contributor

Description

While working on a model with TRISO compacts, @aprilnovak noticed that the Geometry.get_all_universes method was taking a long time (3+ hours) -- preplexing as the get_all_cells call was taking less than a second.

It turns out that we weren't using the memoization objects we have in place for this call/chain-of-calls in the geometry objects. This PR adds the use of memoization for that call.

I haven't added any tests here as the set of tests we have in place exercises these methods significantly -- they should just be faster now.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) 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)

@pshriwise
pshriwise requested a review from paulromano May 9, 2024 16:56
@pshriwise

pshriwise commented May 9, 2024 •

Copy link
Copy Markdown
Contributor Author

One note here is that the pattern:

if memo and self in memo:
    return {}

was pre-existing in other calls using memoization. I stuck with this here for consistency even though this might be more explicit and better:

if memo is not None and self in memo:
    return {}

Happy to update this across the board at the reviewer's request.

@pshriwise pshriwise changed the title Speedy univ Apply memoization in get_all_universes May 10, 2024

@paulromano paulromano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing this @pshriwise! Two things seem a little weird to me in the implementation but hopefully it's easy to fix:

Comment thread openmc/universe.py Outdated
Comment thread openmc/geometry.py Outdated

@paulromano paulromano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @pshriwise!

@paulromano
paulromano enabled auto-merge (squash) May 24, 2024 22:38
@paulromano
paulromano merged commit 25e47de into openmc-dev:develop May 24, 2024
church89 pushed a commit to openmsr/openmc that referenced this pull request Jul 18, 2024
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
apingegno pushed a commit to apingegno/openmc that referenced this pull request May 7, 2026
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.

2 participants