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
Export of depletion results to openmc.Materials #1726
Conversation
Apologies in the delay getting to this. Been a wild few weeks on my end. To the matter at hand. I'm confused as to what PR should be reviewed for this feature: this or #1714. Is @rockfool is still working on their implementation? I'm not sure how I feel about having two PRs up for the same feature, especially with one being a fork of the other. I do like the fact that this pulls in information from a r = openmc.deplete.ResultsList.from_hdf(rfile)
burnable = r.export_materials()
all_mats = openmc.Materials.from_xml(mfile)
# or from Materials built by a script and not exported yet
all_mats.update(burnable)
all_mats.export_to_xml("materials.xml") is more verbose than the current PRs, but I think it yields a lot more control to the user / developer. For the case where new materials are added through burnup (refueling, reprocessing operations? maybe not) these may not exist in a file that has been currently exported. But this also could be some premature optimization / YAGNI |
I am also sorry for this delayed follow-up. I think we can proceed with this in parallel. And you (@drewejohnson ) can approve the one you like. |
Yeah, even in the refueling/reprocessing case, if it's anything like serpent, new materials are never added over the duration of the calculation. So, yeah, I mainly just put in this separate PR since @rockfool probably has lots of other stuff to do aside from address comments on that PR. Guess it should have gone in as a PR to your PR Jiankai, but since there are so few changes, I figured it would be easiest to just put in another. Anyways, yeah, IMO it's a bit YAGNI to add in that level of generality. If someone comes up on the user list asking for this feature, we'll know what to do--and it won't be very much work to rewrite this to accommodate. |
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.
@rockfool please see the comments here if you wish to incorporate them into #1714
I've made some recommendations for how I believe this PR could be improved. One big thing that both PRs are missing is testing.
I will bring up the modular approach from before one more time, since it would be my preference. That would allow easier testing in my opinion: can we get the burnable materials from the result file. There is some overlap, and the functionality would not be fully complete w/o the Materials.update
feature. Which I'm happy to take on
e7a7e3a
to
a7ce070
Compare
Could I get some suggestions on how to test this? Not sure if it should be in regression or units. Given the dependence on an initial materials.xml and a depletion statepoint file, maybe this would fit nicely into an existing test. Not familiar enough to say where though. |
I think our depletion regression test would be the most complete place to test this method. We don't have a To explain some of my comments, or the motivation therein, I recently was burned by a depletion simulation where a non-performance critical part ended up taking an inordinate amount of the simulation time. So that was fresh in my mind when writing the review. I'll address the comments directly, but I wanted to put that forward first |
Ah, that's very interesting Drew, I wouldn't have guessed. Which piece was slowing you down a lot? This piece may be good for optimization if anyone starts doing multiple statepoint calculations at different depletion states. I'll have to test performance on a larger problem at some point. Anyways, I'll come back to this PR this weekend! Thanks for the prompt responses. |
To clarify, it wasn't OpenMC. I would be very interested in timing breakdowns of how OpenMC performs when depleting large problems but haven't had the chance to tackle that yet. If you find something interesting, please pass it along And just ping me when this is ready for another review 🙂 |
@drewejohnson alright, the more specific exceptions are in now, as well as a test for the ResultsList->openmc.Materials conversion. The test just makes a materials.xml for the initial step, then creates a materials.xml for the final step, and ensures that the SHA512 of each file matches. I verified the XML files look as expected, too. |
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.
Thanks for the updates @gridley! I've got some comments on formatting of docstrings and testing, primarily moving from hash-based tests.
Also, can you merge in the latest develop to pick up the CI changes?
# Check that the conversion of the final step depleted materials XML | ||
# file hashes to what we expect. | ||
output_xml_file = 'last_step_materials.xml' | ||
last_step_materials.export_to_xml(path=output_xml_file) | ||
with open(output_xml_file, 'rb') as result_file: | ||
result_file_hash = hashlib.sha512() | ||
for line in result_file: | ||
result_file_hash.update(line) |
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.
The hash based testing is nice because we don't have to track the potentially large xml file generated by this test. But it can hide the reason why this test is failing (#1338). I'd prefer checking if the strings are identical directly. And (optionally) using difflib.unified_diff
to print the difference if two files differ
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.
Personally, I'd prefer not to make this change. Because this is a very minor piece of OpenMC, I would like to minimize the overall LOC we add to the repo in implementing this functionality.
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'd prefer we not add more hashed results if at all possible. How big is the raw data we're talking about here?
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.
Not big, I am working on changing it to plaintext this morning.
d4cfd47
to
9a01a6e
Compare
@drewejohnson Do you definitely want me to rewrite the test to not use hashing? I really doubt this is going to fail in the future, and wouldn't even be terribly hard to debug if it does fail, which is why I initially elected to use hashing rather than a direct diff. |
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.
@gridley I brought up the hash based testing because I know it has caused grief in the past. Enough that an issue was created to move away from it.
I understand your sentiment about not wanting to track in the xml file. Just not sure how to square the inclusion of a hash-based test with a desire from other developers to move away from them. But we also haven't made any movement away from them yet...
I know this PR has been up for a bit with the testing in but that was over the holiday break. I'd like to give anyone with some stronger opinions on #1338 and it's implications to this PR another day to chime in
cc @openmc-dev/technical-committee
Oh darn. I seem to have not kept up with the trend of moving away from hash-based testing. I have been frustrated deciphering hash-based test failures in the past as well. If that is a general movement with OpenMC, I am very happy to follow along. |
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.
Thanks for taking this on @gridley! This is a really useful addition for people working on depletion simulations. A few minor comments I have:
# Check that the conversion of the final step depleted materials XML | ||
# file hashes to what we expect. | ||
output_xml_file = 'last_step_materials.xml' | ||
last_step_materials.export_to_xml(path=output_xml_file) | ||
with open(output_xml_file, 'rb') as result_file: | ||
result_file_hash = hashlib.sha512() | ||
for line in result_file: | ||
result_file_hash.update(line) |
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'd prefer we not add more hashed results if at all possible. How big is the raw data we're talking about here?
Alright, so to test out the file diff stuff, i just screwed up the reference file to see how this looks:
Any further thoughts? |
OK, after a little bit more fiddling, I believe this is fully ready to go. |
@drewejohnson Are you satisfied with this PR? |
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.
5cef1e2
to
67542a3
Compare
Co-authored-by: Andrew Johnson <drewejohnson@users.noreply.github.com>
Co-authored-by: Andrew Johnson <drewejohnson@users.noreply.github.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
OK, rebased, let's see if CI works now... |
Builds off #1714
This PR just ties in a few pieces of feedback from the PR mentioned there. Now, OPENMC_CROSS_SECTIONS or the cross_sections element of a materials.xml file is used to determine which nuclides should be added to depleted materials. I could have made a PR to @rockfool's fork, but didn't so you don't have to worry about this Jiankai. And then we could get feedback from Drew and Paul faster on this.
Anyways, this also includes the recommendation of returning a
Materials
instance, and does not export to XML by default. Rather, if a certain kwarg is provided for a new XML file name, the new materials XML file will be written. The newMaterials
instance is always returned, though.Non-burnable materials are also included in the result.
Was there anything else you guys (@paulromano and @drewejohnson) think would be useful for this?