Ejemplo n.º 1
0
    def add_app(self, name=None, params=None, actions=None, set_active=True):
        """Add an application to the CampaignDB.

        Parameters
        ----------
        name : str
            Name of the application.
        params : dict
            Description of the parameters to associate with the application.
        actions : Actions
            An instance of Actions containing actions to be executed
        set_active: bool
            Should the added app be set to be the currently active app?
        """

        # Verify input parameters dict
        paramsspec = ParamsSpecification(params, appname=name)

        # validate application input
        app = AppInfo(
            name=name,
            paramsspec=paramsspec,
            actions=actions,
        )

        self.campaign_db.add_app(app)
        if set_active:
            self.set_app(app.name)
Ejemplo n.º 2
0
    def _load_campaign(self, src, name):
        with open(src, "r") as infile:
            input_info = json.load(infile)

        if 'campaign' not in input_info:
            message = f"Campaign information missing from state file {src}."
            logger.critical(message)
            raise RuntimeError(message)

        if name is not None and input_info['campaign']['name'] != name:
            message = f'No campaign called {name} found - unable to continue.'
            logger.critical(message)
            raise RuntimeError(message)

        # TODO: Add version check

        self._campaign_info = input_info['campaign']
        self._app = input_info.get('app', {})
        self._runs = input_info.get('runs', {})
        self._sample = input_info.get('sample', {})
        self._collation_csv = input_info.get('collation_csv', {})
        self._next_run = input_info['next_run']
        self._next_ensemble = input_info['next_ensemble']

        self._app['params'] = ParamsSpecification.deserialize(
            self._app['params'])

        # Convert run statuses to enums
        for run_id in self._runs:
            self._runs[run_id]['status'] = constants.Status(
                self._runs[run_id]['status'])
Ejemplo n.º 3
0
    def app(self, name=None):
        """
        Get app information. Specific applications selected by `name`,
        otherwise first entry in database 'app' selected.

        Parameters
        ----------
        name : str or None
            Name of selected app, if `None` given then first app will be
            selected.

        Returns
        -------
        dict:
            Application information.
        """

        if name is None:
            logging.warning('No app name provided so using first app '
                            'in database')
            selected = self.session.query(AppTable).all()
        else:
            selected = self.session.query(AppTable).filter_by(name=name).all()

        if len(selected) == 0:
            message = f'No entry for app: ({name}).'
            logger.critical(message)
            raise RuntimeError(message)
        if len(selected) > 1:
            message = f'Too many apps called: ({name}).'
            logger.critical(message)
            raise RuntimeError(message)

        selected_app = selected[0]

        decoderspec = selected_app.decoderspec
        if decoderspec is not None:
            decoderspec = ast.literal_eval(selected_app.decoderspec)

        app_dict = {
            'id': selected_app.id,
            'name': selected_app.name,
            'input_encoder': selected_app.input_encoder,
            'output_decoder': selected_app.output_decoder,
            'collater': selected_app.collater,
            'params': ParamsSpecification.deserialize(selected_app.params),
            'decoderspec': decoderspec
        }

        return app_dict
Ejemplo n.º 4
0
    def add_app(self,
                name=None,
                params=None,
                decoderspec=None,
                encoder=None,
                decoder=None,
                set_active=True):
        """Add an application to the CampaignDB.

        Parameters
        ----------
        name : str
            Name of the application.
        params : dict
            Description of the parameters to associate with the application.
        decoderspec : dict
            A Cerberus validation dictionary for the output of the decoder
            if left None, will not be used.
        encoder : :obj:`easyvvuq.encoders.base.BaseEncoder`
            Encoder element to convert parameters into application run inputs.
        decoder : :obj:`easyvvuq.decoders.base.BaseDecoder`
            Decoder element to convert application run output into data for
            VVUQ analysis.
        set_active: bool
            Should the added app be set to be the currently active app?

        Returns
        -------

        """

        # Verify input parameters dict
        paramsspec = ParamsSpecification(params, appname=name)

        # validate application input
        app = AppInfo(name=name,
                      paramsspec=paramsspec,
                      decoderspec=decoderspec,
                      encoder=encoder,
                      decoder=decoder)

        self.campaign_db.add_app(app)
        if set_active:
            self.set_app(app.name)
Ejemplo n.º 5
0
    def add_app(self, name=None, params=None, fixtures=None,
                encoder=None, decoder=None, collater=None,
                set_active=True):
        """Add an application to the CampaignDB.

        Parameters
        ----------
        name : str
            Name of the application.
        params : dict
            Description of the parameters to associate with the application.
        fixtures : dict
            Description of files/assets.
        encoder : :obj:`easyvvuq.encoders.base.BaseEncoder`
            Encoder element to convert parameters into application run inputs.
        decoder : :obj:`easyvvuq.decoders.base.BaseDecoder`
            Decoder element to convert application run output into data for
            VVUQ analysis.
        collater : obj:`easyvvuq.collate.base.BaseCollationElement`
            Collation element for this app.
        set_active: bool
            Should the added app be set to be the currently active app?

        Returns
        -------

        """

        # Verify input parameters dict
        paramsspec = ParamsSpecification(params, appname=name)

        # validate application input
        app = AppInfo(
            name=name,
            paramsspec=paramsspec,
            fixtures=fixtures,
            encoder=encoder,
            decoder=decoder,
            collater=collater
        )

        self.campaign_db.add_app(app)
        if set_active:
            self.set_app(app.name)
Ejemplo n.º 6
0
    def app(self, name=None):
        """
        Get app information. Specific applications selected by `name`,
        otherwise first entry in database 'app' selected.

        Parameters
        ----------
        name : str or None
            Name of selected app, if `None` given then first app will be
            selected.

        Returns
        -------
        dict:
            Application information.
        """

        if name is None:
            selected = self.session.query(AppTable).all()
        else:
            selected = self.session.query(AppTable).filter_by(name=name).all()

        if len(selected) == 0:
            message = f'No entry for app: ({name}).'
            logger.critical(message)
            raise RuntimeError(message)
        if len(selected) > 1:
            message = f'Too many apps called: ({name}).'
            logger.critical(message)
            raise RuntimeError(message)

        selected_app = selected[0]

        app_dict = {
            'id': selected_app.id,
            'name': selected_app.name,
            'params': ParamsSpecification.deserialize(selected_app.params),
            'actions': selected_app.actions,
        }

        return app_dict