Skip to content

Commit

Permalink
Cleanup of DB migration scripts (#1433)
Browse files Browse the repository at this point in the history
- I removed two scripts: crossSectionBlueprintsToSettings.py and m0_1_0_newDbFormat.py.
- I also moved the directory armi/scripts/migration/ to armi/migration/,
- I added some code coverage.
  • Loading branch information
john-science committed Oct 19, 2023
1 parent 85d4f6e commit d3af5de
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 451 deletions.
2 changes: 1 addition & 1 deletion armi/cli/migrateInputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os

from armi.cli.entryPoint import EntryPoint
from armi.scripts.migration import ACTIVE_MIGRATIONS, base
from armi.migration import ACTIVE_MIGRATIONS, base
from armi.utils import directoryChangers


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@
like happens in mainstream applications like word processors and spreadsheets.
"""

from armi.scripts.migration import (
from armi.migration import (
m0_1_3,
m0_1_0_newDbFormat,
crossSectionBlueprintsToSettings,
m0_1_6_locationLabels,
m0_1_6,
)

ACTIVE_MIGRATIONS = [
m0_1_0_newDbFormat.ConvertDB2toDB3,
m0_1_3.RemoveCentersFromBlueprints,
m0_1_3.UpdateElementalNuclides,
crossSectionBlueprintsToSettings.MoveCrossSectionsFromBlueprints,
m0_1_6_locationLabels.ConvertAlphanumLocationSettingsToNum,
m0_1_6.ConvertAlphanumLocationSettingsToNum,
]
15 changes: 2 additions & 13 deletions armi/scripts/migration/base.py → armi/migration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _loadStreamFromPath(self):
The operative subclasses implementing this method are below.
"""
if not os.path.exists(self.path):
raise ValueError("File {} does not exist".format(self.path))
raise ValueError(f"File {self.path} does not exist")

def _applyToStream(self):
"""Add actual migration code here in a subclass."""
Expand All @@ -88,8 +88,7 @@ def _writeNewFile(self, newStream):
while os.path.exists(self.path):
# don't overwrite files (could be blueprints)
name, ext = os.path.splitext(self.path)
name += f"{i}"
self.path = name + ext
self.path = name + f"{i}" + ext
i += 1

with open(self.path, "w") as f:
Expand All @@ -116,16 +115,6 @@ def _loadStreamFromPath(self):
self.stream = open(self.path)


class GeomMigration(Migration):
"""Migration for non-blueprints geometry input."""

def _loadStreamFromPath(self):
Migration._loadStreamFromPath(self)
cs = caseSettings.Settings(fName=self.path)
self.path = cs["geomFile"]
self.stream = open(self.path)


class DatabaseMigration(Migration):
"""Migration for db output."""

Expand Down
4 changes: 2 additions & 2 deletions armi/scripts/migration/m0_1_3.py → armi/migration/m0_1_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Cleans up blueprints."""
import re
import io
import re

from armi.scripts.migration.base import BlueprintsMigration
from armi.migration.base import BlueprintsMigration
from armi import runLog


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from armi import runLog
from armi.settings import caseSettings
from armi.scripts.migration.base import SettingsMigration
from armi.migration.base import SettingsMigration
from armi.settings import settingsIO
from armi.utils.units import ASCII_LETTER_A, ASCII_ZERO

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import io
import unittest

from armi.migration.m0_1_6 import ConvertAlphanumLocationSettingsToNum
from armi.settings import caseSettings
from armi.scripts.migration.m0_1_6_locationLabels import (
ConvertAlphanumLocationSettingsToNum,
)
from armi.settings.settingsIO import SettingsWriter, SettingsReader


Expand Down
42 changes: 42 additions & 0 deletions armi/migration/tests/test_migration_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2023 TerraPower, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test base migration classes."""
import os
import unittest

from armi.migration.base import Migration
from armi.migration.base import SettingsMigration
from armi.tests import TEST_ROOT


class TestMigrationBases(unittest.TestCase):
def test_basic_validation(self):
with self.assertRaises(RuntimeError):
_m = Migration(None, None)

with self.assertRaises(RuntimeError):
_m = Migration("fake_stream", "fake_path")

Migration("fake_stream", None)
m = Migration(None, "fake_path")
with self.assertRaises(ValueError):
m._loadStreamFromPath()


class TestSettingsMigration(unittest.TestCase):
def test_loadStreamFromPath(self):
file_path = os.path.join(TEST_ROOT, "armiRun.yaml")
m = SettingsMigration(None, file_path)
m._loadStreamFromPath()
self.assertIsNotNone(m.stream)
37 changes: 3 additions & 34 deletions armi/physics/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,9 @@
Displacements per atom are correlated to material damage.
.. note:: This data structure can be updated by plugins with design-specific dpa data.
See :py:mod:`armi.scripts.genDpaXs` for details.
The dpa cross sections are generated by running the following code:
>>> from armi.scripts import genDpaXs
>>> from armi.nuclearDataIO import SPECTR
>>> from armi.materials import T92, HT9, SS316
>>> import os
>>> from armi import settings
>>> from armi.physics.neutronics import energyGroups
>>> ANL33 = energyGroups.GROUP_STRUCTURE["ANL33"]
>>> cs = settings.Settings()
>>> spectrum = SPECTR(os.path.join(cs['DPAXSDirectoryPath'], "spectra\\twr_bol.SPECTR"))
>>> ht9collapser = genDpaXs.DpaCrossSectionCollapser(coarseEnergyUpperBoundseV=ANL33,
detailedSpectrum=spectrum,
endfDataPath=cs['DPAXSDirectoryPath'],
material=HT9())
>>> ht9collapser.collapse()
>>> t92collapser = genDpaXs.DpaCrossSectionCollapser(coarseEnergyUpperBoundseV=ANL33,
detailedSpectrum=spectrum,
endfDataPath=cs['DPAXSDirectoryPath'],
material=T92())
>>> t92collapser.collapse()
>>> ss316collapser = genDpaXs.DpaCrossSectionCollapser(coarseEnergyUpperBoundseV=ANL33,
detailedSpectrum=spectrum,
endfDataPath=cs['DPAXSDirectoryPath'],
material=SS316())
>>> ss316collapser.collapse()
Notes
-----
This data structure can be updated by plugins with design-specific dpa data.
"""

# The following are multigroup DPA XS for EBR II. They were generated using an ultra hard MCC spectrum
Expand Down
17 changes: 0 additions & 17 deletions armi/physics/neutronics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
from armi.operators import settingsValidation
from armi.physics.neutronics.const import NEUTRON
from armi.physics.neutronics.energyGroups import GROUP_STRUCTURE
from armi.scripts.migration.crossSectionBlueprintsToSettings import (
migrateCrossSectionsFromBlueprints,
)
from armi.physics.neutronics import LatticePhysicsFrequency
from armi.settings import setting
from armi.utils import directoryChangers
Expand Down Expand Up @@ -513,20 +510,6 @@ def migrateDpaGridPlate():
)
)

queries.append(
settingsValidation.Query(
lambda: inspector.cs[CONF_LOADING_FILE]
and _blueprintsHasOldXSInput(inspector),
"The specified blueprints input file '{0}' contains compound cross section settings. "
"".format(inspector.cs[CONF_LOADING_FILE]),
"Automatically move them to the settings file, {}? WARNING: if multiple settings files point "
"to this blueprints input you must manually update the others.".format(
inspector.cs.path
),
lambda: migrateCrossSectionsFromBlueprints(inspector.cs),
)
)

queries.append(
settingsValidation.Query(
lambda: inspector.cs[CONF_DETAILED_AXIAL_EXPANSION]
Expand Down
2 changes: 1 addition & 1 deletion armi/physics/neutronics/tests/test_neutronicsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_neutronicsSettingsValidators(self):
cs = settings.Settings()
inspector = settingsValidation.Inspector(cs)
sv = getNeutronicsSettingValidators(inspector)
self.assertEqual(len(sv), 9)
self.assertEqual(len(sv), 8)

# Test the Query: boundaries are now "Extrapolated", not "Generalized"
cs = cs.modified(newSettings={CONF_BOUNDARIES: "Generalized"})
Expand Down
9 changes: 2 additions & 7 deletions armi/reactor/blueprints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@

from armi import context
from armi import getPluginManager, getPluginManagerOrFail
from armi import migration
from armi import plugins
from armi import runLog
from armi.nucDirectory import nuclideBases
from armi.reactor import assemblies
from armi.reactor import geometry
from armi.reactor import systemLayoutInput
from armi.reactor.flags import Flags
from armi.scripts import migration
from armi.utils.customExceptions import InputError
from armi.utils import textProcessors
from armi.settings.fwSettings.globalSettings import (
Expand Down Expand Up @@ -633,10 +633,5 @@ def migrate(bp: Blueprints, cs):
aDesign.radialMeshPoints = radMesh
aDesign.azimuthalMeshPoints = aziMesh

# Someday: write out the migrated file. At the moment this messes up the case
# TODO: write out the migrated file. At the moment this messes up the case
# title and doesn't yet have the other systems in place so this isn't the right place.


# cs.writeToXMLFile(cs.caseTitle + '.migrated.xml')
# with open(os.path.split(cs['loadingFile'])[0] + '.migrated.' + '.yaml', 'w') as loadingFile:
# blueprints.Blueprints.dump(bp, loadingFile)
15 changes: 0 additions & 15 deletions armi/scripts/__init__.py

This file was deleted.

Loading

0 comments on commit d3af5de

Please sign in to comment.