Skip to content

Commit

Permalink
Adding impl/test crumbs for the Database (#1493)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science authored Nov 27, 2023
1 parent 550c47f commit 0a4bad7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
4 changes: 0 additions & 4 deletions armi/bookkeeping/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ def _getH5File(db):
All this being said, we are probably violating this already with genAuxiliaryData,
but we have to start somewhere.
.. impl:: The ARMI output file has a language-agnostic format.
:id: I_ARMI_DB_H5
:implements: R_ARMI_DB_H5
"""
if isinstance(db, Database3):
return db.h5db
Expand Down
17 changes: 17 additions & 0 deletions armi/bookkeeping/db/database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class Database3:
handles the packing and unpacking of the structure of the objects, their
relationships, and their non-parameter attributes.
.. impl:: The database files are H5, and thus language agnostic.
:id: I_ARMI_DB_H51
:implements: R_ARMI_DB_H5
See Also
--------
`doc/user/outputs/database` for more details.
Expand Down Expand Up @@ -423,6 +427,7 @@ def loadBlueprints(self):
def loadGeometry(self):
"""
This is primarily just used for migrations.
The "geometry files" were replaced by ``systems:`` and ``grids:`` sections of ``Blueprints``.
"""
geom = systemLayoutInput.SystemLayoutInput()
Expand All @@ -437,6 +442,14 @@ def writeInputsToDB(self, cs, csString=None, geomString=None, bpString=None):
implementation should be very stable, so we dont want it to be easy to change
one Database implementation's behavior when trying to change another's.
.. impl:: The run settings are saved the settings file.
:id: I_ARMI_DB_CS
:implements: R_ARMI_DB_CS
.. impl:: The reactor blueprints are saved the settings file.
:id: I_ARMI_DB_BP
:implements: R_ARMI_DB_BP
Notes
-----
This is hard-coded to read the entire file contents into memory and write that
Expand Down Expand Up @@ -659,6 +672,10 @@ def load(
continue with new settings (or if blueprints are not on the database).
Geometry is read from the database itself.
.. test:: Users can load a reactor from a DB.
:id: I_ARMI_DB_R_LOAD
:tests: R_ARMI_DB_R_LOAD
Parameters
----------
cycle : int
Expand Down
6 changes: 6 additions & 0 deletions armi/bookkeeping/db/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ def _initComps(self, caseTitle, bp):
return comps, groupedComps

def writeToDB(self, h5group):
"""Write a chunk of data to the database.
.. test:: Write data to the DB for a given time step.
:id: I_ARMI_DB_TIME
:tests: R_ARMI_DB_TIME
"""
if "layout/type" in h5group:
# It looks like we have already written the layout to DB, skip for now
return
Expand Down
25 changes: 25 additions & 0 deletions armi/bookkeeping/db/tests/test_database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def tearDown(self):
self.td.__exit__(None, None, None)

def test_writeToDB(self):
"""Test writing to the database.
.. test:: Write a single time step of data to the database.
:id: T_ARMI_DB_TIME
:tests: R_ARMI_DB_TIME
"""
self.r.p.cycle = 0
self.r.p.timeNode = 0
self.r.p.cycleLength = 0
Expand All @@ -67,6 +73,7 @@ def test_writeToDB(self):
self.db.writeToDB(self.r)
self.assertEqual(sorted(self.db.h5db.keys()), ["c00n00", "inputs"])

# check the keys for a single time step
keys = [
"Circle",
"Core",
Expand Down Expand Up @@ -345,6 +352,12 @@ def test_computeParents(self):
)

def test_load(self):
"""Load a reactor at different time steps, from the database.
.. test:: Load the reactor from the database.
:id: T_ARMI_DB_R_LOAD
:tests: R_ARMI_DB_R_LOAD
"""
self.makeShuffleHistory()
with self.assertRaises(KeyError):
_r = self.db.load(0, 0)
Expand Down Expand Up @@ -601,14 +614,26 @@ def test_fileName(self):
self.assertEqual(str(self.db.fileName), "thing.h5")

def test_readInputsFromDB(self):
"""Test that we can read inputs from the database.
.. test:: Save and retrieve settings from the database.
:id: T_ARMI_DB_CS
:tests: R_ARMI_DB_CS
.. test:: Save and retrieve blueprints from the database.
:id: T_ARMI_DB_BP
:tests: R_ARMI_DB_BP
"""
inputs = self.db.readInputsFromDB()
self.assertEqual(len(inputs), 3)

# settings
self.assertGreater(len(inputs[0]), 100)
self.assertIn("settings:", inputs[0])

self.assertEqual(len(inputs[1]), 0)

# blueprints
self.assertGreater(len(inputs[2]), 100)
self.assertIn("custom isotopics:", inputs[2])
self.assertIn("blocks:", inputs[2])
Expand Down

0 comments on commit 0a4bad7

Please sign in to comment.