def __init__( self, model, year, scenario_name=None, model_group=None, configuration=None, xml_configuration=None, cache_directory=None, ): self.model_group = model_group self.explored_model = model if configuration is None: if xml_configuration is None: raise StandardError, "Either dictionary based or XML based configuration must be given." config = xml_configuration.get_run_configuration(scenario_name) else: config = Configuration(configuration) self.scenario_models = config["models"] if config.get("models_in_year", None) is not None and config["models_in_year"].get(year, None) is not None: del config["models_in_year"][year] if model is not None: dependent_models = config["models_configuration"][model]["controller"].get("dependencies", []) config["models"] = dependent_models if model_group is None: config["models"] = config["models"] + [{model: ["run"]}] else: config["models"] = config["models"] + [{model: {"group_members": [{model_group: ["run"]}]}}] else: config["models"] = [] config["years"] = [year, year] config["datasets_to_cache_after_each_model"] = [] config["flush_variables"] = False self.config = Resources(config) self.xml_configuration = xml_configuration if cache_directory is None: cache_directory = config["creating_baseyear_cache_configuration"].baseyear_cache.existing_cache_to_copy self.simulation_state = SimulationState( new_instance=True, base_cache_dir=cache_directory, start_time=config.get("base_year", 0) ) self.config["cache_directory"] = cache_directory SessionConfiguration( new_instance=True, package_order=self.config["dataset_pool_configuration"].package_order, in_storage=AttributeCache(), )
def __init__(self, model, year, scenario_name=None, model_group=None, configuration=None, xml_configuration=None, cache_directory=None): self.model_group = model_group self.explored_model = model if configuration is None: if xml_configuration is None: raise StandardError, "Either dictionary based or XML based configuration must be given." config = xml_configuration.get_run_configuration(scenario_name) else: config = Configuration(configuration) self.scenario_models = config['models'] if config.get('models_in_year', None) is not None and config['models_in_year'].get(year, None) is not None: del config['models_in_year'][year] if model is not None: dependent_models = config['models_configuration'][model]['controller'].get('dependencies', []) config['models'] = dependent_models if model_group is None: config['models'] = config['models'] + [{model: ["run"]}] else: config['models'] = config['models'] + [{model: {"group_members": [{model_group: ["run"]}]}}] else: config['models'] = [] config['years'] = [year, year] config["datasets_to_cache_after_each_model"]=[] config['flush_variables'] = False self.config = Resources(config) self.xml_configuration = xml_configuration if cache_directory is None: cache_directory = config['creating_baseyear_cache_configuration'].baseyear_cache.existing_cache_to_copy self.simulation_state = SimulationState(new_instance=True, base_cache_dir=cache_directory, start_time=config.get('base_year', 0)) self.config['cache_directory'] = cache_directory SessionConfiguration(new_instance=True, package_order=self.config['dataset_pool_configuration'].package_order, in_storage=AttributeCache())
def __init__(self, model, specification_module=None, xml_configuration=None, model_group=None, configuration={}, save_estimation_results=False): """ If 'specification_module' is given, it contains the specification defined as a dictionary in a module. Alternatively, the specification can be passed in an xml format in the 'xml_configuration' argument (which should be an instance of XMLConfiguration). If both of those arguments are None, the specification is taken from the cache. 'configuration' is an Opus configuration. It can contain an entry 'config_changes_for_estimation' which is a dictionary where keys are model names and values are controller changes for that model. If 'configuration' is None, it is taken from 'xml_configuration'. If xml_configuration is used, and if it has a non-empty expression library, the dictionary representing the expression library is added to the configuration under the key 'expression_library'. If save_estimation_results is True, the estimation results are saved in the output configuration (if given in 'configuration') and in the cache. """ self.specification_module = specification_module self.xml_configuration = xml_configuration self.model_group = model_group self.estimated_model = model self.explored_model = model if configuration is None: if self.xml_configuration is None: raise StandardError, "Either dictionary based or XML based configuration must be given." config = self.xml_configuration.get_estimation_configuration(model, model_group) else: config = Configuration(configuration) config_changes = config.get('config_changes_for_estimation', {}) specification_dict=None if self.xml_configuration is not None: specification_dict = self.xml_configuration.get_estimation_specification(model, model_group) if model_group is None: if model in config_changes.keys(): config.merge(config_changes[model]) else: config['models'] = [{model: ["estimate"]}] if specification_module is not None: config = update_controller_by_specification_from_module( config, model, specification_module) elif specification_dict is not None: config = update_controller_by_specification_from_dict(config, model, specification_dict) else: if model in config_changes.keys(): if model_group in config_changes[model]: config.merge(config_changes[model][model_group]) else: config.merge(config_changes[model]) else: config['models'] = [{model: {"group_members": [{model_group: ["estimate"]}]}}] if (specification_module is not None) or (specification_dict is not None): if '%s_%s' % (model_group, model) in config["models_configuration"].keys(): model_name_in_configuration = '%s_%s' % (model_group, model) else: model_name_in_configuration = model if specification_module is not None: config = update_controller_by_specification_from_module(config, model_name_in_configuration, specification_module) config["models_configuration"][model_name_in_configuration]["controller"]["prepare_for_estimate"]["arguments"]["specification_dict"] = "spec['%s']" % model_group else: config = update_controller_by_specification_from_dict(config, model, specification_dict[model_group]) if model.startswith('%s_' % model_group): config['model_name_for_coefficients'] = model else: config['model_name_for_coefficients'] = '%s_%s' % (model_group, model) Estimator.__init__(self, config, save_estimation_results=save_estimation_results)
def __init__(self, model, specification_module=None, xml_configuration=None, model_group=None, configuration={}, save_estimation_results=False): """ If 'specification_module' is given, it contains the specification defined as a dictionary in a module. Alternatively, the specification can be passed in an xml format in the 'xml_configuration' argument (which should be an instance of XMLConfiguration). If both of those arguments are None, the specification is taken from the cache. 'configuration' is an Opus configuration. It can contain an entry 'config_changes_for_estimation' which is a dictionary where keys are model names and values are controller changes for that model. If 'configuration' is None, it is taken from 'xml_configuration'. If xml_configuration is used, and if it has a non-empty expression library, the dictionary representing the expression library is added to the configuration under the key 'expression_library'. If save_estimation_results is True, the estimation results are saved in the output configuration (if given in 'configuration') and in the cache. """ self.specification_module = specification_module self.xml_configuration = xml_configuration self.model_group = model_group self.estimated_model = model if configuration is None: if self.xml_configuration is None: raise StandardError, "Either dictionary based or XML based configuration must be given." config = self.xml_configuration.get_estimation_configuration( model, model_group) else: config = Configuration(configuration) config_changes = config.get('config_changes_for_estimation', {}) specification_dict = None if self.xml_configuration is not None: specification_dict = self.xml_configuration.get_estimation_specification( model, model_group) if model_group is None: if model in config_changes.keys(): config.merge(config_changes[model]) else: config['models'] = [{model: ["estimate"]}] if specification_module is not None: config = update_controller_by_specification_from_module( config, model, specification_module) elif specification_dict is not None: config = update_controller_by_specification_from_dict( config, model, specification_dict) else: if model in config_changes.keys(): if model_group in config_changes[model]: config.merge(config_changes[model][model_group]) else: config.merge(config_changes[model]) else: config['models'] = [{ model: { "group_members": [{ model_group: ["estimate"] }] } }] if (specification_module is not None) or (specification_dict is not None): if '%s_%s' % (model_group, model) in config["models_configuration"].keys(): model_name_in_configuration = '%s_%s' % (model_group, model) else: model_name_in_configuration = model if specification_module is not None: config = update_controller_by_specification_from_module( config, model_name_in_configuration, specification_module) config["models_configuration"][model_name_in_configuration][ "controller"]["prepare_for_estimate"]["arguments"][ "specification_dict"] = "spec['%s']" % model_group else: config = update_controller_by_specification_from_dict( config, model, specification_dict[model_group]) if model.startswith('%s_' % model_group): config['model_name_for_coefficients'] = model else: config['model_name_for_coefficients'] = '%s_%s' % (model_group, model) Estimator.__init__(self, config, save_estimation_results=save_estimation_results)