:py:mod:`eelib.utils.simulation_helper` ======================================= .. py:module:: eelib.utils.simulation_helper .. autoapi-nested-parse:: Helper methods for retrieving simulation objects from lists or listing available entitities. | Author: elenia@TUBS | Copyright 2024 elenia | This file is part of eELib, which is free software under the terms of the GNU GPL Version 3. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: eelib.utils.simulation_helper.get_entity_by_id eelib.utils.simulation_helper.get_entity_by_id_from_dict_list eelib.utils.simulation_helper.create_plots eelib.utils.simulation_helper.start_simulators eelib.utils.simulation_helper.create_entities eelib.utils.simulation_helper.create_entities_of_model eelib.utils.simulation_helper.get_grid_components eelib.utils.simulation_helper.check_model_connect_config eelib.utils.simulation_helper.connect_entities eelib.utils.simulation_helper.set_connection_direction eelib.utils.simulation_helper.connect_entities_in_grid eelib.utils.simulation_helper.connect_entities_to_db eelib.utils.simulation_helper.connect_grid_to_db eelib.utils.simulation_helper.remove_cs_ev_conn_from_connect_config eelib.utils.simulation_helper.connect_to_forecast eelib.utils.simulation_helper.connect_entities_of_two_model_types eelib.utils.simulation_helper.check_entities_connections eelib.utils.simulation_helper.get_default_dirs Attributes ~~~~~~~~~~ .. autoapisummary:: eelib.utils.simulation_helper._logger .. py:data:: _logger .. py:function:: get_entity_by_id(e_list: list, e_id: str) -> tuple[object, dict] Provides an entity with regard to a given id from the entity list. :param e_list: list of entities to be searched in :type e_list: list :param e_id: id of the entity that we search for :type e_id: str :returns: model entity if found, otherwise None AND dict for the model entity (eid, full_id, type) if found, otherwise None :rtype: tuple[object, dict] .. py:function:: get_entity_by_id_from_dict_list(e_dict_list: dict, e_id: str) -> tuple[object, dict] Provides an entity with regard to a given id from the entity list. :param e_dict_list: dict with lists of entities (sorted by type) to be searched in :type e_dict_list: dict :param e_id: id of the entity that we search for :type e_id: str :returns: model entity if found, otherwise None AND dict for the model entity (eid, full_id, type) if found, otherwise None :rtype: tuple[object, dict] .. py:function:: create_plots(world: mosaik.World, dir_graphs: str, bool_plot: bool, slices_execution: list = [0, 4]) Create some plots after the simulation. Especially the execution_graph take some time to create and should not be created for every simulation. :param world: mosaik world object to orchestrate the simulation process :type world: World :param dir_graphs: direction where to save the create plots :type dir_graphs: str :param bool_plot: whether to create the plots or not :type bool_plot: bool :param slices_execution: list of length 2 to assign start and end index of the execution graph to plot. Defaults to [0, 4]. :type slices_execution: list .. py:function:: start_simulators(sim_config: dict, world: mosaik.World, scenario_config: dict) -> dict Start all model factories for the simulators listed in SIM_CONFIG and one for each model. :param sim_config: Information about the used simulators and their models :type sim_config: dict :param world: mosaik world object to orchestrate the simulation process :type world: World :param scenario_config: parameters for the simulation scenario :type scenario_config: dict :returns: Contains all ModelFactorys sorted by the name of the corresponding model :rtype: dict .. py:function:: create_entities(sim_config: dict, model_data: dict, dict_simulators: dict, grid_model_config: dict = {}) -> dict Create all models based on simulators and their models dict given in sim_config. :param sim_config: Information about the used simulators and their models :type sim_config: dict :param model_data: dict containing all information about the to-be-created model entities :type model_data: dict :param dict_simulators: dict of all used simulators with their ModelFactory-objects :type dict_simulators: dict :param grid_model_config: contains assigning the devices (by its type) to loads in the grid :type grid_model_config: dict :returns: contains all created entities sorted by their model type :rtype: dict .. py:function:: create_entities_of_model(model_factory: object, model_name: str, init_vals: dict) -> list Create model entities for a given ModelFactory object with regard to model name and input. :param model_factory: ModelFactory for a model :type model_factory: object :param model_name: name of the model to create entities for :type model_name: str :param init_vals: initial values of the model (attributes to set) :type init_vals: dict :raises KeyError: If the ModelFactory has no such model type :raises TypeError: If the initial values were given in the wrong format :returns: all created model entities in one list (empty if no entity to create) :rtype: list .. py:function:: get_grid_components(grid_comps_list: list) -> dict Collect all components of a specific grid. :param grid_comps_list: list of all grid components to collect from :type grid_comps_list: list :returns: containing all grid components separated by type :rtype: dict .. py:function:: check_model_connect_config(model_connect_config: list) Check the layout and input of a connection configuration for models. :param model_connect_config: list of the model properties to connect :type model_connect_config: list :raises TypeError: If the connection config is no list OR if an element of the connection config is neither a string nor a tuple OR if an connection config element is a tuple but not consisting of two strings. .. py:function:: connect_entities(world: mosaik.World, dict_entities: dict, model_connect_config: dict, dict_simulators: dict = {}, cs_ev_connection: dict = {}) Connect all model entities to each other based on the created models and their connections. :param world: mosaik world object to orchestrate the simulation process :type world: World :param dict_entities: dict of all used model entity objects as lists, sorted by their type :type dict_entities: dict :param model_connect_config: dict of all connected attributes between each model type :type model_connect_config: dict :param dict_simulators: dict of all used simulators with their ModelFactory-objects. Defaults to {}. :type dict_simulators: dict :param cs_ev_connection: ev connections to charging stations. Defaults to {}. :type cs_ev_connection: dict :raises ValueError: If cs-ev connection given, but the entities cannot be found .. py:function:: set_connection_direction(name_from_init: str, name_to_init: str) -> tuple[str, str] Orders the weak-strong direction of two models by its model names to begin with. :param name_from_init: name of model in initial from-position :type name_from_init: str :param name_to_init: name of model in initial to-position :type name_to_init: str :raises ValueError: if no decision was found for connection of these two models :returns: names of models, first FROM- and second TO-position :rtype: tuple[str, str] .. py:function:: connect_entities_in_grid(grid_model_config: dict, grid: object, grid_loads: list, world: mosaik.World, model_connect_conf: dict, dict_entities: dict, dict_simulators: dict, architecture_models: list = get_architecture_models(), grid_trafos: list = None) Connect all entities for a simulation containing a power grid. Includes connection between the devices in the grid and between HEMS and grid loads. :param grid_model_config: contains assigning the devices (by its type) to loads in the grid :type grid_model_config: dict :param grid: power grid entity :type grid: object :param grid_loads: list of all load objects in the power grid :type grid_loads: list :param world: mosaik world object to orchestrate the simulation process :type world: World :param model_connect_conf: dict of all connected attributes between each model type :type model_connect_conf: dict :param dict_entities: dict of all used model entity objects as lists, sorted by their type :type dict_entities: dict :param dict_simulators: dict of all used simulators with their ModelFactory-objects :type dict_simulators: dict :param architecture_models: all superordinate models to connect to each other and every HEMS :type architecture_models: list :param grid_trafos: list of all trafo objects in the power grid. Defaults to None :type grid_trafos: list :raises ValueError: If more than one entity of any architecture model type is created OR if there are electric vehicles but no charging stations at a connection point. :raises KeyError: No entity was created for a desired connection in the grid OR if given grid load name from model_connect_conf not found in grid loads list OR if a grid load is planned to be connected to two different entities. .. py:function:: connect_entities_to_db(sim_config: dict, world: mosaik.World, database: object, dict_entities: dict) Connects all models (model entities) to the database. :param sim_config: Information about the used simulators and their models :type sim_config: dict :param world: mosaik world object to orchestrate the simulation process :type world: World :param database: model object of the database for the simulation :type database: object :param dict_entities: dict of all used model entity objects :type dict_entities: dict .. py:function:: connect_grid_to_db(sim_config_grid: dict, world: mosaik.World, database: object, dict_comps: dict) Connects all grid components to the database. :param sim_config_grid: Information about the used grid simulator and the components with a list of their output attributes :type sim_config_grid: dict :param world: mosaik world object to orchestrate the simulation process :type world: World :param database: model object of the database for the simulation :type database: object :param dict_comps: dict of all used grid component entity objects, sorted by their type :type dict_comps: dict .. py:function:: remove_cs_ev_conn_from_connect_config(connect_config: dict) -> dict In copied dict, remove information on connections between cs and ev. :param connect_config: info on connections between devices (and grid) :type connect_config: dict :returns: cleared dict with info on connections (without cs_ev_connection in 2nd order) :rtype: dict .. py:function:: connect_to_forecast(world: mosaik.World, dict_entities: dict, dict_simulators: dict, forecast: object, forecast_sim: object, connect_models_names: list) Create connections for the forecasts to work. Includes mosaik connections from forecast to model and adding of the model entities to the forecasts list. :param world: mosaik world object to orchestrate the simulation process :type world: World :param dict_entities: dict of all used model entity objects :type dict_entities: dict :param dict_simulators: dict of all used simulators with their ModelFactory-objects :type dict_simulators: dict :param forecast: forecast model entity :type forecast: object :param forecast_sim: simulator for the forecast model :type forecast_sim: object :param connect_models_names: model names to directly connect to forecast entity :type connect_models_names: list .. py:function:: connect_entities_of_two_model_types(world: mosaik.World, entity_list_strong: list, entity_list_weak: list, model_connect_config_from_strong: list, model_connect_config_from_weak: list = [], sim_ent_strong: object = None, sim_ent_weak: object = None) -> None Connect the elements of two lists in both directions (if needed) via mosaik. Also add elements to list of controlled entities if the "weak" entity is an hems/dems. :param world: mosaik World object :type world: World :param entity_list_strong: entities that have "strong" outgoing connections :type entity_list_strong: list :param entity_list_weak: entities that have "weak" outgoing connections :type entity_list_weak: list :param model_connect_config_from_strong: list of properties (str or tuple) to connect the two models types - from strong to weak :type model_connect_config_from_strong: list :param model_connect_config_from_weak: list of properties (str or tuple) to connect the two models types - from weak to strong. Defaults to []. :type model_connect_config_from_weak: list :param sim_ent_strong: Simulator of the "strong" entities for the adding of entities to the hems/dems controlled entities. Defaults to None. :type sim_ent_strong: object :param sim_ent_weak: Simulator of the "weak" entities for the adding of entities to the hems/dems controlled entities. Defaults to None. :type sim_ent_weak: object :raises TypeError: if given mosaik world is not correct (does not have connect method) :raises ValueError: if no strong connection properties are given but there are weak connections :returns: Nothing is returned :rtype: None .. py:function:: check_entities_connections(world: mosaik.World, dict_entities: dict) Check that there are adjacent connections for each entity of the simulation. :param world: mosaik World object :type world: World :param dict_entities: dict of all used model entity objects :type dict_entities: dict .. py:function:: get_default_dirs(scenario: str, format_db: str = 'hdf5') -> dict[str, str] Gathers all needed directories and paths based on eELib's default structure. The output dict features the following keys: - "DATA": dir with profile data - "INPUT_DATA": filename with configuration of models (and grid) - "DATABASE_FILENAME": filename of database storing all results - "GRAPHS": dir for output graphs :param scenario: Type of used scenario (like building, grid etc.). :type scenario: str :param format_db: format of the database. :type format_db: str, optional :raises FileNotFoundError: If model data for current simulation scenario not found :returns: Includes all relevant paths for a simulation. :rtype: dict[str, str]