diff --git a/armi/bookkeeping/__init__.py b/armi/bookkeeping/__init__.py index 0e30a7fff..00c8f149d 100644 --- a/armi/bookkeeping/__init__.py +++ b/armi/bookkeeping/__init__.py @@ -44,9 +44,6 @@ def defineEntryPoints(): from armi.cli import database entryPoints = [] - # Disabling ConvertDB because there is no other format to convert between. The - # entry point is rather general so leaving this here so we don't forget about it - # entryPoints.append(database.ConvertDB) entryPoints.append(database.ExtractInputs) entryPoints.append(database.InjectInputs) entryPoints.append(visualization.VisFileEntryPoint) diff --git a/armi/bookkeeping/db/__init__.py b/armi/bookkeeping/db/__init__.py index 336d4c85d..ca0f5b4ed 100644 --- a/armi/bookkeeping/db/__init__.py +++ b/armi/bookkeeping/db/__init__.py @@ -60,12 +60,10 @@ location, without having to compose the full model. """ import os -from typing import Optional, List, Tuple from armi import runLog # re-export package components for easier import -from armi.bookkeeping.db.permissions import Permissions from armi.bookkeeping.db.database3 import Database3 from armi.bookkeeping.db.databaseInterface import DatabaseInterface from armi.bookkeeping.db.compareDB3 import compareDatabases @@ -154,87 +152,6 @@ def loadOperator(pathToDb, loadCycle, loadNode, allowMissing=False): return o -def convertDatabase( - inputDBName: str, - outputDBName: Optional[str] = None, - outputVersion: Optional[str] = None, - nodes: Optional[List[Tuple[int, int]]] = None, -): - """ - Convert database files between different versions. - - Parameters - ---------- - inputDB - name of the complete hierarchy database - outputDB - name of the output database that should be consistent with XTView - outputVersion - version of the database to convert to. Defaults to latest version - nodes - optional list of specific (cycle,node)s to convert - """ - dbIn = databaseFactory(inputDBName, permission=Permissions.READ_ONLY_FME) - - if dbIn.version == outputVersion: - runLog.important( - "The input database ({}) appears to already be in the desired " - "format ({})".format(inputDBName, dbIn.version) - ) - return - - outputDBName = outputDBName or "-converted".join(os.path.splitext(inputDBName)) - dbOut = databaseFactory( - outputDBName, permission=Permissions.CREATE_FILE_TIE, version=outputVersion - ) - # each DB load resets the verbosity to that of the run. Here we allow - # conversion users to overpower it. - conversionVerbosity = runLog.getVerbosity() - runLog.extra(f"Converting {dbIn} to DB version {outputVersion}") - with dbIn, dbOut: - dbNodes = list(dbIn.genTimeSteps()) - - if nodes is not None and any(node not in dbNodes for node in nodes): - raise RuntimeError( - "Some of the requested nodes are not in the source database.\n" - "Requested: {}\n" - "Present: {}".format(nodes, dbNodes) - ) - - # Making the bold assumption that we are working with HDF5 - h5In = _getH5File(dbIn) - h5Out = _getH5File(dbOut) - dbOut.writeInputsToDB(None, *dbIn.readInputsFromDB()) - - for cycle, timeNode in dbNodes: - if nodes is not None and (cycle, timeNode) not in nodes: - continue - runLog.extra(f"Converting cycle={cycle}, timeNode={timeNode}") - timeStepsInOutDB = set(dbOut.genTimeSteps()) - r = dbIn.load(cycle, timeNode) - if (r.p.cycle, r.p.timeNode) in timeStepsInOutDB: - runLog.warning( - "Time step ({}, {}) is already in the output DB. This " - "is probably due to repeated cycle/timeNode in the source DB; " - "deleting the existing time step and re-writing".format( - r.p.cycle, r.p.timeNode - ) - ) - del dbOut[r.p.cycle, r.p.timeNode, None] - runLog.setVerbosity(conversionVerbosity) - dbOut.writeToDB(r) - - for auxPath in dbIn.genAuxiliaryData((cycle, timeNode)): - name = next(reversed(auxPath.split("/"))) - auxOutPath = dbOut.getAuxiliaryDataPath((cycle, timeNode), name) - runLog.important( - "Copying auxiliary data for time ({}, {}): {} -> {}".format( - cycle, timeNode, auxPath, auxOutPath - ) - ) - h5In.copy(auxPath, h5Out, name=auxOutPath) - - def _getH5File(db): """Return the underlying h5py File that provides the backing storage for a database. diff --git a/armi/cli/database.py b/armi/cli/database.py index dedd575da..651cb5dfd 100644 --- a/armi/cli/database.py +++ b/armi/cli/database.py @@ -15,7 +15,6 @@ """Entry point into ARMI for manipulating output databases.""" import os import pathlib -import re from armi import context from armi import runLog @@ -23,64 +22,6 @@ from armi.utils.textProcessors import resolveMarkupInclusions -class ConvertDB(EntryPoint): - """Convert databases between different versions.""" - - name = "convert-db" - mode = context.Mode.BATCH - - def addOptions(self): - self.parser.add_argument("h5db", help="Input database path", type=str) - self.parser.add_argument( - "--output-name", "-o", help="output database name", type=str, default=None - ) - self.parser.add_argument( - "--output-version", - help=( - "output database version. '2' or 'xtview' for older XTView database; '3' " - "for new format." - ), - type=str, - default=None, - ) - - self.parser.add_argument( - "--nodes", - help="An optional list of time nodes to migrate. Should look like " - "`(1,0)(1,1)(1,2)`, etc", - type=str, - default=None, - ) - - def parse_args(self, args): - EntryPoint.parse_args(self, args) - if self.args.output_version is None: - self.args.output_version = "3" - elif self.args.output_version.lower() == "xtview": - self.args.output_version = "2" - - if self.args.nodes is not None: - self.args.nodes = [ - (int(cycle), int(node)) - for cycle, node in re.findall(r"\((\d+),(\d+)\)", self.args.nodes) - ] - - def invoke(self): - from armi.bookkeeping.db import convertDatabase - - if self.args.nodes is not None: - runLog.info( - "Converting the following time nodes: {}".format(self.args.nodes) - ) - - convertDatabase( - self.args.h5db, - outputDBName=self.args.output_name, - outputVersion=self.args.output_version, - nodes=self.args.nodes, - ) - - class ExtractInputs(EntryPoint): """ Recover input files from a database file. diff --git a/armi/cli/tests/test_runEntryPoint.py b/armi/cli/tests/test_runEntryPoint.py index ca83ad2bf..3ec38f25f 100644 --- a/armi/cli/tests/test_runEntryPoint.py +++ b/armi/cli/tests/test_runEntryPoint.py @@ -22,7 +22,7 @@ from armi.cli.checkInputs import CheckInputEntryPoint, ExpandBlueprints from armi.cli.clone import CloneArmiRunCommandBatch, CloneSuiteCommand from armi.cli.compareCases import CompareCases, CompareSuites -from armi.cli.database import ConvertDB, ExtractInputs, InjectInputs +from armi.cli.database import ExtractInputs, InjectInputs from armi.cli.entryPoint import EntryPoint from armi.cli.migrateInputs import MigrateInputs from armi.cli.modify import ModifyCaseSettingsCommand @@ -46,7 +46,7 @@ def test_entryPointInitialization(self): entryPoints = getEntireFamilyTree(EntryPoint) # Comparing to a minimum number of entry points, in case more are added. - self.assertGreater(len(entryPoints), 16) + self.assertGreater(len(entryPoints), 15) for e in entryPoints: entryPoint = e() @@ -191,36 +191,6 @@ def test_compareSuitesBasics(self): self.assertIsNone(cs.args.weights) -class TestConvertDB(unittest.TestCase): - def test_convertDbBasics(self): - cdb = ConvertDB() - cdb.addOptions() - cdb.parse_args(["/path/to/fake.h5"]) - - self.assertEqual(cdb.name, "convert-db") - self.assertEqual(cdb.args.output_version, "3") - self.assertIsNone(cdb.args.nodes) - - # Since the file is fake, invoke() should exit early. - with mockRunLogs.BufferLog() as mock: - cdb.args.nodes = [1, 2, 3] - with self.assertRaises(ValueError): - cdb.invoke() - self.assertIn("Converting the", mock.getStdout()) - - def test_convertDbOutputVersion(self): - cdb = ConvertDB() - cdb.addOptions() - cdb.parse_args(["/path/to/fake.h5", "--output-version", "XtView"]) - self.assertEqual(cdb.args.output_version, "2") - - def test_convertDbOutputNodes(self): - cdb = ConvertDB() - cdb.addOptions() - cdb.parse_args(["/path/to/fake.h5", "--nodes", "(1,2)"]) - self.assertEqual(cdb.args.nodes, [(1, 2)]) - - class TestExpandBlueprints(unittest.TestCase): def test_expandBlueprintsBasics(self): ebp = ExpandBlueprints() diff --git a/armi/nucDirectory/nuclideBases.py b/armi/nucDirectory/nuclideBases.py index 121b2a8e7..0d92103b4 100644 --- a/armi/nucDirectory/nuclideBases.py +++ b/armi/nucDirectory/nuclideBases.py @@ -91,46 +91,6 @@ class which is used to organize and store metadata about each nuclide. The >>> nuclideBases.byAAAZZZSId['2350920'] , HL:2.22160758861e+16, Abund:7.204000e-03> -.. only:: html - - .. _nuclide-bases-table: - - .. exec:: - import numpy - from tabulate import tabulate - from armi.nucDirectory import nuclideBases - from dochelpers import createTable - - attributes = ['name', - 'type', - 'a', - 'z', - 'state', - 'abundance', - 'weight', - 'halflife'] - - def getAttributes(nuc): - if nuc.halflife == numpy.inf: - halflife = "inf" - else: - halflife = f'{nuc.halflife:<12.6e}' - return [ - f'``{nuc.name}``', - f':py:class:`~armi.nucDirectory.nuclideBases.{nuc.__class__.__name__}`', - f'``{nuc.a}``', - f'``{nuc.z}``', - f'``{nuc.state}``', - f'``{nuc.abundance:<12.6e}``', - f'``{nuc.weight:<12.6e}``', - f'``{halflife}``', - ] - - sortedNucs = sorted(nuclideBases.instances) - return createTable(tabulate(tabular_data=[getAttributes(nuc) for nuc in sortedNucs], - headers=attributes, - tablefmt='rst'), - caption='List of nuclides') """ import os diff --git a/doc/release/0.3.rst b/doc/release/0.3.rst index 653a96a93..6c1d71c3d 100644 --- a/doc/release/0.3.rst +++ b/doc/release/0.3.rst @@ -17,6 +17,7 @@ API Changes #. Removing unused method ``HexGrid.allPositionsInThird()``. (`PR#1655 `_) #. Removed unused methods: ``Reactor.getAllNuclidesIn()``, ``plotTriangleFlux()``. (`PR#1656 `_) #. Removed ``armi.utils.dochelpers``; not relevant to nuclear modeling. (`PR#1662 `_) +#. Removing old tools created to help people convert to the current database format: ``armi.bookkeeping.db.convertDatabase()`` and ``ConvertDB``. (`PR#1658 `_) #. TBD Bug Fixes @@ -26,8 +27,8 @@ Bug Fixes Changes that Affect Requirements -------------------------------- -#. Touched ``HexGrid`` by adding a "cornersUp" property and fixing two bugs. (`PR#1649 `_) #. Very minor change to ``Block.coords()``, removing unused argument. (`PR#1651 `_) +#. Touched ``HexGrid`` by adding a "cornersUp" property and fixing two bugs. (`PR#1649 `_) #. TBD