# Additional checking steps in MGXS library

**URL:** <https://openmc.discourse.group/t/additional-checking-steps-in-mgxs-library/1642>\
**Category:** Development\
**Created:** [January 17, 2022, 10:23pm UTC](https://openmc.discourse.group/t/additional-checking-steps-in-mgxs-library/1642 "2022-01-17T22:23:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gridley](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/gridley/32/1064_2.png) [@gridley](https://openmc.discourse.group/u/gridley)\
**Post date:** [January 17, 2022, 10:23pm UTC](https://openmc.discourse.group/t/additional-checking-steps-in-mgxs-library/1642/1 "2022-01-17T22:23:05Z")

</div>

Hey everyone,

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,

Gavin

---

<div class="post-metadata">

**Author:** ![agnelson](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@agnelson](https://openmc.discourse.group/u/agnelson)\
**Post date:** [February 9, 2022, 7:22pm UTC](https://openmc.discourse.group/t/additional-checking-steps-in-mgxs-library/1642/2 "2022-02-09T19:22:31Z")

</div>

Hi Gavin,

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 `Model` class.

Thoughts?

Thanks and sorry about the delay!  
Adam
