-
Notifications
You must be signed in to change notification settings - Fork 514
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
Various changes in Python API #667
Conversation
I will review this later today, though it might be nice if @smharper can help out, particularly with regards to As for the testing your new plotting methods, I feel your pain with matplotlib. I'm not sure how much you looked into running diffs on matplotlib-generated figures, but it is worse than you might imagine. The images generated on different machines with the exact same install of matplotlib (and the exact same All of our tests for the plotting module in OpenMOC by generating an RGB histogram of the pixel in a test/reference plot and then diff'ing the histogram (as recommended on Stack Overflow) as illustrated here. This hacky solution is known to miss small but perhaps meaningful deviations in figures (link), but will at least catch any medium to large errors. |
@@ -532,23 +474,6 @@ def __eq__(self, other): | |||
def __ne__(self, other): | |||
return not self == other | |||
|
|||
def __deepcopy__(self, memo): | |||
existing = memo.get(id(self)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious - is this line included in the default implementation? Seeing this is now sparking my memory of one of the reasons I went about implementing __deepcopy__
methods back in the day - to boost performance by eliminating redundant copies of objects in CSG trees (i.e., this line of code). I want to say that this is not included in the default implementation, but I'm not sure. Regardless, I don't think it matters for the Cross*
and Aggregate*
classes anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also may be wrong, the memo
may be used in this way by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as far as I can tell memo
is used this way by default. Here's proof:
In [1]: import openmc, copy
In [2]: c = openmc.Cell()
In [3]: l = [c, c]
In [4]: l_copy = copy.deepcopy(l)
In [5]: [id(x) for x in l_copy]
Out[5]: [140129480509648, 140129480509648]
In [6]: memo = {id(c): 'See Will, I told you so'}
In [7]: l_copy2 = copy.deepcopy(l, memo)
In [8]: l_copy2
Out[8]: ['See Will, I told you so', 'See Will, I told you so']
@wbinventor I only looked into diffing plots enough to know that it is painful, not to what degree :) Good to know! And sounds like we can learn from your experience when the time comes. |
# Randomly sample location | ||
x = random.uniform(-0.5, 0.5) | ||
y = random.uniform(-0.5, 0.5) | ||
z = random.uniform(-0.5, 0.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can sample particles that are split by the reflective boundary condition. These should be changed to something like
x = random.uniform(-0.5+radii[-1], 0.5-radii[-1])
Or you could move the reflective BCs outwards by radii[-1]
@paulromano, this implementation has all of the TRISO surfaces on the same universe level. I would really recommend using a two-level approach where the upper universe only has one surface and cell per TRISO. That cell is filled with a lower universe containing the rest of the surfaces. There are two big advantages to this method: The I have a rough example implementation in my repo. The test you added runs twice as many neutrons/s with these changes. I suspect the speedup will be even larger for higher packing fractions. |
@smharper Nice idea with the multiple universes! Though to be clear, even with the current scheme there should still only be one surface per TRISO that is checked during |
Hmm, I see now that you're right about |
Well, since the single universe (and cells within) for TRISOs gets reused as a particle is tracking through, it should be a little more cache-friendly all around. |
I did profile the code. It turns out that |
@smharper Your comments have been addressed. I also added a commit fixing an issue with |
|
||
Parameters | ||
---------- | ||
outer_radius : int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int -> Real
I'm happy. @wbinventor, have all of your concerns been addressed? |
This ship is ready to sail! |
Thanks guys! Can we also sail my one-liner in #672? |
Shesh, you give 'em an inch... |
This pull request makes a few changes/additions:
Universe.plot
now has two extra arguments,colors
(dictionary mapping cells/materials to RGB(A) tuples) andfilename
(for saving plot to file instead of display).__deepcopy__
methods have been removed since they don't do anything special. I'm holding off on making more radical changes like autogenerating new IDs for a deepcopy since we don't have consensus on it yet.openmc.model
subpackage was added with aTRISO
class that helps ease modeling TRISO fuel particles. There's also acreate_triso_lattice
function which is loosly based on @smharper's one-off script for placing TRISO particles in a lattice, duplicating them where they overlap lattice boundaries. You can look at the new test_triso to see how the class and function are used.@wbinventor Note that I've held off on adding a test for the Python plotting capabilities mostly due to the fact that there's no good way to hash a PNG (and writing raw RGBA data from matplotlib was broken apparently). The other reason I'm deferring is that we should really decide what we want to do with respect to unit testing.