Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to force certain parameters into database #426

Merged
merged 6 commits into from Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion armi/bookkeeping/db/database3.py
Expand Up @@ -90,10 +90,12 @@
from armi import settings
from armi.reactor import parameters
from armi.reactor.parameters import parameterCollections
from armi.reactor.parameters import parameterDefinitions
from armi.reactor.flags import Flags
from armi.reactor.reactors import Reactor, Core
from armi.reactor import assemblies
from armi.reactor.assemblies import Assembly
from armi.reactor import blocks
from armi.reactor.blocks import Block
from armi.reactor.components import Component
from armi.reactor.composites import ArmiObject
Expand All @@ -103,7 +105,10 @@
from armi.reactor import systemLayoutInput
from armi.utils.textProcessors import resolveMarkupInclusions
from armi.nucDirectory import nuclideBases
from armi.settings.fwSettings.databaseSettings import CONF_SYNC_AFTER_WRITE
from armi.settings.fwSettings.databaseSettings import (
CONF_SYNC_AFTER_WRITE,
CONF_FORCE_DB_PARAMS,
)

ORDER = interfaces.STACK_ORDER.BOOKKEEPING
DB_MAJOR = 3
Expand Down Expand Up @@ -161,6 +166,20 @@ def __init__(self, r, cs):
self._db = None
self._dbPath: Optional[pathlib.Path] = None

if cs[CONF_FORCE_DB_PARAMS]:
toSet = {paramName: set() for paramName in cs[CONF_FORCE_DB_PARAMS]}
for (name, _), pDef in parameterDefinitions.ALL_DEFINITIONS.items():
if name in toSet.keys():
toSet[name].add(pDef)

for name, pDefs in toSet.items():
runLog.info(
"Forcing parameter {} to be written to the database, per user "
"input".format(name)
)
for pDef in pDefs:
pDef.saveToDB = True

def __repr__(self):
return "<{} '{}' {} >".format(
self.__class__.__name__, self.name, repr(self._db)
Expand Down
6 changes: 6 additions & 0 deletions armi/bookkeeping/tests/test_databaseInterface.py
Expand Up @@ -34,6 +34,7 @@
from armi import runLog
from armi.reactor.tests import test_reactors
from armi.reactor import grids
from armi.settings.fwSettings.databaseSettings import CONF_FORCE_DB_PARAMS


def getSimpleDBOperator(cs):
Expand All @@ -52,6 +53,9 @@ def getSimpleDBOperator(cs):
cs["runType"] = "Standard"
cs["geomFile"] = "geom1Assem.xml"
cs["nCycles"] = 2
cs[CONF_FORCE_DB_PARAMS] = [
"baseBu",
]
genDBCase = case.Case(cs)
settings.setMasterCs(cs)
runLog.setVerbosity("info")
Expand All @@ -74,6 +78,7 @@ def __init__(self, r, cs, action=None):
self.action = action

def interactEveryNode(self, cycle, node):
self.r.core.getFirstBlock().p.baseBu = 5.0
self.action(cycle, node)


Expand Down Expand Up @@ -113,6 +118,7 @@ def goodMethod(cycle, node): # pylint: disable=unused-argument
self.assertIn("geomFile", h5["inputs"])
self.assertIn("settings", h5["inputs"])
self.assertIn("blueprints", h5["inputs"])
self.assertIn("baseBu", h5["c01n02/HexBlock"])

def test_metaData_endFail(self):
def failMethod(cycle, node): # pylint: disable=unused-argument
Expand Down
3 changes: 1 addition & 2 deletions armi/operators/tests/test_inspectors.py
Expand Up @@ -92,8 +92,7 @@ def test_callableCorrectionCheck(self):

def test_assignCS(self):
keys = sorted(self.inspector.cs.keys())
self.assertEqual(len(keys), 146)
self.assertEqual(keys[0], "HCFcoretype")
self.assertIn("HCFcoretype", keys)

self.assertEqual(self.inspector.cs["HCFcoretype"], "TWRC")
self.inspector._assignCS(
Expand Down
11 changes: 11 additions & 0 deletions armi/settings/fwSettings/databaseSettings.py
Expand Up @@ -24,6 +24,7 @@
CONF_DB_STORAGE_AFTER_CYCLE = "dbStorageAfterCycle"
CONF_ZERO_OUT_NUCLIDES_NOT_IN_DB = "zeroOutNuclidesNotInDB"
CONF_SYNC_AFTER_WRITE = "syncDbAfterWrite"
CONF_FORCE_DB_PARAMS = "forceDbParams"


def defineSettings():
Expand Down Expand Up @@ -69,5 +70,15 @@ def defineSettings():
"after each write."
),
),
setting.Setting(
CONF_FORCE_DB_PARAMS,
default=[],
label="Force database write of parameters",
description=(
"A list of parameter names that should always be written to the "
"database, regardless of their Parameter Definition's typical saveToDB "
"status. This is only honored if the DatabaseInterface is used."
),
),
]
return settings
4 changes: 2 additions & 2 deletions armi/settings/tests/test_settings.py
Expand Up @@ -78,8 +78,8 @@ def test_update(self):
with self.cs._unlock():
# grab the keys, and make sure they make some sense
keys = sorted(self.cs.keys())
self.assertEqual(len(keys), 146)
self.assertEqual(keys[:3], ["HCFcoretype", "Tin", "Tout"])
for key in {"HCFcoretype", "Tin", "Tout"}:
self.assertIn(key, keys)

# test an invalid update
d = {"aaba": 1, "aardvark": 2}
Expand Down