palaestrai_mosaik package — palaestrAI Mosaik Interface documentation

# palaestrai_mosaik package

## Subpackages

- palaestrai_mosaik.environment package
  - Submodules
  - palaestrai_mosaik.environment.loader module
  - palaestrai_mosaik.environment.mosaik_ifs module
  - palaestrai_mosaik.environment.mosaik_world module
  - Module contents
- palaestrai_mosaik.mosaikpatch package
  - Submodules
  - palaestrai_mosaik.mosaikpatch.scenario module
  - palaestrai_mosaik.mosaikpatch.scheduler module
  - Module contents
- palaestrai_mosaik.simulator package
  - Submodules
  - palaestrai_mosaik.simulator.arlsync_sim module
  - palaestrai_mosaik.simulator.exceptions module
  - Module contents

## Submodules

## palaestrai_mosaik.config module

## palaestrai_mosaik.mosaik_environment module

This module contains the `MosaikEnvironment`, which allows to run mosaik co-simulations with palaestrAI.

class `palaestrai_mosaik.mosaik_environment.` `MosaikEnvironment`(connection, uid, seed: int, params=None)

  Bases: `palaestrai.environment.environment.Environment`

  The mosaik environment for palaestrAI.

  This class implements the abstract class `palaestrai.environment.Environment` and allows the interaction between ARL agents and a mosaik co-simulation.

  Parameters

    - connection (str) – The connection to the broker, required by the Environment class.

    - uid (str) – The uid of this environment, required by the Environment class.

    - seed (int) – A random seed provided by the experiment.

    - params (dict) –

      A dict containing information about the mosaik world that should be created. This should look, e.g, like:

          params = {
              # Full import path to a module or class
              "module": "midas.adapter.arl:Descriptor",
              # A function of *module* that returns descriptions
              # of sensors and actuators
              "description_func": "describe",
              # A function of *module* that returns a mosaik world
              # object
              "instance_func": "get_world",
              # Step size for the ARL synchronization
              "step_size": 900,
              # Additional params passed to *description_func* and
              # *instance_func*
              "params": {},
          }

  `mworld`

    Creates and holds the mosaik world object.

    Type

      `MosaikWorld`

  property `mifs`

    Return the mosaik interface component.

    Holds the sensors and actuators and handles the exchange of data between the communication worker and the mosaik simpy process.

    Returns

    Return type

      `MosaikInterfaceComponent`

  `shutdown`(reset=False)

    Try to shutdown the environment.

    Returns

      True if the environment was shut down, False otherwise.

    Return type

      bool

  `start`()

    Start the simulation process.

    As soon as the mosaik simulation is finished (or interrupted), events are set to notify the worker that the simulation is finished.

  `start_environment`()

    Function to start the environment

    If the environment uses a simulation tool, this function can be used to initiate the simulation tool. Otherwise this function is used to prepare the environment for the simulation. It must be able to provide initial sensor information.

    On a reset, this method is called to restart a new environment run. Therefore, it also must provide initial values for all variables used!

    Returns

      A tuple containing a list of available sensors and a list of available actuators.

    Return type

      tuple(List[SensorInformation], List[ActuatorInformation])

  `sync`(time)

    Allow synchronization with the message worker.

    This method is called each time the `ARLSyncSimulator` steps. Updates the values in the sensor objects directly from the mosaik data graph.

    The actuator values will not be set here, since each simulator fetches its input data directly and independently from mosaik.

    This method implements the mosaik part of the synchronization between worker and mosaik process.

    Parameters

      time (int) – The current simulation time (current step) is required to retrieve the correct data from the mosaik world.

  `update`(actuators)

    Update the environment with new actuator values.

    On each call, actuators contains new values, which will be injected into the mosaik data graph so that simulators can fetch these values without even noticing.

    This method implements the communication part of the synchronization between worker process and the mosaik process.

    Parameters

      actuators (list[ActuatorInformation]) – A list of actuators with new values provided by the agents.

    Returns

      A tuple containing a list, a float, and a bool The list contains sensors with updated values, the float represents a reward defining the current state of the environment, and the bool is False if the environment is still running and True otherwise.

    Return type

      tuple

## Module contents