mosaik.scenario — Classes related to the scenario creation — mosaik 2.0a1 documentation

# `mosaik.scenario` — Classes related to the scenario creation

This module provides the interface for users to create simulation scenarios for mosaik.

The `World` holds all necessary data for the simulation and allows the user to start simulators. It provides a `ModelFactory` (and a `ModelMock`) via which the user can instantiate model instances (entities). The method `World.run()` finally starts the simulation.

class `mosaik.scenario.` `Entity`(sid, eid, type, rel, sim)

  An entity represents an instance of a simulation model within mosaik.

  `eid`

    The entity’s ID.

  `rel`

    A list of related entities (their IDs)

  `sid`

    The ID of the simulator this entity belongs to.

  `sim`

    The `SimProxy` containing the entity.

  `type`

    The entity’s type (or class).

class `mosaik.scenario.` `World`(sim_config, execution_graph=False)

  The world holds all data required to specify and run the scenario.

  It provides a method to start a simulator process (`start()`) and manages the simulator instances.

  You have to provide a sim_config which tells the world which simulators are available and how to start them. See `mosaik.simmanager.start()` for more details.

  If execution_graph is set to `True`, an execution graph will be created during the simulation. This may be useful for debugging and testing. Note, that this increases the memory consumption and simulation time.

  `config` = None

    The config dictionary for general mosaik settings.

  `connect`(src, dest, *attr_pairs)

    Connect the src entity to dest entity.

    Establish a dataflow for each `(src_attr, dest_attr)` tuple in attr_pairs.

    Raise a `ScenarioError` if both entities share the same simulator instance, if at least one (src. or dest.) attribute in attr_pairs does not exist, or if the connection would introduce a cycle in the dataflow (e.g., A → B → C → A).

  `df_graph` = None

    The directed dataflow graph for this scenario.

  `entity_graph` = None

    The graph of related entities. Nodes are `(sid, eid)` tuples. Each note has an attribute entity with an `Entity`.

  `env` = None

    The SimPy.io networking `Environment`.

  `run`(until)

    Start the simulation until the simulation time until is reached.

    Return the current simulation time (>= until).

    This method should only be called once!

  `shutdown`()

    Shut-down all simulators and close the server socket.

  `sim_config` = None

    The config dictionary that tells mosaik how to start a simulator.

  `sim_progress` = None

    Progress of the current simulation.

  `sims` = None

    A dictionary of already started simulators instances.

  `srv_sock` = None

    Mosaik’s server socket.

  `start`(sim_name, **sim_params)

    Start the simulator named sim_name and return a `ModelFactory` for it.

class `mosaik.scenario.` `ModelFactory`(world, sim)

  This is a facade for a simulator sim that allows the user to create new model instances (entities) within that simulator.

  For every model that a simulator publicly exposes, the `ModelFactory` provides a `ModelMock` attribute that actually creates the entities.

  If you access an attribute that is not a model or if the model is not marked as public, an `ScenarioError` is raised.

class `mosaik.scenario.` `ModelMock`(world, name, sim)

  Instances of this class are exposed as attributes of `ModelFactory` and allow the instantiation of simulator models.

  You can call an instance of this class to create exactly one entiy: `sim.ModelName(x=23)`. Alternatively, you can use the `create()` method to create multiple entities with the same set of parameters at once: `sim.ModelName.create(3, x=23)`.

  `create`(num, **model_params)

    Create num entities with the specified model_params and return a list with the entity dicts.

    The returned list of entities is the same as returned by `mosaik_api.Simulator.create()`, but the simulator is prepended to every entity ID to make them globally unique.