emat/model/core_model.py
def run_experiments(
            self,
            design:pd.DataFrame=None,
            evaluator=None,
            *,
            design_name=None,
            db=None,
    ):
        """
        Runs a design of combined experiments using this model.

        A combined experiment includes a complete set of input values for
        all exogenous uncertainties (a Scenario) and all policy levers
        (a Policy). Unlike the perform_experiments function in the EMA Workbench,
        this method pairs each Scenario and Policy in sequence, instead
        of running all possible combinations of Scenario and Policy.
        This change ensures compatibility with the EMAT database modules, which
        preserve the complete set of input information (both uncertainties
        and levers) for each experiment.  To conduct a full cross-factorial set
        of experiments similar to the default settings for EMA Workbench,
        use a factorial design, by setting the `jointly` argument for the
        `design_experiments` to False, or by designing experiments outside
        of EMAT with your own approach.

        Args:
            design (pandas.DataFrame, optional): experiment definitions
                given as a DataFrame, where each exogenous uncertainties and
                policy levers is given as a column, and each row is an experiment.
            evaluator (ema_workbench.Evaluator, optional): Optionally give an
                evaluator instance.  If not given, a default SequentialEvaluator
                will be instantiated.
            design_name (str, optional): The name of a design of experiments to
                load from the database.  This design is only used if
                `design` is None.
            db (Database, optional): The database to use for loading and saving experiments.
                If none is given, the default database for this model is used.
                If there is no default db, and none is given here,
                the results are not stored in a database. Set to False to explicitly
                not use the default database, even if it exists.

        Returns:
            pandas.DataFrame:
                A DataFrame that contains all uncertainties, levers, and measures
                for the experiments.

        Raises:
            ValueError:
                If there are no experiments defined.  This includes
                the situation where `design` is given but no database is
                available.

        """

        from ema_workbench import Scenario, Policy, perform_experiments

        # catch user gives only a design, not experiment_parameters
        if isinstance(design, str) and design_name is None:
            design_name, design = design, None

        if design_name is None and design is None:
            raise ValueError(f"must give design_name or design")

        if db is None:
            db = self.db

        if design_name is not None and design is None:
            if not db:
                raise ValueError(f'cannot load design "{design_name}", there is no db')
            design = db.read_experiment_parameters(self.scope.name, design_name)

        if design.empty:
            raise ValueError(f"no experiments available")

        scenarios = [
            Scenario(**dict(zip(self.scope._get_uncertainty_and_constant_names(), i)))
            for i in design[self.scope._get_uncertainty_and_constant_names()].itertuples(index=False,
                                                                           name='ExperimentX')
        ]

        policies = [
            Policy(f"Incognito{n}", **dict(zip(self.scope.get_lever_names(), i)))
            for n,i in enumerate(design[self.scope.get_lever_names()].itertuples(index=False,
                                                                                 name='ExperimentL'))
        ]

        evaluator = prepare_evaluator(evaluator, self)

        with evaluator:
            experiments, outcomes = perform_experiments(
                self,
                scenarios=scenarios,
                policies=policies,
                zip_over={'scenarios', 'policies'},
                evaluator=evaluator,
            )
        experiments.index = design.index



        outcomes = pd.DataFrame.from_dict(outcomes)
        outcomes.index = design.index

        if db:
            db.write_experiment_measures(self.scope.name, self.metamodel_id, outcomes)

        # Put constants back into experiments
        experiments_ = experiments.drop(columns=['scenario', 'policy', 'model'])
        for i in self.scope.get_constants():
            experiments_[i.name] = i.value

        return self.ensure_dtypes(pd.concat([
            experiments_,
            outcomes
        ], axis=1, sort=False))

        Runs a design of combined experiments using this model.

        A combined experiment includes a complete set of input values for
        all exogenous uncertainties (a Scenario) and all policy levers
        (a Policy). Unlike the perform_experiments function in the EMA Workbench,
        this method pairs each Scenario and Policy in sequence, instead
        of running all possible combinations of Scenario and Policy.
        This change ensures compatibility with the EMAT database modules, which
        preserve the complete set of input information (both uncertainties
        and levers) for each experiment.  To conduct a full cross-factorial set
        of experiments similar to the default settings for EMA Workbench,
        use a factorial design, by setting the `jointly` argument for the
        `design_experiments` to False, or by designing experiments outside
        of EMAT with your own approach.

        Args:
            design (pandas.DataFrame, optional): experiment definitions
                given as a DataFrame, where each exogenous uncertainties and
                policy levers is given as a column, and each row is an experiment.
            evaluator (ema_workbench.Evaluator, optional): Optionally give an
                evaluator instance.  If not given, a default SequentialEvaluator
                will be instantiated.
            design_name (str, optional): The name of a design of experiments to
                load from the database.  This design is only used if
                `design` is None.
            db (Database, optional): The database to use for loading and saving experiments.
                If none is given, the default database for this model is used.
                If there is no default db, and none is given here,
                the results are not stored in a database. Set to False to explicitly
                not use the default database, even if it exists.

        Returns:
            pandas.DataFrame:
                A DataFrame that contains all uncertainties, levers, and measures
                for the experiments.

        Raises:
            ValueError:
                If there are no experiments defined.  This includes
                the situation where `design` is given but no database is
                available.

        
Runs a design of combined experiments using this model.
A combined experiment includes a complete set of input values for
all exogenous uncertainties (a Scenario) and all policy levers
(a Policy). Unlike the perform_experiments function in the EMA Workbench,
this method pairs each Scenario and Policy in sequence, instead
of running all possible combinations of Scenario and Policy.
This change ensures compatibility with the EMAT database modules, which
preserve the complete set of input information (both uncertainties
and levers) for each experiment.  To conduct a full cross-factorial set
of experiments similar to the default settings for EMA Workbench,
use a factorial design, by setting the `jointly` argument for the
`design_experiments` to False, or by designing experiments outside
of EMAT with your own approach.
Runs a design of combined experiments using this model . A combined experiment includes a complete set of input values for all exogenous uncertainties ( a Scenario ) and all policy levers ( a Policy ) . Unlike the perform_experiments function in the EMA Workbench this method pairs each Scenario and Policy in sequence instead of running all possible combinations of Scenario and Policy . This change ensures compatibility with the EMAT database modules which preserve the complete set of input information ( both uncertainties and levers ) for each experiment . To conduct a full cross - factorial set of experiments similar to the default settings for EMA Workbench use a factorial design by setting the ` jointly ` argument for the ` design_experiments ` to False or by designing experiments outside of EMAT with your own approach .
def run_experiments(
            self,
            design:pd.DataFrame=None,
            evaluator=None,
            *,
            design_name=None,
            db=None,
    ):
        from ema_workbench import Scenario, Policy, perform_experiments
        if isinstance(design, str) and design_name is None:
            design_name, design = design, None
        if design_name is None and design is None:
            raise ValueError(f"must give design_name or design")
        if db is None:
            db = self.db
        if design_name is not None and design is None:
            if not db:
                raise ValueError(f'cannot load design "{design_name}", there is no db')
            design = db.read_experiment_parameters(self.scope.name, design_name)
        if design.empty:
            raise ValueError(f"no experiments available")
        scenarios = [
            Scenario(**dict(zip(self.scope._get_uncertainty_and_constant_names(), i)))
            for i in design[self.scope._get_uncertainty_and_constant_names()].itertuples(index=False,
                                                                           name='ExperimentX')
        ]
        policies = [
            Policy(f"Incognito{n}", **dict(zip(self.scope.get_lever_names(), i)))
            for n,i in enumerate(design[self.scope.get_lever_names()].itertuples(index=False,
                                                                                 name='ExperimentL'))
        ]
        evaluator = prepare_evaluator(evaluator, self)
        with evaluator:
            experiments, outcomes = perform_experiments(
                self,
                scenarios=scenarios,
                policies=policies,
                zip_over={'scenarios', 'policies'},
                evaluator=evaluator,
            )
        experiments.index = design.index
        outcomes = pd.DataFrame.from_dict(outcomes)
        outcomes.index = design.index
        if db:
            db.write_experiment_measures(self.scope.name, self.metamodel_id, outcomes)
        experiments_ = experiments.drop(columns=['scenario', 'policy', 'model'])
        for i in self.scope.get_constants():
            experiments_[i.name] = i.value
        return self.ensure_dtypes(pd.concat([
            experiments_,
            outcomes
        ], axis=1, sort=False))
def run_experiments ( self , design : pd . DataFrame = None , evaluator = None , * , design_name = None , db = None , ) : from ema_workbench import Scenario , Policy , perform_experiments if isinstance ( design , str ) and design_name is None : design_name , design = design , None if design_name is None and design is None : raise ValueError ( f"must give design_name or design" ) if db is None : db = self . db if design_name is not None and design is None : if not db : raise ValueError ( f'cannot load design "{design_name}", there is no db' ) design = db . read_experiment_parameters ( self . scope . name , design_name ) if design . empty : raise ValueError ( f"no experiments available" ) scenarios = [ Scenario ( ** dict ( zip ( self . scope . _get_uncertainty_and_constant_names ( ) , i ) ) ) for i in design [ self . scope . _get_uncertainty_and_constant_names ( ) ] . itertuples ( index = False , name = 'ExperimentX' ) ] policies = [ Policy ( f"Incognito{n}" , ** dict ( zip ( self . scope . get_lever_names ( ) , i ) ) ) for n , i in enumerate ( design [ self . scope . get_lever_names ( ) ] . itertuples ( index = False , name = 'ExperimentL' ) ) ] evaluator = prepare_evaluator ( evaluator , self ) with evaluator : experiments , outcomes = perform_experiments ( self , scenarios = scenarios , policies = policies , zip_over = { 'scenarios' , 'policies' } , evaluator = evaluator , ) experiments . index = design . index outcomes = pd . DataFrame . from_dict ( outcomes ) outcomes . index = design . index if db : db . write_experiment_measures ( self . scope . name , self . metamodel_id , outcomes ) experiments_ = experiments . drop ( columns = [ 'scenario' , 'policy' , 'model' ] ) for i in self . scope . get_constants ( ) : experiments_ [ i . name ] = i . value return self . ensure_dtypes ( pd . concat ( [ experiments_ , outcomes ] , axis = 1 , sort = False ) )
Runs a design of combined experiments using this model.
Runs a design of combined experiments using this model .
"""
        Runs a design of combined experiments using this model.

        A combined experiment includes a complete set of input values for
        all exogenous uncertainties (a Scenario) and all policy levers
        (a Policy). Unlike the perform_experiments function in the EMA Workbench,
        this method pairs each Scenario and Policy in sequence, instead
        of running all possible combinations of Scenario and Policy.
        This change ensures compatibility with the EMAT database modules, which
        preserve the complete set of input information (both uncertainties
        and levers) for each experiment.  To conduct a full cross-factorial set
        of experiments similar to the default settings for EMA Workbench,
        use a factorial design, by setting the `jointly` argument for the
        `design_experiments` to False, or by designing experiments outside
        of EMAT with your own approach.

        Args:
            design (pandas.DataFrame, optional): experiment definitions
                given as a DataFrame, where each exogenous uncertainties and
                policy levers is given as a column, and each row is an experiment.
            evaluator (ema_workbench.Evaluator, optional): Optionally give an
                evaluator instance.  If not given, a default SequentialEvaluator
                will be instantiated.
            design_name (str, optional): The name of a design of experiments to
                load from the database.  This design is only used if
                `design` is None.
            db (Database, optional): The database to use for loading and saving experiments.
                If none is given, the default database for this model is used.
                If there is no default db, and none is given here,
                the results are not stored in a database. Set to False to explicitly
                not use the default database, even if it exists.

        Returns:
            pandas.DataFrame:
                A DataFrame that contains all uncertainties, levers, and measures
                for the experiments.

        Raises:
            ValueError:
                If there are no experiments defined.  This includes
                the situation where `design` is given but no database is
                available.

        """ # catch user gives only a design, not experiment_parameters # Put constants back into experiments
A DataFrame that contains all uncertainties, levers, and measures
for the experiments.
A DataFrame that contains all uncertainties levers and measures for the experiments .
pandas.DataFrame
If there are no experiments defined.  This includes
the situation where `design` is given but no database is
available.
If there are no experiments defined . This includes the situation where ` design ` is given but no database is available .
ValueError
self
design
pd.DataFrame
experiment definitions
given as a DataFrame, where each exogenous uncertainties and
policy levers is given as a column, and each row is an experiment.
experiment definitions given as a DataFrame where each exogenous uncertainties and policy levers is given as a column and each row is an experiment .
evaluator
Optionally give an
evaluator instance.  If not given, a default SequentialEvaluator
will be instantiated.
Optionally give an evaluator instance . If not given a default SequentialEvaluator will be instantiated .
design_name
The name of a design of experiments to
load from the database.  This design is only used if
`design` is None.
The name of a design of experiments to load from the database . This design is only used if ` design ` is None .
db
The database to use for loading and saving experiments.
If none is given, the default database for this model is used.
If there is no default db, and none is given here,
the results are not stored in a database. Set to False to explicitly
not use the default database, even if it exists.
The database to use for loading and saving experiments . If none is given the default database for this model is used . If there is no default db and none is given here the results are not stored in a database . Set to False to explicitly not use the default database even if it exists .