Return a deepcopy of x.

x may be or contain the following types:

{dict, set, list, tuple, datetime, string, int, float, bool, NoneType}
class maverig.models.model.ElemPort(elem_id, port)

Bases: tuple

An element port instance (e.g. ElemPort('CSV.House_1', '0')) describes a specific port (e.g. '0') of an element specified by elem_id (e.g. 'CSV.House_1'), which may be docked to other element ports.

Element ports are often abbreviated with ep.

In all model methods, element ports can also be passed as list (e.g. ['CSV.House_1', '0'] and will be automatically converted to ElemPort when needed.


Alias for field number 0


Alias for field number 1

class maverig.models.model.ProgramMode

Bases: object

Represents the main program mode: composition, simulation, or simulation paused.

composition = 'composition mode'

Composition mode, where scenario can be edited.

simulation = 'simulation mode'

Simulation mode, where simulation or recorded simulation history “video” is running.

simulation_paused = 'simulation paused'

Simulation paused mode, where simulation is paused.

class maverig.models.model.Mode

Bases: object

Represents the currently selected mode for the composition.

selection = 'selection mode'

In selection mode, all elements may be moved and edited.

hand = 'hand mode'

In hand mode, the complete scenario is movable and elements can’t be edited or created.

comp = 'component mode'

In component mode, only elements of a the selected component in mode panel may be edited and created.

sim = 'simulation mode'

In simulation mode, the scenario can only be watched and elements can’t be edited. Similar to hand mode but may differ in element visualizations.

class maverig.models.model.Model

Bases: object

Model manages the complete scenario state: - simulation start and end time - elements as component instances and their dockings - clipboard - selected elements - modi (comp_mode, selection_mode, hand_mode) and - events.

auto_update_components_languages = None

Switch for automatic creation of *.po language entries for new component texts.

elements = None

A dict mapping elem_id to element instance.” Elements instances represent a Power or Logic Unit (here a PQBus example) with customizable data for the following purposes:

  • link to component description by model.get_component(elem_id) or model.components[sim_model]

    (here in maverig/data/components/PyPower.PQBus.json)

  • reference data (elem_id)

  • custom visualization (icon),

  • positioning for each port (pos),

  • dockings to/from other elements and their ports (out, in)

  • data for simulation runtime and initialization:
    • parameters and their values (params)

    • attributes at simulation runtime with their static or listed dynamic values (attrs)

    • reference to mosaik entity (mosaik_full_id)

      mosaik_full_id and attrs will be automatically filled during simulation time

Example elements dictionary with PyPower PQBus instance:

    "PyPower.PQBus_4": {
        "sim_model": "PyPower.PQBus",
        "icon": "bus.svg",
        "elem_id": "PyPower.PQBus_4",
        "mosaik_full_id": "PyPower-0.0-PyPower.PQBus_4",
        "docking_ports": {
            "0": {
                "pos": [450.0,200.0]
                "out": [],
                "in": [["PyPower.Branch_3","1"], ["PyPower.Branch_5","0"], ["CSV.House_4","1"]],
        "params": {
            "bus_type": "PQ",
            "base_kv": 0.23,
            "fbus": null,
            "tbus": null
        "attrs": {
            "Vl": 230.0,
            "Q": [0.0, 0.0, 0.0],
            "Vm": [230.14789278916751, 230.23588331696217, 230.22035839218473],
            "P": [381.21, 174.35, 116.43999999999998],
            "Va": [-0.17130258343689386, -0.17013456872934510, -0.16981416413842957]
    "CSV.House_1": {...}
history_undo = None

The history list of scenarios that can be undone. history_undo[-1] is the nearest to the current scenario.

history_redo = None

The history list of scenarios that can be redone. history_redo[-1] is the nearest to the current scenario.

tmp_scenario_copy = None

A copy of the current scenario since the last history relevant change occured.

saved_scenario_copy = None

A copy of the last saved scenario. Use self.saved_scenario_copy == self.tmp_scenario_copy comparison to check whether scenario has changed since last save.

uid = None

A dict mapping sim_model to current id counter for creating elements.

clipboard_elements = None

A dict mapping elem_id to element instance containing all the elements which are currently in clipboard.


The maverig.models.modelGraph.ModelGraph as networkx-Graph representation of the scenario.


The maverig.models.modelSimulation.SimulationServer which manages the simulation.


A dict mapping sim_model to component description. Component descriptions are read from JSON-Files in maverig/data/components.


A dict mapping simulator name to simulator description. Simulator descriptions are read from JSON-Files in maverig/data/components/simulators.


The simulation start time as datetime.datetime.


The simulation end time as datetime.datetime.


The step size of the simulation in seconds. Standard is 1800 (= 30 minutes).


The current simulation time index, which is used to address the current timestamp and the current dynamic attribute value.

Setting it will result in the closest valid index if it exceeds the boundaries of collected simulation timestamps.


The last possible simulation time index of an completed simulation.


Simulation visualization speed interval. The interval in milliseconds, how much time to pass until showing the next simulation timestep.

Setting this property will result in the closest supported speed interval.

Supported intervals (slow → fast):

2000, 1750, 1500, 1250, 1000, 750, 500, 250, 50

Simulation visualization speed factor. Note that this property does not represent an exact speed factor.

Setting this property will result in the closest supported speed factor.

Supported factors (slow → fast):

0.5, 0.625, 0.75, 0.875, 1, 1.5, 2, 4, 8

The running simulation progress in percent (0..100).


The current time stamp as datetime.datetime of the current simulation time index.

Setting this property will result in the closest collected simulation time stamp.


The simulation duration in seconds calculated by sim_start and sim_end time difference.


The currently active installed language for internationalization (e.g. 'en_EN').


The current program mode as ProgramMode.


The current mode as Mode.

switch_modes(standard_mode, substitute_mode)

Switch current mode between standard_mode and substitute_mode as Mode. If current mode is none of these, it will be set to standard_mode.


The current component sim_model for element creation when mode is set to Mode.comp.


Raster visibility as bool.


Raster visibility for composition mode as bool.

Use this property to memorize raster_mode before simulation and set it back when switching back to composition mode.


bool property whether elements snap to raster positions on mouse_release().


bool property whether scenario items are currently beeing dragged by an layout algorithm.


bool property whether scenario items are currently beeing dragged by mouse selection.


A list of elem_ids of selected elements.


Return whether element is selectable according to current mode.


Reset all history entries and set an initial history entry as first scenario state.


Adds a new history point if there have been some changes and clears redo history list.


Undo latest change.


Redo latest undone change.


Return an int value representing the current number of model state changes. This function is used for detecting history specific differences to the last temporary stored scenario.

History specific changes consider elements, positions, dockings, parameters and scenario simulation settings. Selection changes are not detected.


Get or apply a JSON compatible scenario dict with the following keys:

  • changes_count(): number of history specific scenario changes.
  • uid: id counters for element creation.
  • sim_start: simulation start time as string (e.g. '2014-10-20T00:00:00').
  • sim_end: simulation end time as string (e.g. '2014-10-24T23:59:59').
  • sim_step_size: the current simulation step size in seconds (e.g. 1800 = 30 minutes).
  • elements: the elements dict of elem_id to element instance.
  • selection: the currently selected elements as dict from elem_id to element.

Return a new flat copied model including ...

  • scenario
  • components and simulators descriptions
  • no connected events.

Copy all elements of the elem_ids list to an internal clipboard.


Paste all elements from internal clipboard and return the newly inserted elem_ids. Only dockings inside of clipboard will be maintained.

create_element(sim_model, pos)

Create a new element with a specific sim_model on an specific position as QtCore.QPointF in scenario.


Delete the given element.


Return the component description dict of an elem_id by the elements sim_model.


Return the simulator description dict of an element.


Return the color of the element icon. The icon will be scanned for the most valuable color only once. The icon colors are memorized locally.


Return a filtered list of published parameter names which are contained in each element of elem_ids.

param_is_multivalue(elem_ids, param_name)

Return whether one specific parameter (param_name) of multiple elements (elem_ids) differ in their values.

get_param_value(elem_id, param_name)

Get the value of a parameter in element (elem_id), Return None if element has no parameter param_name.

set_param_value(elem_id, param_name, param_value)

Set value of parameter (param_name) in element (elem_id) if value is not None.


Return a filtered list of published attribute names which are contained in each element of elem_ids.

attr_is_multivalue(elem_ids, attr_name)

Return whether current attribute values differ in elements of elem_ids.

get_attr_values(elem_id, attr_name, from_time_index=0, to_time_index=None)

Get attribute values of attr_name in element (elem_id) in time interval [from_time_index, to_time_index] where to_time_index is sim_timestamp if set to None.

get_attr_value(elem_id, attr_name, time_index=None)

Get current attribute value of attr_name in element (elem_id) at current time index. Return None if attribute does not exist.


Return the voltage dependent heat value of an element with component type PQBus or Branch.


Return the current dependent heat value of an element only with component type Branch.


Return the power level of an element with component type House, PV, Transformer, CHP, WECS or EV.


Return the state of charge of an EV.


Return whether element (elem_id) is selected.

set_selected(elem_id, value)

Set whether element (elem_id) is selected.


Return an element docking port content.

Example docking_port(['CSV.House_1', '1']) returns the port ‘1’ content of the element docking ports:

    'pos': [220.0, 330.0],
    'in': [],
    'out': [['PyPower.PQBus_3', '0']]

Return a list of available element ports of an specific element (elem_id).


Get the position of an element port as QtCore.QPointF.

set_pos(ep, pos)

Set a position of an element port as QtCore.QPointF.


Return a list of outgoing dockings to other element ports from an element port ep.


Return a list of ingoing dockings from other element ports to an element port ep.

docking_attrs(from_elem_id, to_elem_id)

Return a set of valid attribute connection tuples from one element to another, e.g. {('P_out','P')}. This function is used for connecting elements in mosaik in maverig.models.modelSimulation.SimulationProcess.start_simulation().

Component attribute descriptions may contain 'out':[...] or 'in':[...] entries indicating allowed connections to or from other attribute names.

can_dock(from_ep, to_ep)

Check whether it is possible to dock from one port to another.

dock(from_ep, to_ep)

Dock one port to another port.

undock(from_ep, to_ep)

Undock two element ports. Only undock if elements exists, because undock might have been called by element deletion.


Creates output and error events and selects elements in elem_ids for visual feedback of scenario errors.


Validates the scenario.


Fires all events with pending demands.


Fires all events.


Deselect all selected elements.


Stop the simulation and switch the mode to selection and program_mode to composition.


class maverig.models.modelGraph.ModelGraph(model, data=None, **attr)

Bases: networkx.Graph

A networkx.Graph representation of the model element ports as nodes and element internal lines between them as edges.

This graph can be used for layout optimization algorithms.

Example connection scenario:

('House', '0') --- ('House', '1') -> ('PQBus_1', '0')

('PQBus_1', '0') <- ('Branch', '0') --- ('Branch', '1') -> ('PQBus_2', '0')

Where --- are lines and <-, -> are dockings.

This scenario would be represented in ModelGraph as follows:

('House', '0') --- ('PQBus_1', '0') --- ('PQBus_2', '0'))

Where --- are edges and the element ports are nodes.

Ports with outgoing dockings (endpoints in view) get represented by their docked Port as Node, because they share the same position.

set_pos(ep, pos)

Change the position of an ElemPort node to pos (PySide.QtCore.QPointF). This method gets called by model when a position is set there.


class maverig.models.modelSimulation.SimulationProcess(sim_proxy, model)

Bases: multiprocessing.context.Process

The Simulation Process instantiates all needed Mosaik models and simulators and runs them until simulation is finished.


Process entry point.


Strip name extensions after ‘-‘.


Start simulators and their elements in Mosaik and create and run Mosaik world.

The Simulation is beeing initiated in the following order:

  1. Prepare model and simulator specific parameters and configuration.
  2. Start the simulators with parameter values taken from element where possible.
  3. Start the element as Mosaik entity and optionally create needed parent entities
  4. Connect entities as defined by dockings and component attribute descriptions
  5. Create and connect maverig.utils.visSimulator.VisSimulator which constantly sends simulated data to SimulationServer on each simulation step.
  6. Run the Simulation and return when it is finished.
start_simulator(world, elem)

Starts a mosaik_simulator with parameters specified in prepared element simulator parameter dict (elem['simulator']['params']).


Create an element in Mosaik with needed params specified in simulator meta and collected from elem. Apply the mapping of mosaik element id (mosaik_full_id) to elem, so that the data pushed to SimulationServer by maverig.utils.visSimulator.VisSimulator can be mapped back to elem_id on SimulationServer.run_iteration() side later on.

class maverig.models.modelSimulation.SimulationServer(model)

Bases: maverig.utils.processServer.ProcessServer

Manage a simulation process and serve proxy-access to registered functions.


Reset attributes and start class:SimulationProcess as Maverig subprocess.


Stop the Simulation and terminate the simulation process if it is still active.


Proxy function. Write text and subprocess stdout to Maverig console output.


Proxy function for error handling passed to maverig.models.model.Model.handle_scenario_error().

map_elem_to_mosaik(elem_id, mosaik_full_id)

Proxy function mapping mosaik_full_id to elem_id for data assignment in run_iteration().

update_data(timestamp, progress, data)

Proxy function for pushing collected from maverig.utils.visSimulator.VisSimulator. Apply the data later in run_iteration() by starting a timer. This may be faster than applying the data on each processed update_data call.


Apply simulated data on model.