Skip to content

Commit

Permalink
expose handleInvalids further back so scripts can opt out when they u…
Browse files Browse the repository at this point in the history
…se loadOperator
  • Loading branch information
opotowsky committed Nov 4, 2024
1 parent ad120c9 commit 72fb32f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion armi/bookkeeping/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def loadOperator(
loadNode,
statePointName=None,
allowMissing=False,
handleInvalids=True,
):
"""
Return an operator given the path to a database.
Expand All @@ -104,6 +105,8 @@ def loadOperator(
allowMissing : bool
Whether to emit a warning, rather than crash if reading a database
with undefined parameters. Default False.
handleInvalids : bool
Whether to check for invlaid settings. Default True.
See Also
--------
Expand Down Expand Up @@ -145,14 +148,15 @@ def loadOperator(
# init Case here as it keeps track of execution time and assigns a reactor
# attribute. This attribute includes the time it takes to initialize the reactor
# so creating a reactor from the database should be included.
cs = db.loadCS()
cs = db.loadCS(handleInvalids=handleInvalids)
thisCase = cases.Case(cs)

r = db.load(
loadCycle,
loadNode,
statePointName=statePointName,
allowMissing=allowMissing,
handleInvalids=handleInvalids,
)

o = thisCase.initializeOperator(r=r)
Expand Down
16 changes: 13 additions & 3 deletions armi/bookkeeping/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,14 @@ def fileName(self, fName):
raise RuntimeError("Cannot change Database file name while it's opened!")
self._fileName = fName

def loadCS(self):
def loadCS(self, handleInvalids=True):
"""Attempt to load settings from the database file.
Parameters
----------
handleInvalids : bool
Whether to check for invlaid settings. Default True.
Notes
-----
There are no guarantees here. If the database was written from a different version of ARMI than you are using,
Expand All @@ -405,7 +410,9 @@ def loadCS(self):
cs = settings.Settings()
cs.caseTitle = os.path.splitext(os.path.basename(self.fileName))[0]
try:
cs.loadFromString(self.h5db["inputs/settings"].asstr()[()])
cs.loadFromString(
self.h5db["inputs/settings"].asstr()[()], handleInvalids=handleInvalids
)
except KeyError:
# not all paths to writing a database require inputs to be written to the
# database. Technically, settings do affect some of the behavior of database
Expand Down Expand Up @@ -708,6 +715,7 @@ def load(
bp=None,
statePointName=None,
allowMissing=False,
handleInvalids=True,
):
"""Load a new reactor from a DB at (cycle, node).
Expand Down Expand Up @@ -743,6 +751,8 @@ def load(
allowMissing : bool, optional
Whether to emit a warning, rather than crash if reading a database
with undefined parameters. Default False.
handleInvalids : bool
Whether to check for invlaid settings. Default True.
Returns
-------
Expand All @@ -751,7 +761,7 @@ def load(
"""
runLog.info("Loading reactor state for time node ({}, {})".format(cycle, node))

cs = cs or self.loadCS()
cs = cs or self.loadCS(handleInvalids=handleInvalids)
bp = bp or self.loadBlueprints()

if node < 0:
Expand Down

0 comments on commit 72fb32f

Please sign in to comment.