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

# `mosaik.simmanager` — Management of external processes

The simulation manager is responsible for starting simulation processes and shutting them down.

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, conf, sim_id, sim_params)

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

  Return a `LocalProcess` instance.

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

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

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

  Return a `RemoteProcess` instance.

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

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

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

  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`(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)
  `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', 'attrs']}`).

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

  `get_progress`()

    Return the current simulation progress from `sim_progress`.

  `get_related_entities`(*entities)

    Get a list of entities for entities.

    An entity may either be the string `'sim_id/entity_id'` or just `'entity_id'`. If the latter is the case, use `self.sim_id` to identify the entiy.

    The return value is a dict mapping `'sim_id/entity_id'` to sorted lists of tuples `('sim_id/entity_id', entity_type)`.