mosaik.util — Utility classes and functions

This module contains some utility functions and classes.

mosaik.util.connect_many_to_one(world, src_set, dest, *attrs, async_requests=False)

connect() each entity in src_set to dest.

See the connect() for more details.

mosaik.util.connect_randomly(world, src_set, dest_set, *attrs, evenly=True, max_connects=inf)

Randomly connect() the entities from src_set to the entities from dest_set and return a subset of dest_set containing all entities with a connection.

world is an instance of the World to which the entities belong.

src_set and dest_set are iterables containing Entity instances. src_set may be empty, dest_set must not be empty. Each entity of src_set will be connected to an entity of dest_set, but not every entity of dest_set will necessarily have a connection (e.g., if you connect a set of three entities to a set of four entities). A set of all entities from dest_set, to which at least one entity from src_set was connected, will be returned.

attrs is a list of attribute names of pairs as in connect().

If the flag evenly is set to True, entities connections will be distributed as evenly as possible. That means if you connect a set of three entities to a set of three entities, there will be three 1:1 connections; if you connect four entities to three entities, there will be one 2:1 and two 1:1 connections. If evenly is set to False, connections will be truly random. That means if you connect three entities to three entities, you may either have three 1:1 connections, one 2:1 and two 1:1 connections or just one 3:1 connection.

max_connects lets you set the maximum number of connections that an entity of dest_set may receive. This argument is only taken into account if evenly is set to False.

mosaik.util.plot_execution_time(world, folder='figures', hdf5path=None, dpi=600, format='png', show_plot=True, slice=None)

Creates an image visualizing the execution time of the different simulators of a mosaik scenario.

Parameters:
  • world – mosaik world object

  • folder – folder to store the image (only if no hdf5path is provided)

  • hdf5path – Path to HDF5 file, which will be used as path for the created image

  • dpi – DPI for created images

  • format – format for created image

  • slice – reduce the timeframe that you show in the plot. Usage as python list slicing,

Show_plot:

open a window to show the plot

i.e., negative values are possible to start from the end of the list. Jumps are not possible. Slice needs to be a two-parameter integer list, e.g. [0,5]. :return: no return object, but image file will be written to file system

mosaik.util.plot_dataflow_graph(world, folder='figures', hdf5path=None, dpi=600, format='png', show_plot=True)

Creates an image visualizing the data flow graph of a mosaik scenario. Using the spring_layout from Matplotlib (Fruchterman-Reingold force-directed algorithm) to position the nodes.

Parameters:
  • world – mosaik world object

  • folder – folder to store the image (only if no hdf5path is provided)

  • hdf5path – Path to HDF5 file, which will be used as path for the created image

  • dpi – DPI for created images

  • format – format for created image

Show_plot:

open a window to show the plot

Returns:

no return object, but image file will be written to file system

mosaik.util.plot_execution_graph(world, title='', folder='figures', hdf5path=None, dpi=600, format='png', show_plot=True, slice=None)

Creates an image visualizing the execution graph of a mosaik scenario.

Parameters:
  • world – mosaik world object

  • title

  • folder – folder to store the image (only if no hdf5path is provided)

  • hdf5path – Path to HDF5 file, which will be used as path for the created image

  • dpi – DPI for created images

  • format – format for created image

  • slice – reduce the timeframe that you show in the plot. Usage as python list slicing,

Show_plot:

open a window to show the plot

i.e., negative values are possible to start from the end of the list. Jumps are not possible. Slice needs to be a two-parameter integer list, e.g. [0,5]. :return: no return object, but image file will be written to file system

mosaik.util.split_node(node)
Parameters:

node

Returns:

mosaik.util.plot_execution_time_per_simulator(world, folder='figures', hdf5path=None, dpi=600, format='png', show_plot=True, slice=None)

Creates images visualizing the execution time of each of the different simulators of a mosaik scenario.

Parameters:
  • world – mosaik world object

  • folder – folder to store the image (only if no hdf5path is provided)

  • hdf5path – Path to HDF5 file, which will be used as path for the created image

  • dpi – DPI for created images

  • format – format for created image

  • slice – reduce the timeframe that you show in the plot. Usage as python list slicing,

Show_plot:

open a window to show the plot

i.e., negative values are possible to start from the end of the list. Jumps are not possible. Slice needs to be a two-parameter integer list, e.g. [0,5]. :return: no return object, but image file will be written to file system