eelib.data.database.hdf5

Interface for the event-based HDF5 database.

Within this interface mosaik functionalities are used. Copyright (c) LGPL

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

Classes

Hdf5Database

HDF5 Database class

Attributes

meta

meta
class Hdf5Database

Bases: mosaik_api.Simulator

HDF5 Database class Inherits mosaik simulator class for management.

init(sid, time_resolution, scenario_config, series_path=(None, None))

Initialize HDF5 Database Entity.

Parameters:
  • sid (str) – string id of the entity to be created

  • time_resolution (float) – timely resolution of the simulation scenario

  • scenario_config (dict) – configurations of the simulation

  • series_path (tuple) – path for the series to be stored. Defaults to (None, None).

Returns:

meta description of the simulator

Return type:

meta

create(num, model, filename, buf_size=1000, dataset_opts=None)

Creates instances of the HDF5 output database.

Parameters:
  • num (int) – Number of hdf5 db models to be created

  • model (str) – Description of the created hdf5 db entity

  • filename (str) – Directory of the hdf5 file

  • buf_size (int) – Number of elements to be stored before writing into DB. Defaults to 1000

  • dataset_opts (dict) – Potential set of options for the dataset. Defaults to None.

Raises:
  • ValueError – Error if more than one hdf5 DB is to be created

  • ValueError – Error if an unknown model type (not Database) is given

Returns:

discription of the hdf5 DB entity with ID, type and relations

Return type:

dict

setup_done()

Check if setup of the DB is done.

Yields:

list – related entity for the simulator (given by mosaik)

step(time, inputs, max_advance)

Performs simulation step saving/buffering data and storing it into the DB. Core function of mosaik.

Parameters:
  • time (int) – current simulation time (given by mosaik)

  • inputs (dict) – allocation of return values to specific models

  • max_advance (int) – simulation time until the simulator can safely advance it’s internal time without causing any causality errors.

Returns:

next time step (when orchestrator calls again)

Return type:

int

_store_relations()

Query relations graph and store it in the database.

Yields:

list – related entities of simulator (given by mosaik)

_create_dataset(src_id, attr, dtype, ds_size, buf, buf_size)

Create a dataset for the attribute attr of entity src_id. The dataset will use the type dtype and will have the size ds_size. Also initialize the buffer buf with size buf_size.

Parameters:
  • src_id (str) – entity for the dataset to be stored in hdf5 file

  • attr (str) – attribute to be saved

  • dtype (type) – Type of the attribute

  • ds_size (int) – number of data elements to be stored

  • buf (dict) – storing of buffered elements within a list

  • buf_size (int) – number of elements to be buffered before storing

_get_group(eid)

Get or create group for entity eid.

Parameters:

eid (str) – entity identification string

Returns:

hdf5 file group element for data to be stored into

Return type:

Group

_get_supergroup(eid)

Get or create supergroup for entity eid using pattern.

Parameters:

eid (str) – entity identification string

Raises:

ValueError – Error if entity ID was not given in correct format

Returns:

supergroup for the data to be stored into

Return type:

SuperGroup

_store_dict(group, dictionary, dataset_name)

Store a dictionary as a dataset in a given group.

Parameters:
  • dictionary (dict) – dictionary to be stored

  • group (Group) – the group to store the data in

  • dataset_name (str) – the name of the dataset

_store_json(group, data, dataset_name)

Store json-like data as a dataset in a given group.

Parameters:
  • data (Any) – data to be stored

  • group (Group) – the group to store the data in

  • dataset_name (str) – the name of the dataset

_get_entity_path(eid)

Get the database path to a searched entity by its ID.

Parameters:

eid (str) – identification number of the entity to be searched

Returns:

path to the entity

Return type:

str