Skip to content

Commit

Permalink
Add try/except around unpackSpecialData (#809)
Browse files Browse the repository at this point in the history
compareDatabases should be able to continue to run even if unpackSpecialData fails.

Some parameters are not able to be compared, which in a recent scenario led to a failure inside unpackSpecialData. This PR adds the try/except so that there is just an error and not a failure, and it also adds a the traceback to the log printout so parameters that cause this step to fail can be more easily addressed / manually compared.
  • Loading branch information
opotowsky committed Aug 4, 2022
1 parent 7534a85 commit 1660f9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 10 additions & 2 deletions armi/bookkeeping/db/compareDB3.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import collections
import os
import re
import traceback

from tabulate import tabulate
import h5py
Expand Down Expand Up @@ -360,8 +361,15 @@ def _diffSpecialData(
if not attrsMatch:
return

src = database3.unpackSpecialData(srcData[()], srcData.attrs, paramName)
ref = database3.unpackSpecialData(refData[()], refData.attrs, paramName)
try:
src = database3.unpackSpecialData(srcData[()], srcData.attrs, paramName)
ref = database3.unpackSpecialData(refData[()], refData.attrs, paramName)
except Exception:
runLog.error(
f"Unable to unpack special data for paramName {paramName}. "
f"{traceback.format_exc()}",
)
return

diff = []
for dSrc, dRef in zip(src.tolist(), ref.tolist()):
Expand Down
15 changes: 15 additions & 0 deletions armi/bookkeeping/db/tests/test_comparedb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,21 @@ def test_diffSpecialData(self):
self.assertEqual(dr.nDiffs(), 0)
self.assertIn("Special formatting parameters for", mock._outputStream)

# make an H5 datasets that will cause unpackSpecialData to fail
f4 = h5py.File("test_diffSpecialData4.hdf5", "w")
refData4 = f4.create_dataset("numberDensities", data=a2)
refData4.attrs["shapes"] = "2"
refData4.attrs["numDens"] = a2
f5 = h5py.File("test_diffSpecialData5.hdf5", "w")
srcData5 = f5.create_dataset("numberDensities", data=a2)
srcData5.attrs["shapes"] = "2"
srcData5.attrs["numDens"] = a2

# there should an exception
with self.assertRaises(Exception) as e:
_diffSpecialData(refData4, srcData5, out, dr)
self.assertIn("Unable to unpack special data for paramName", e)

def test_diffSimpleData(self):
dr = DiffResults(0.01)

Expand Down
1 change: 1 addition & 0 deletions doc/release/0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ What's new in ARMI
#. Introduction of axial expansion changer to enable component-level axial expansion of assemblies.
#. Add setting ``inputHeightsConsideredHot`` to enable thermal expansion of assemblies at BOL.
#. Add blueprints setting, ``axial expansion target component``, to enable users to manually set a "target component" for axial expansion.
#. Allow database comparison to continue even if ``unpackSpecialData`` fails.
#. TBD

Bug fixes
Expand Down

0 comments on commit 1660f9f

Please sign in to comment.