mosaik.simmanager — Management of external processes — mosaik 2.0a2 documentation

# `mosaik.simmanager` — Management of external processes

The simulation manager is responsible for starting simulation processes and shutting them down. It also manages the communication between mosaik and the processes.

It is able to start pure Python simulators in-process (by importing and instantiating them), to start external simulation processes and to connect to already running simulators and manage access to them.

`mosaik.simmanager.` `start`(world, sim_name, sim_id, sim_params)

  Start the simulator sim_name based on the configuration im world.sim_config, give it the ID sim_id and pass the parameters of the dict sim_params to it.

  The sim config is a dictionary with one entry for every simulator. The entry itself tells mosaik how to start the simulator:

      {
          'ExampleSimA': {
              'python': 'example_sim.mosaik:ExampleSim',
          },
          'ExampleSimB': {
              'cmd': 'example_sim %(addr)s',
              'cwd': '.',
          },
          'ExampleSimC': {
              'connect': 'host:port',
          },
      }

  ExampleSimA is a pure Python simulator. Mosaik will import the module `example_sim.mosaik` and instantiate the class `ExampleSim` to start the simulator.

  ExampleSimB would be started by executing the command example_sim and passing the network address of mosaik das command line argument. You can optionally specify a current working directory. It defaults to `.`.

  ExampleSimC can not be started by mosaik, so mosaik tries to connect to it.

  The function returns a `mosaik_api.Simulator` instance.

  It raises a `SimulationError` if the simulator could not be started.

  Return a `SimProxy` instance.

`mosaik.simmanager.` `start_inproc`(world, sim_name, sim_config, sim_id, sim_params)

  Import and instantiate the Python simulator sim_name based on its config entry sim_config.

  Return a `LocalProcess` instance.

  Raise a `ScenarioError` if the simulator cannot be instantiated.

`mosaik.simmanager.` `start_proc`(world, sim_name, sim_config, sim_id, sim_params)

  Start a new process for simulator sim_name based on its config entry sim_config.

  Return a `RemoteProcess` instance.

  Raise a `ScenarioError` if the simulator cannot be instantiated.

`mosaik.simmanager.` `start_connect`(world, sim_name, sim_config, sim_id, sim_params)

  Connect to the already running simulator sim_name based on its config entry sim_config.

  Return a `RemoteProcess` instance.

  Raise a `ScenarioError` if the simulator cannot be instantiated.

class `mosaik.simmanager.` `SimProxy`(sid, meta)

  Simple proxy/facade for in-process simulators.

  `stop`()

    Stop the simulator behind the proxy.

    The default implementation does nothing.

class `mosaik.simmanager.` `LocalProcess`(world, sid, inst, env, meta)

  Proxy for internal simulators.

  `stop`()

    Yield a triggered event but do nothing else.

class `mosaik.simmanager.` `RemoteProcess`(world, sid, proc, rpc_con, meta)

  Proxy for external simulator processes.

  `stop`()

    Send a stop message to the process represented by this proxy and wait for it to terminate.

class `mosaik.simmanager.` `MosaikRemote`(world, sim_id)

  This class provides an RPC interface for remote processes to query mosaik and other processes (simulators) for data while they are executing a `step()` command.

  `get_progress`()

    Return the current simulation progress from `sim_progress`.

  `get_related_entities`(entities=None)

    Return information about the related entities of entities.

    If entitites omitted (or `None`), return the complete entity graph, e.g.:

        {
            'nodes': {
                'sid_0/eid_0': {'type': 'A'},
                'sid_0/eid_1': {'type': 'B'},
                'sid_1/eid_0': {'type': 'C'},
            },
            'edges': [
                ['sid_0/eid_0', 'sid_1/eid0', {}],
                ['sid_0/eid_1', 'sid_1/eid0', {}],
            ],
        }

    If entities is a single string (e.g., `sid_1/eid_0`), return a dict containing all entities related to that entity:

        {
            'sid_0/eid_0': {'type': 'A'},
            'sid_0/eid_1': {'type': 'B'},
        }

    If entities is a list of entity IDs (e.g., `['sid_0/eid_0', 'sid_0/eid_1']`), return a dict mapping each entity to a dict of related entities:

        {
            'sid_0/eid_0': {
                'sid_0/eid_1': {'type': 'B'},
            },
            'sid_0/eid_1': {
                'sid_0/eid_1': {'type': 'B'},
            },
        }

  `get_data`(attrs)

    Return the data for the requested attributes attrs.

    Attributes is a dict of (fully qualified) entity IDs mapping to lists of attribute names (`{'sid/eid': ['attr1', 'attr2']}`).

    The return value is a dict mapping the input entity IDs to data dictionaries mapping attribute names to there respective values.

  `set_data`(data)

    Set data as input data for all affected simulators.

    data is a dictionary mapping sim_id/entity_id paths to dictionaries of attributes and values (`{'sid/eid': {'attr1': 'val1', 'attr2': 'val2'}}`)