simtools module

class simtools.Notifier(name: str = '', owner: Optional[Any] = None)

Bases: object

A class that helps implementing the observer pattern. A Notifier can be triggered providing a value. Both callback functions and SimPy generators can be subscribed. Every time the Notifier is triggered, it will run its callback methods and trigger the execution of the subscribed SimPy generators. Aditionally, SimPy generators can wait for a Notifier to be triggered by yielding its event.

property event

Event: A SimPy event that succeeds when the Notifier is triggered

property name

str: The Notifier’s name as it has been passed to the constructor

subscribeCallback(callback: Callable[Any, None], priority: int = 0, additionalArgs: Optional[List[Any]] = None)

Adds the passed callable to the set of callback functions. Thus, when the Notifier gets triggered, the callable will be invoked passing the value that the Notifier was triggered with. Note:

A callable can only be added once, regardless of its priority.

Args:

callback: The callable to be subscribed priority: If set, the callable is guaranteed to be invoked only

after every callback with a higher priority value has been executed. Callbacks added without a priority value are assumed to have priority 0.

additionalArgs: A list of arguments that are passed as further

arguments when the callback function is invoked

subscribeProcess(process: Generator[simpy.events.Event, Any, None], blocking=True, queued=False)

Makes the SimPy environment process the passed generator function when trigger() is called. The value passed to trigger() will also be passed to the generator function. Args:

blocking: If set to False, only one instance of the generator

will be processed at a time. Thus, if trigger() is called while the SimPy process started by an earlier trigger() call has not terminated, no action is taken.

queued: Only relevant if blocking is True. If queued is set to

false False, a trigger() call while an instance of the generator is still active will not result in an additional generator execution. If queued is set to True instead, the values of trigger() calls that happen while the subscribed generator is being processed will be queued and as long as the queue is not empty, a new generator instance with a queued value will be processed every time a previous instance has terminated.

trigger(value: Optional[Any] = None)

Triggers the Notifier. This runs the callbacks, makes the event succeed, and triggers the processing of subscribed SimPy generators.

unsubscribeCallback(callback: Callable[Any, None])

Removes the passed callable from the set of callback functions. Afterwards, it is not triggered anymore by this Notifier. Args:

callback: The callable to be removed

class simtools.SimulationManager

Bases: object

The SimulationManager offers methods and properties for managing and accessing a SimPy simulation. Note:

Do not create instances on your own. Reference the existing instance by SimMan instead.

property env

The SimPy Environment object belonging to the current simulation

event()

Creates and returns a new Event object belonging to the current environment.

init()

Creates a new Environment.

nextTimeSlot(timeSlotLength: float) simpy.events.Event

Returns a SimPy timeout event that is scheduled for the beginning of the next time slot. A time slot starts whenever now % timeSlotLength is 0. Args:

timeSlotLength: The time slot length in seconds

property now

int: The current simulation time step

process(generator: Generator[simpy.events.Event, None, None]) simpy.events.Process

Registers a SimPy process generator (a generator yielding SimPy events) at the SimPy environment and returns it. Args:

process: The generator to be registered as a process

runSimulation(until: Union[int, float, simpy.events.Event])

Runs the simulation (or continues running it) until the amount of simulated time specified by until has passed (with until being a float) or until is triggered (with until being an Event).

timeout(duration: float, value: Optional[Any] = None) simpy.events.Event

Shorthand for env.timeout(duration, value)

timeoutUntil(triggerTime: float, value: Optional[Any] = None) simpy.events.Event

Returns a SimPy EventEvent that succeeds at the simulated time specified by triggerTime. Args:

triggerTime: When to trigger the Event value: The value to call succeed() with

triggerAfterTimeout(event: simpy.events.Event, timeout: float, value: Optional[Any] = None)

Calls succeed() on the event after the simulated time specified in timeout has passed. If the event has already been triggered by then, no action is taken.

updateRoute()
simtools.ownerPrefix(ownerObject: Any) str

Calls __repr__() on the ownerObject (if it is not None) and returns the result concatenated with ‘.’. If the object is None, an empty string will be returned.

simtools.strAndRepr(obj: Any) str

Returns “str (repr)” where str and repr are the result of str(obj) and repr(obj).