Skip to content

Commit

Permalink
Fix snapshot (#1783)
Browse files Browse the repository at this point in the history
Bug fixes for PR #1090
  • Loading branch information
onufer authored Jul 17, 2024
1 parent f04b365 commit 621a818
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion armi/bookkeeping/db/database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class Database3:
`doc/user/outputs/database` for more details.
"""

timeNodeGroupPattern = re.compile(r"^c(\d\d)n(\d\d)$")
# Allows matching for, e.g., c01n02EOL
timeNodeGroupPattern = re.compile(r"^c(\d\d)n(\d\d).*$")

def __init__(self, fileName: os.PathLike, permission: str):
"""
Expand Down
4 changes: 4 additions & 0 deletions armi/bookkeeping/db/databaseInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def interactEOL(self):
# is necessary, too.
self.r.core.p.minutesSinceStart = (time.time() - self.r.core.timeOfStart) / 60.0
self._db.writeToDB(self.r, "EOL")
self.closeDB()

def closeDB(self):
"""Close the DB, writing to file."""
self._db.close(True)

def interactError(self):
Expand Down
6 changes: 3 additions & 3 deletions armi/operators/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def interactAllEOC(self, cycle, excludedInterfaceNames=()):
activeInterfaces = self.getActiveInterfaces("EOC", excludedInterfaceNames)
self._interactAll("EOC", activeInterfaces, cycle)

def interactAllEOL(self):
def interactAllEOL(self, excludedInterfaceNames=()):
"""
Run interactEOL for all enabled interfaces.
Expand All @@ -665,7 +665,7 @@ def interactAllEOL(self):
order. This allows, for example, an interface that must run
first to also run last.
"""
activeInterfaces = self.getActiveInterfaces("EOL")
activeInterfaces = self.getActiveInterfaces("EOL", excludedInterfaceNames)
self._interactAll("EOL", activeInterfaces)

def interactAllCoupled(self, coupledIteration):
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def getActiveInterfaces(

# Ensure the name of the interface isn't in some exclusion list.
nameCheck = lambda i: True
if interactState == "EveryNode" or interactState == "EOC":
if interactState in ("EveryNode", "EOC", "EOL"):
nameCheck = lambda i: i.name not in excludedInterfaceNames
elif interactState == "BOC" and cycle < self.cs[CONF_DEFERRED_INTERFACES_CYCLE]:
nameCheck = lambda i: i.name not in self.cs[CONF_DEFERRED_INTERFACE_NAMES]
Expand Down
19 changes: 9 additions & 10 deletions armi/operators/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def _mainOperate(self):

# update the snapshot requests if the user chose to load from a specific cycle/node
dbi = self.getInterface("database")

lastTimeStep = snapshots[-1]
# database is excluded since SS writes by itself
excludeDB = ("database",)
for ssCycle, ssNode in snapshots:
runLog.important(
"Beginning snapshot ({0:02d}, {1:02d})".format(ssCycle, ssNode)
Expand All @@ -79,18 +79,17 @@ def _mainOperate(self):
if halt:
break

# database is excluded since it writes at EOC
self.interactAllEveryNode(
ssCycle, ssNode, excludedInterfaceNames=("database",)
)
# database is excluded since it writes after coupled
self.interactAllEveryNode(ssCycle, ssNode, excludedInterfaceNames=excludeDB)
self._performTightCoupling(ssCycle, ssNode, writeDB=False)
# tight coupling is done, now write to DB
dbi.writeDBEveryNode()

# database is excluded at last snapshot since it writes at EOL
exclude = ("database",) if (ssCycle, ssNode) == lastTimeStep else ()
self.interactAllEOC(self.r.p.cycle, excludedInterfaceNames=exclude)
self.interactAllEOC(self.r.p.cycle)

# run things that happen at EOL, like reports, plotters, etc.
self.interactAllEOL()
self.interactAllEOL(excludedInterfaceNames=excludeDB)
dbi.closeDB() # dump the database to file
runLog.important("Done with ARMI snapshots case.")

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions armi/operators/tests/test_operatorSnapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def setUp(self):
# mock a Database Interface
self.dbi = DatabaseInterface(self.r, o1.cs)
self.dbi.loadState = lambda c, n: None
self.dbi.writeDBEveryNode = lambda: None
self.dbi.closeDB = lambda: None

def test_atEOL(self):
self.assertFalse(self.o.atEOL)
Expand Down

0 comments on commit 621a818

Please sign in to comment.