mosaik.proxies – Proxies for mosaik simulators

This module contains the Proxy class and its subclasses. They are used to represent a running simulator in the scenario. LocalProxy represents a simulator running in the current Python process; RemoteProxy represents a simulator connected to mosaik via a TCP connection.

class Proxy[source]

A proxy for a mosaik simulator from the view of a mosaik scenario.

Generally, this will be a BaseProxy subclass wrapped in the appropriate Adapter subclasses to bring the interface of the connected simulator in line with the most up-to-date API version.

abstractmethod async send(request)[source]

Send a request to the connected simulator.

Parameters:

request (Any) – Generally, this will be a three-tuple consisting of a function name, a list of positional arguments and a dict of named arguments.

Returns:

The return value from the remote simulator (depends on the specified function).

Return type:

Any

abstract property meta: Meta[source]

The meta of the connected simulator, as adapted by the adapters.

abstractmethod async stop()[source]

Stop the connected simulator. This is not handled via send as there are extra steps to be taken to close the connection cleanly.

Return type:

None

class BaseProxy[source]

A base Proxy for a connected simulator that simply sends all requests along unchanged. This will usually be wrapped in one or more instances of Adapter to allow treating the simulator as up-to-date from other parts of mosaik.

abstractmethod async init(sid, *, time_resolution, **sim_params)[source]

Initialize the simulator by sending the init call. The meta returned by the simulator will be saved to be retrieved using the meta property.

Parameters:
  • sid (str) – The SimId that mosaik assigns to this simulator instance

  • time_resolution (float) – The time resolution of the simulation, i.e. how many seconds correspond to one mosaik time step.

  • sim_params (Any) – The params sent to the simulator for initialization.

Return type:

list[int]

class LocalProxy(sim, mosaik_remote)[source]

Proxy for a local simulator. This mainly wraps each mosaik method in a coroutine.

Parameters:
sim: Simulator[source]

The underlying mosaik_api_v3.Simulator.

async init(sid, **kwargs)[source]

Initialize the simulator by sending the init call. The meta returned by the simulator will be saved to be retrieved using the meta property.

Parameters:
  • sid (str) – The SimId that mosaik assigns to this simulator instance

  • time_resolution – The time resolution of the simulation, i.e. how many seconds correspond to one mosaik time step.

  • sim_params – The params sent to the simulator for initialization.

  • kwargs (Any)

Return type:

list[int]

property meta[source]

The meta of the connected simulator, as adapted by the adapters.

async send(request)[source]

Send a request to the connected simulator.

Parameters:

request (tuple[str, tuple[Any, ...], dict[str, Any]]) – Generally, this will be a three-tuple consisting of a function name, a list of positional arguments and a dict of named arguments.

Returns:

The return value from the remote simulator (depends on the specified function).

async stop()[source]

Stop the connected simulator. This is not handled via send as there are extra steps to be taken to close the connection cleanly.

class RemoteProxy(channel, mosaik_remote, *, process=None)[source]
Parameters:
async init(sid, **kwargs)[source]

Initialize the simulator by sending the init call. The meta returned by the simulator will be saved to be retrieved using the meta property.

Parameters:
  • sid (str) – The SimId that mosaik assigns to this simulator instance

  • time_resolution – The time resolution of the simulation, i.e. how many seconds correspond to one mosaik time step.

  • sim_params – The params sent to the simulator for initialization.

  • kwargs (Any)

Return type:

list[int]

property meta: Meta[source]

The meta of the connected simulator, as adapted by the adapters.

async send(request)[source]

Send a request to the connected simulator.

Parameters:

request (Any) – Generally, this will be a three-tuple consisting of a function name, a list of positional arguments and a dict of named arguments.

Returns:

The return value from the remote simulator (depends on the specified function).

Return type:

Any

async stop()[source]

Stop the connected simulator. This is not handled via send as there are extra steps to be taken to close the connection cleanly.

Return type:

None