Example #1
0
File: case.py Project: ntouran/armi
    def writeInputs(self, sourceDir: Optional[str] = None):
        """
        Write the inputs to disk.

        This allows input objects that have been modified in memory (e.g.
        for a parameter sweep or migration) to be written out as input
        for a forthcoming case.

        Parameters
        ----------
        sourceDir : str, optional
            The path to copy inputs from (if different from the cs.path). Needed
            in SuiteBuilder cases to find the baseline inputs from plugins (e.g. shuffleLogic)

        Notes
        -----
        This will rename the ``loadingFile`` and ``geomFile`` to be ``title-blueprints + '.yaml'`` and
        ``title + '-geom.yaml'`` respectively.

        See Also
        --------
        independentVariables
            parses/reads the independentVariables setting

        clone
            Similar to this but doesn't let you write out new/modified
            geometry or blueprints objects
        """
        with ForcedCreationDirectoryChanger(self.cs.inputDirectory,
                                            dumpOnException=False):
            # trick: these seemingly no-ops load the bp and geom via properties if
            # they are not yet initialized.
            self.bp  # pylint: disable=pointless-statement
            self.geom  # pylint: disable=pointless-statement

            newSettings = {}
            newSettings["loadingFile"] = self.title + "-blueprints.yaml"
            if self.geom:
                newSettings["geomFile"] = self.title + "-geom.yaml"
                self.geom.writeGeom(newSettings["geomFile"])

            if self.independentVariables:
                newSettings["independentVariables"] = [
                    "({}, {})".format(repr(varName), repr(val))
                    for varName, val in self.independentVariables.items()
                ]

            with open(newSettings["loadingFile"], "w") as loadingFile:
                blueprints.Blueprints.dump(self.bp, loadingFile)

            # copy input files from other modules/plugins
            interfaceSettings = copyInterfaceInputs(self.cs, ".", sourceDir)
            for settingName, value in interfaceSettings.items():
                newSettings[settingName] = value

            self.cs = self.cs.modified(newSettings=newSettings)
            self.cs.writeToYamlFile(self.title + ".yaml")
Example #2
0
    def clone(self, oldRoot=None):
        """
        Clone a CaseSuite to a new place.

        Creates a clone for each case within a CaseSuite. If ``oldRoot`` is not
        specified, then each case clone is made in a directory with the title of the
        case. If ``oldRoot`` is specified, then a relative path from ``oldRoot`` will be
        used to determine a new relative path to the current directory ``oldRoot``.

        Parameters
        ----------
        oldRoot : str (optional)
            root directory of original case suite used to help filter when a suite
            contains one or more cases with the same case title.

        Notes
        -----
        By design, a CaseSuite has no location dependence; this allows any set of cases
        to compose a CaseSuite. The thought is that the post-analysis capabilities
        without restricting a root directory could be beneficial. For example, this
        allows one to perform analysis on cases analyzed by Person A and Person B, even
        if the analyses were performed in completely different locations. As a
        consequence, when you want to clone, we need to infer a "root" of the original
        cases to attempt to mirror whatever existing directory structure there may have
        been.
        """
        clone = CaseSuite(self.cs.duplicate())

        modifiedSettings = {
            ss.name: ss.value
            for ss in self.cs.settings.values() if ss.offDefault
        }
        for case in self:
            if oldRoot:
                newDir = os.path.dirname(os.path.relpath(
                    case.cs.path, oldRoot))
            else:
                newDir = case.title
            with ForcedCreationDirectoryChanger(newDir,
                                                clean=True,
                                                dumpOnException=False):
                clone.add(case.clone(modifiedSettings=modifiedSettings))
        return clone
Example #3
0
File: case.py Project: bakta5/armi
    def writeInputs(self):
        """
        Write the inputs to disk.

        This allows input objects that have been modified in memory (e.g.
        for a parameter sweep or migration) to be written out as input
        for a forthcoming case.

        Notes
        -----
        This will rename the ``loadingFile`` and ``geomFile`` to be ``title-blueprints + '.yaml'`` and
        ``title + '-geom.xml'`` respectively.

        See Also
        --------
        independentVariables
            parses/reads the independentVariables setting

        clone
            Similar to this but doesn't let you write out new/modified
            geometry or blueprints objects
        """
        with ForcedCreationDirectoryChanger(self.cs.inputDirectory):
            # trick: these seemingly no-ops load the bp and geom via properties if
            # they are not yet initialized.
            self.bp
            self.geom
            self.cs["loadingFile"] = self.title + "-blueprints.yaml"
            self.cs["geomFile"] = self.title + "-geom.xml"
            if self.independentVariables:
                self.cs["independentVariables"] = [
                    "({}, {})".format(repr(varName), repr(val))
                    for varName, val in self.independentVariables.items()
                ]

            self.cs.writeToYamlFile(self.title + ".yaml")
            self.geom.writeGeom(self.cs["geomFile"])

            with open(self.cs["loadingFile"], "w") as loadingFile:
                blueprints.Blueprints.dump(self.bp, loadingFile)

            copyInterfaceInputs(self.cs, self.directory)