repast4py.schedule module

This module includes classes and functions for scheduling events in a Repast4py simulation. Users will typically only use the repast4py.schedule.SharedScheduleRunner.

class repast4py.schedule.OneTimeEvent(at, evt)

Bases: repast4py.schedule.ScheduledEvent

Scheduled event that executes only once.

Parameters
  • at (float) – the time of the event.

  • evt (Callable) – the callable to execute when this event is executed.

reschedule(queue, sequence_count)

Null-op as this OneTimeEvent only occurs once.

class repast4py.schedule.RepeatingEvent(at, interval, evt)

Bases: repast4py.schedule.ScheduledEvent

Scheduled event that repeats at some specified interval.

Parameters
  • at (float) – the time of the event.

  • interval (float) – the interval at which to repeat.

  • evt (Callable) – the callable to execute when this event is executed.

reschedule(queue, sequence_count)

Reschedules this event to occur after its interval has passed.

Parameters
  • queue (List) – the priority queue list to schedule this event on

  • sequence_count (int) – the original sequeuce count for this event. The sequence count is used to order events scheduled for the same tick.

class repast4py.schedule.Schedule

Bases: object

Encapsulates a dynamic schedule of events and a method for iterating through that schedule and exectuting those events.

Events are added to the schedule for execution at a particular tick. The first valid tick is 0. Events will be executed in tick order, earliest before latest. Events scheduled for the same tick will be executed in the order in which they were added. If during the execution of a tick, an event is scheduled before the executing tick (i.e., scheduled to occur in the past) then that event is ignored.

execute()

Executes this schedule by repeatedly popping the next scheduled events off the queue and executing them.

next_tick()

Gets the tick of the next scheduled event.

Returns

the tick at which the next scheduled event will occur or -1 if nothing is scheduled.

Return type

float

schedule_event(at, evt)

Schedules the specified event to execute at the specified tick.

Parameters
  • at (float) – the time of the event.

  • evt (Callable) – the Callable to execute when the event occurs.

schedule_repeating_event(at, interval, evt)

Schedules the specified event to execute at the specified tick, and repeat at the specified interval.

Parameters
  • at (float) – the time of the event.

  • interval (float) – the interval at which to repeat event execution.

  • evt (Callable) – the Callable to execute when the event occurs.

class repast4py.schedule.ScheduledEvent(at, evt)

Bases: object

A callable base class for all scheduled events. Calling instances of this class will execute the Callable evt.

Parameters
  • at (float) – the time of the event.

  • evt (Callable) – the callable to execute when this event is executed.

reschedule(queue, sequence_count)

Implemented by subclasses.

class repast4py.schedule.SharedScheduleRunner(comm)

Bases: object

Encapsulates a dynamic schedule of executable events shared and synchronized across processes.

Events are added to the scheduled for execution at a particular tick. The first valid tick is 0. Events will be executed in tick order, earliest before latest. Events scheduled for the same tick will be executed in the order in which they were added. If during the execution of a tick, an event is scheduled before the executing tick (i.e., scheduled to occur in the past) then that event is ignored. The scheduled is synchronized across process ranks by determining the global cross-process minimum next scheduled event time, and executing only the events schedule for that time. In this way, no schedule runs ahead of any other.

Parameters

comm (mpi4py.MPI.Intracomm) – the communicator over which this schedule is shared.

execute()

Executes this SharedSchedule by repeatedly popping the next scheduled events off the queue and executing them.

schedule_end_event(evt)

Schedules the specified event (a Callable) for execution when the schedule terminates and the simulation ends.

Parameters

evt (Callable) – the Callable to execute when simulation ends.

schedule_event(at, evt)

Schedules the specified event to execute at the specified tick.

Parameters
  • at (float) – the time of the event.

  • evt (Callable) – the Callable to execute when the event occurs.

schedule_repeating_event(at, interval, evt)

Schedules the specified event to execute at the specified tick, and repeat at the specified interval.

Parameters
  • at (float) – the time of the event.

  • interval (float) – the interval at which to repeat event execution.

  • evt (Callable) – the Callable to execute when the event occurs.

schedule_stop(at)

Schedules the execution of this schedule to stop at the specified tick.

Parameters

at (float) – the tick at which the schedule will stop.

stop()

Stops schedule execution. All events scheduled for the current tick will execute and then schedule execution will stop.

tick()

Gets the current tick.

Returns

the currently executing tick.

Return type

float

repast4py.schedule.init_schedule_runner(comm)

Initializes the default schedule runner, a dynamic schedule of executable events shared and synchronized across processes.

Events are added to the scheduled for execution at a particular tick. The first valid tick is 0. Events will be executed in tick order, earliest before latest. Events scheduled for the same tick will be executed in the order in which they were added. If during the execution of a tick, an event is scheduled before the executing tick (i.e., scheduled to occur in the past) then that event is ignored. The scheduled is synchronized across process ranks by determining the global cross-process minimum next scheduled event time, and executing only the events schedule for that time. In this way, no schedule runs ahead of any other.

Parameters

comm (mpi4py.MPI.Intracomm) – the communicator over which this scheduled is shared.

Returns

The default SharedScheduledRunner instance that can be used to schedule events.

Return type

SharedScheduleRunner

repast4py.schedule.runner()

Gets the default schedule runner, a dynamic schedule of executable events shared and synchronized across processes.

Returns

The default SharedScheduledRunner instance that can be used to schedule events.

Return type

SharedScheduleRunner