eelib.utils.simulation_helper

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

get_entity_by_id(e_list, e_id)

Provides an entity with regard to a given id from the entity list.

get_entity_by_id_from_dict_list(e_dict_list, e_id)

Provides an entity with regard to a given id from the entity list.

create_plots(world, dir_graphs, bool_plot[, ...])

Create some plots after the simulation.

start_simulators(→ dict)

Start all model factories for the simulators listed in SIM_CONFIG and one for each model.

create_entities(→ dict)

Create all models based on simulators and their models dict given in sim_config.

create_entities_of_model(→ list)

Create model entities for a given ModelFactory object with regard to model name and input.

get_grid_components(→ dict)

Collect all components of a specific grid.

check_model_connect_config(model_connect_config)

Check the layout and input of a connection configuration for models.

connect_entities(world, dict_entities, ...)

Connect all model entities to each other based on the created models and their connections.

set_connection_direction(→ tuple[str, str])

Orders the weak-strong direction of two models by its model names to begin with.

connect_entities_in_grid(grid_model_config, grid, ...)

Connect all entities for a simulation containing a power grid.

connect_entities_to_db(sim_config, world, database, ...)

Connects all models (model entities) to the database.

connect_grid_to_db(sim_config_grid, world, database, ...)

Connects all grid components to the database.

connect_to_forecast(world, dict_entities, ...)

Create connections for the forecasts to work.

connect_entities_of_two_model_types(world, ...[, ...])

Connect the elements of two lists in both directions (if needed) via mosaik.

get_default_dirs(→ dict)

Gathers all needed directories resp. its paths based on eELib's default structure.

Attributes

_logger

_logger
get_entity_by_id(e_list: list, e_id: str)

Provides an entity with regard to a given id from the entity list.

Parameters:
  • e_list (list) – list of entities to be searched in

  • e_id (str) – id of the entity that we search for

Returns:

  1. model entity if found, otherwise None

  2. dict for the model entity (eid, full_id, type) if found, otherwise None

Return type:

entity, dict

get_entity_by_id_from_dict_list(e_dict_list: dict, e_id: str)

Provides an entity with regard to a given id from the entity list.

Parameters:
  • e_dict_list (dict) – dict with lists of entities (sorted by type) to be searched in

  • e_id (str) – id of the entity that we search for

Returns:

  1. model entity if found, otherwise None

  2. dict for the model entity (eid, full_id, type) if found, otherwise None

Return type:

entity, dict

create_plots(world: object, 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.

Parameters:
  • world (object) – mosaik world object to orchestrate the simulation process

  • dir_graphs (str) – direction where to save the create plots

  • bool_plot (bool) – whether to create the plots or not

  • slices_execution (list) – list of length 2 to assign start and end index of the execution graph to plot. Defaults to [0, 4].

start_simulators(sim_config: dict, world: object, scenario_config: dict) dict

Start all model factories for the simulators listed in SIM_CONFIG and one for each model.

Parameters:
  • sim_config (dict) – Information about the used simulators and their models

  • world (object) – mosaik world object to orchestrate the simulation process

  • scenario_config (dict) – parameters for the simulation scenario

Returns:

Contains all ModelFactorys sorted by the name of the corresponding model

Return type:

dict

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.

Parameters:
  • sim_config (dict) – Information about the used simulators and their models

  • model_data (dict) – dict containing all information about the to-be-created model entities

  • dict_simulators (dict) – dict of all used simulators with their ModelFactory-objects

  • grid_model_config (dict) – contains assigning the devices (by its type) to loads in the grid

Raises:

KeyError – If a model is to be created but does not exist for this simulator (ModelFactory)

Returns:

contains all created entities sorted by their model type

Return type:

dict

create_entities_of_model(model_factory: object, model_name: str, init_vals: list) list

Create model entities for a given ModelFactory object with regard to model name and input.

Parameters:
  • model_factory (object) – ModelFactory for a model

  • model_name (str) – name of the model to create entities for

  • init_vals (list) – initial values of the model (attributes to set)

Raises:
  • KeyError – If the ModelFactory has no such model type

  • 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)

Return type:

list

get_grid_components(grid_comps_list: list) dict

Collect all components of a specific grid.

Parameters:

grid_comps_list (list) – list of all grid components to collect from

Returns:

containing all grid components separated by type

Return type:

dict

check_model_connect_config(model_connect_config: list)

Check the layout and input of a connection configuration for models.

Parameters:

model_connect_config (list) – list of the model properties to connect

Raises:
  • TypeError – If the connection config is no list

  • TypeError – If an element of the connection config is neither a string nor a tuple

  • TypeError – If an connection config element is a tuple but not consisting of two strings

connect_entities(world: object, dict_entities: dict, model_connect_config: dict, dict_simulators: dict)

Connect all model entities to each other based on the created models and their connections.

Parameters:
  • world (object) – mosaik world object to orchestrate the simulation process

  • dict_entities (dict) – dict of all used model entity objects as lists, sorted by their type

  • model_connect_config (dict) – dict of all connected attributes between each model type

  • dict_simulators (dict) – dict of all used simulators with their ModelFactory-objects

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.

Parameters:
  • name_from_init (str) – name of model in initial from-position

  • name_to_init (str) – name of model in initial to-position

Raises:

ValueError – if no decision was found for connection of these two models

Returns:

names of models, first FROM- and second TO-position

Return type:

tuple[str, str]

connect_entities_in_grid(grid_model_config: dict, grid: object, grid_loads: list, world: object, model_connect_conf: dict, dict_entities: dict, dict_simulators: dict, architecture_models: list = ['RetailElectricityProvider', 'GridEMS'])

Connect all entities for a simulation containing a power grid. Includes connection between the devices in the grid and between devices (or EMS) and grid loads.

Parameters:
  • grid_model_config (dict) – contains assigning the devices (by its type) to loads in the grid

  • grid (object) – power grid entity

  • grid_loads (list) – list of all load objects in the power grid

  • world (object) – mosaik world object to orchestrate the simulation process

  • model_connect_conf (dict) – dict of all connected attributes between each model type

  • dict_entities (dict) – dict of all used model entity objects as lists, sorted by their type

  • dict_simulators (dict) – dict of all used simulators with their ModelFactory-objects

  • architecture_models (list) – all superordinate models to connect to each other and every ems

Raises:
  • ValueError – If more than one grid ems is created.

  • ValueError – If more than one retail electricity provider is created.

  • KeyError – No entity was created for a desired connection in the grid.

  • KeyError – Given grid load name from model_connect_conf not found in grid loads list.

  • ValueError – There are electric vehicles but no charging stations at a connection point.

  • KeyError – A grid load is planned to be connected to two different entities.

connect_entities_to_db(sim_config: dict, world: object, database: object, dict_entities: dict)

Connects all models (model entities) to the database.

Parameters:
  • sim_config (dict) – Information about the used simulators and their models

  • world (object) – mosaik world object to orchestrate the simulation process

  • database (object) – model object of the database for the simulation

  • dict_entities (dict) – dict of all used model entity objects

connect_grid_to_db(sim_config_grid: dict, world: object, database: object, dict_comps: dict)

Connects all grid components to the database.

Parameters:
  • sim_config_grid (dict) – Information about the used grid simulator and the components with a list of their output attributes

  • world (object) – mosaik world object to orchestrate the simulation process

  • database (object) – model object of the database for the simulation

  • dict_comps (dict) – dict of all used grid component entity objects, sorted by their type

connect_to_forecast(world: object, 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 to ems model and adding of the model entities to the forecasts list.

Parameters:
  • world (object) – mosaik world object to orchestrate the simulation process

  • dict_entities (dict) – dict of all used model entity objects

  • dict_simulators (dict) – dict of all used simulators with their ModelFactory-objects

  • forecast (object) – forecast model entity

  • forecast_sim (object) – simulator for the forecast model

  • connect_models_names (list) – model names to directly connect to forecast entity

connect_entities_of_two_model_types(world: object, entity_list_strong: list, entity_list_weak: list, model_connect_config_from_strong: list, model_connect_config_from_weak: list = [], sim_entities_weak: object = 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 ems.

Parameters:
  • world (object) – mosaik World object

  • entity_list_strong (list) – entities that have “strong” outgoing connections

  • entity_list_weak (list) – entities that have “weak” outgoing connections

  • model_connect_config_from_strong (list) – list of properties (str or tuple) to connect the two models types - from strong to weak

  • model_connect_config_from_weak (list) – list of properties (str or tuple) to connect the two models types - from weak to strong. Defaults to [].

  • sim_entities_weak (object) – Simulator of the “weak” entities for the adding of entities to the ems controlled entities. Defaults to None.

Raises:
  • TypeError – if given mosaik world is not correct (does not have connect method)

  • ValueError – if no strong connection properties are given but there are weak connections

get_default_dirs(dir_base, scenario: str = 'building', grid: str = 'example_grid_kerber.json', format_db: str = 'hdf5') dict

Gathers all needed directories resp. its paths based on eELib’s default structure.

Parameters:
  • dir_base (str) – string with path to root director

  • scenario (str) – Type of used scenario (like building, grid etc.). Defaults to “building”.

  • grid (str) – name of the grid file to use. Defaults to “example_grid_kerber.json”.

  • format_db (str) – format of the database. Defaults to None.

Raises:

FileNotFoundError – If model data for current simulation scenario not found

Returns:

all relevant paths for a simulation

Return type:

dict