I was recently creating a multigroup library, and wanted to parse some tally data. It turns out that if you don’t run the build_library method on mgxs.Library before loading from a statepoint, it fails with a dictionary key error when running the method to load from a statepoint. The same error appears if you don’t bulid_library before using the export_to_tallies method.
So I’d like to save time for others in the future to save them from this hassle. One thing is clear: we should add a flag denoting whether build_library has been run (or needs to be run again as a result of modifying the state).
What I’m not clear on is the correct action to take. Should we automatically rebuilt the library before exporting tallies or loading from statepoints? Or should a more descriptive error appear saying that build_library should be run? I am in favor of automating out the build_library command with the aforementioned flag.
Looking forward to hearing back,
I agree this is definitely an area that could use improvement. Your suggested fix makes a lot of sense to me: setting the flag and automating the
Library.build_library method. It is relatively simple and is a ‘just-in-time’ sort of approach. The only downside I see is that this flag would miss when the user could ran
Library.build_library method, changed the MGXS, and then tried writing to to the
Tallies object/loading from statepoint. That seems relatively low-risk to me though. What do you think about that risk?
There is a separate but related risk/issue though where the user could create the
Library object, and even run
Library.build_library method, but forget to add the results to the tallies file with
Library.add_to_tallies_file. I dont know the frequency of this but it sure seems like it wouldn’t be rare because the
Tallies class has no awareness of a
Library object existing out there. This also will result in a significant time wasting as the user doesn’t find out about the mistake until after OpenMC runs. Whether or not we should actively address this problem, I’m not on the fence for. The best way would be to make
Model be aware of
Library and have it automatically handle
Library.add_tallies_to_file. I kind of prefer getting to this point anyways as all objects that describe the model get to stay together in the
Thanks and sorry about the delay!