Ejemplo n.º 1
0
    def _listInputFiles(cs):
        """
        Gathers information about the input files of this case.
    
        Returns
        -------
        inputInfo : list
            (label, fileName, shaHash) tuples
        """
        inputInfo = []
        inputFiles = [
            ("Case Settings", cs.caseTitle + ".yaml"),
            ("Blueprints", cs["loadingFile"]),
            ("Geometry", cs["geomFile"]),
        ]
        if cs["shuffleLogic"]:
            inputFiles.append(("Fuel Management", cs["shuffleLogic"]))
        if cs["controlLogic"]:
            inputFiles.append(("Control Logic", cs["controlLogic"]))
        if cs["orificeSettingsFile"]:
            inputFiles.append(("Orifice Settings", cs["orificeSettingsFile"]))
        if cs["reloadDBName"] and cs["runType"] == RunTypes.SNAPSHOTS:
            inputFiles.append(("Database", cs["reloadDBName"]))
        for label, fName in inputFiles:
            shaHash = ("MISSING" if (not fName or not os.path.exists(fName))
                       else utils.getFileSHA1Hash(fName, digits=10))
            inputInfo.append((label, fName, shaHash))

        return inputInfo
Ejemplo n.º 2
0
def _migrateDatabase(databasePath, preCollector, visitor, postApplier):
    """
    Generic database-traversing system to apply custom version-specific migrations.

    Parameters
    ----------
    databasePath : str
        Path to DB file to be converted
    preCollector : callable
        Function that acts on oldDB and produces some generic data object
    visitor : callable
        Function that will be called on each dataset of the old HDF5 database.
        This should map information into the new DB.
    postApplier : callable
        Function that will run after all visiting is done. Will have acecss
        to the pre-collected data.

    Raises
    ------
    OSError
        When database is not found.
    """
    if not os.path.exists(databasePath):
        raise OSError("Database file {} does not exist".format(databasePath))

    runLog.info("Migrating database file: {}".format(databasePath))
    runLog.info("Generating SHA-1 hash for original database: {}".format(databasePath))
    shaHash = utils.getFileSHA1Hash(databasePath)
    runLog.info("    Database: {}\n" "    SHA-1: {}".format(databasePath, shaHash))
    _remoteFolder, remoteDbName = os.path.split(databasePath)  # make new DB locally
    root, ext = os.path.splitext(remoteDbName)
    newDBName = root + "_migrated" + ext
    runLog.info("Copying database from {} to {}".format(databasePath, newDBName))
    with h5py.File(newDBName, "w") as newDB, h5py.File(databasePath, "r") as oldDB:

        preCollection = preCollector(oldDB)

        def closure(name, dataset):
            visitor(newDB, preCollection, name, dataset)

        oldDB.visititems(closure)

        # Copy all old database attributes to the new database (h5py AttributeManager has no update method)
        for key, val in oldDB.attrs.items():
            newDB.attrs[key] = val

        newDB.attrs["original-armi-version"] = oldDB.attrs["version"]
        newDB.attrs["original-db-hash"] = shaHash
        newDB.attrs["original-databaseVersion"] = oldDB.attrs["databaseVersion"]
        newDB.attrs["version"] = armi.__version__

        postApplier(oldDB, newDB, preCollection)

    runLog.info("Successfully generated migrated database file: {}".format(newDBName))
Ejemplo n.º 3
0
    def _listInputFiles(cs):
        """
        Gathers information about the input files of this case.

        Returns
        -------
        inputInfo : list
            (label, fileName, shaHash) tuples
        """

        pathToLoading = pathlib.Path(cs.inputDirectory) / cs["loadingFile"]

        if pathToLoading.is_file():
            includedBlueprints = [
                inclusion[0]
                for inclusion in textProcessors.findYamlInclusions(pathToLoading)
            ]
        else:
            includedBlueprints = []

        inputInfo = []
        inputFiles = (
            [
                ("Case Settings", cs.caseTitle + ".yaml"),
                ("Blueprints", cs["loadingFile"]),
            ]
            + [("Included blueprints", inclBp) for inclBp in includedBlueprints]
            + [("Geometry", cs["geomFile"])]
        )

        activeInterfaces = interfaces.getActiveInterfaceInfo(cs)
        for klass, kwargs in activeInterfaces:
            if not kwargs.get("enabled", True):
                # Don't consider disabled interfaces
                continue
            interfaceFileNames = klass.specifyInputs(cs)
            for label, fileNames in interfaceFileNames.items():
                for fName in fileNames:
                    inputFiles.append((label, fName))

        if cs["reloadDBName"] and cs["runType"] == RunTypes.SNAPSHOTS:
            inputFiles.append(("Database", cs["reloadDBName"]))
        for label, fName in inputFiles:
            shaHash = (
                "MISSING"
                if (not fName or not os.path.exists(fName))
                else utils.getFileSHA1Hash(fName, digits=10)
            )
            inputInfo.append((label, fName, shaHash))

        return inputInfo
Ejemplo n.º 4
0
def migrate_settings(settings_path):
    """Migrate a settings file to be compatible with the latest ARMI code base."""
    if not os.path.exists(settings_path):
        raise ValueError(
            "Case settings file {} does not exist".format(settings_path))

    runLog.info("Migrating case settings: {}".format(settings_path))
    shaHash = utils.getFileSHA1Hash(settings_path)
    runLog.info("\Settings: {}\n" "\tSHA-1: {}".format(settings_path, shaHash))
    cs = caseSettings.Settings()
    reader = cs.loadFromInputFile(settings_path, handleInvalids=False)
    if reader.invalidSettings:
        runLog.info(
            "The following deprecated settings will be deleted:\n  * {}"
            "".format("\n  * ".join(list(reader.invalidSettings))))

    _modify_settings(cs)
    newSettingsInput = cs.caseTitle + "_migrated.yaml"
    cs.writeToYamlFile(newSettingsInput)
    runLog.info("Successfully generated migrated settings file: {}".format(
        newSettingsInput))
Ejemplo n.º 5
0
def migrate_database(database_path):
    """Migrate the database to be compatible with the latest ARMI code base."""
    if not os.path.exists(database_path):
        raise ValueError(
            "Database file {} does not exist".format(database_path))

    runLog.info("Migrating database file: {}".format(database_path))
    runLog.info("Generating SHA-1 hash for original database: {}".format(
        database_path))
    shaHash = utils.getFileSHA1Hash(database_path)
    runLog.info("    Database: {}\n"
                "    SHA-1: {}".format(database_path, shaHash))
    _remoteFolder, remoteDbName = os.path.split(
        database_path)  # make new DB locally
    root, ext = os.path.splitext(remoteDbName)
    newDBName = root + "_migrated" + ext
    runLog.info("Copying database from {} to {}".format(
        database_path, newDBName))
    with h5py.File(newDBName, "w") as newDB, h5py.File(database_path,
                                                       "r") as oldDB:

        typeNames = _getTypeNames(oldDB)

        def closure(name, dataset):
            _copyValidDatasets(newDB, typeNames, name, dataset)

        oldDB.visititems(closure)

        # Copy all old database attributes to the new database (h5py AttributeManager has no update method)
        for key, val in oldDB.attrs.items():
            newDB.attrs[key] = val

        newDB.attrs["original-db-version"] = oldDB.attrs["version"]
        newDB.attrs["original-db-hash"] = shaHash
        newDB.attrs["version"] = armi.__version__

        _writeAssemType(oldDB, newDB, typeNames)

    runLog.info(
        "Successfully generated migrated database file: {}".format(newDBName))