mosaik.scheduler
— Coordinate and execute simulators
This module is responsible for performing the simulation of a scenario.
- async mosaik.scheduler.run(world, until, rt_factor=None, rt_strict=False, lazy_stepping=True)[source]
Run the simulation for a
AsyncWorld
until the simulation time until has been reached.Return the final simulation time.
See
mosaik.scenario.AsyncWorld.run
for a detailed description of the rt_factor and rt_strict arguments.
- async mosaik.scheduler.sim_process(world, sim, until, rt_factor, rt_strict, lazy_stepping)[source]
Coroutine running the simulator sim.
- async mosaik.scheduler.rt_sleep(sim, world)[source]
If in real-time mode, check if to sleep and do so if necessary.
- Parameters:
sim (SimRunner)
world (AsyncWorld)
- Return type:
None
- async mosaik.scheduler.wait_for_dependencies(sim, lazy_stepping)[source]
Wait until all simulators that can provide input for this simulator have run for this step.
Also notify any simulator that is already waiting to perform its next step.
world is a mosaik
AsyncWorld
.
- mosaik.scheduler.get_input_data(world, sim)[source]
Return a dictionary with the input data for sim.
The dict will look like:
{ 'eid': { 'attrname': {'src_eid_0': val_0, ... 'src_eid_n': val_n}, ... }, ... }
For every entity, there is an entry in the dict and each entry is itself a dict with attributes and a list of values. This is, because we may have inputs from multiple simulators (e.g., different consumers that provide loads for a node in a power grid) and cannot know how to aggregate that data (sum, max, …?).
world is a mosaik
AsyncWorld
.- Parameters:
world (AsyncWorld)
sim (SimRunner)
- Return type:
InputData
- mosaik.scheduler.get_max_advance(world, sim, until)[source]
Checks how far sim can safely advance its internal time during next step without causing a causality error.
- async mosaik.scheduler.step(world, sim, inputs, max_advance)[source]
Advance (step) a simulator sim with the given inputs. Return an event that is triggered when the step was performed.
inputs is a dictionary, that maps entity IDs to data dictionaries which map attribute names to lists of values (see
get_input_data
).max_advance is the simulation time until the simulator can safely advance it’s internal time without causing any causality errors.
- mosaik.scheduler.rt_check(rt_factor, rt_start, rt_strict, sim)[source]
Check if simulation is fast enough for a given real-time factor.
- async mosaik.scheduler.get_outputs(world, sim)[source]
Wait for all required output data from a simulator sim.
world is a mosaik
AsyncWorld
.- Parameters:
world (AsyncWorld)
sim (SimRunner)
- mosaik.scheduler.validate_output_time(sim, output_time)[source]
Validate the output time against the simulation’s current state.
This function ensures that the output time is greater than or equal to the simulation’s last recorded time step. If the output time is earlier, it raises an error, as this would indicate an invalid state for processing output data.
- Parameters:
- Raises:
SimulationError – If the output time is less than the simulation’s last time step.
- mosaik.scheduler.determine_output_tiered_time(sim, output_time)[source]
Determine the tiered time structure for the given output time.
If the output time matches the current simulation step’s time, the current tiered time is returned. Otherwise, a new TieredTime object is created with the specified output time as the first tier and all subsequent tiers set to zero.
- mosaik.scheduler.push_output_data(sim, data, output_time)[source]
Push output data to connected simulators, applying time shifts as needed.
This function retrieves the output data for each entity and attribute specified in the simulation’s output mappings. The data is then forwarded to the connected simulators, with time shifts applied to ensure alignment with their input timelines. If a required key is missing in the data, it is skipped without raising an error.
- Parameters:
- mosaik.scheduler.trigger_successors(sim)[source]
Notify all simulators waiting for us.
- Parameters:
sim (SimRunner)
- Return type:
None
- mosaik.scheduler.prune_dataflow_cache(world)[source]
Prunes the dataflow cache.
- Parameters:
world (AsyncWorld)