The Simulation Clock

The components here provide implementations of different kinds of simulation clocks for use in vivarium.

For more information about time in the simulation, see the associated concept note.

class vivarium.framework.time.SimulationClock[source]

A base clock that includes global clock and a pandas series of clocks for each simulant

property name: str
property columns_created: list[str]

Provides names of columns created by the manager.

property columns_required: list[str]
property time: Timestamp | datetime | int

The current simulation time.

property stop_time: Timestamp | datetime | int

The time at which the simulation will stop.

property minimum_step_size: Timedelta | timedelta | int

The minimum step size.

property standard_step_size: Timedelta | timedelta | int

The standard varied step size.

property step_size: Timedelta | timedelta | int

The size of the next time step.

property event_time: Timestamp | datetime | int

Convenience method for event time, or clock + step

property time_steps_remaining: int
setup(builder)[source]

Defines custom actions this manager needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the manager. By default, it does nothing.

Return type:

None

Parameters:

builder (Builder) – The builder object used to set up the manager.

on_post_setup(event)[source]
Return type:

None

Parameters:

event (Event)

on_initialize_simulants(pop_data)[source]

Sets the next_event_time and step_size columns for each simulant

Return type:

None

Parameters:

pop_data (SimulantData)

simulant_next_event_times(index)[source]

The next time each simulant will be updated.

Parameters:

index (pd.Index[int])

Return type:

pd.Series[ClockTime]

simulant_step_sizes(index)[source]

The step size for each simulant.

Parameters:

index (pd.Index[int])

Return type:

pd.Series[ClockStepSize]

step_backward()[source]

Rewinds the clock by the current step size.

Return type:

None

step_forward(index)[source]

Advances the clock by the current step size, and updates aligned simulant clocks.

Parameters:

index (pd.Index[int])

Return type:

None

get_active_simulants(index, time)[source]

Gets population that is aligned with global clock

Parameters:
  • index (pd.Index[int])

  • time (ClockTime)

Return type:

pd.Index[int]

move_simulants_to_end(index)[source]
Parameters:

index (pd.Index[int])

Return type:

None

step_size_post_processor(value, manager)[source]

Computes the largest feasible step size for each simulant.

This is the smallest component-modified step size (rounded down to increments of the minimum step size), or the global step size, whichever is larger. If no components modify the step size, we default to the global step size.

Return type:

Any

Parameters:
Returns:

The largest feasible step size for each simulant

class vivarium.framework.time.SimpleClock[source]

A unitless step-count based simulation clock.

CONFIGURATION_DEFAULTS: dict[str, Any] = {'time': {'end': 100, 'standard_step_size': None, 'start': 0, 'step_size': 1}}

A dictionary containing the defaults for any configurations managed by this manager. An empty dictionary indicates no managed configurations.

property name: str
setup(builder)[source]

Defines custom actions this manager needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the manager. By default, it does nothing.

Return type:

None

Parameters:

builder (Builder) – The builder object used to set up the manager.

vivarium.framework.time.get_time_stamp(time)[source]
Return type:

Timestamp

Parameters:

time (dict[str, int])

class vivarium.framework.time.DateTimeClock[source]

A date-time based simulation clock.

CONFIGURATION_DEFAULTS: dict[str, Any] = {'time': {'end': {'day': 2, 'month': 7, 'year': 2010}, 'standard_step_size': None, 'start': {'day': 2, 'month': 7, 'year': 2005}, 'step_size': 1}}

A dictionary containing the defaults for any configurations managed by this manager. An empty dictionary indicates no managed configurations.

property name: str
setup(builder)[source]

Defines custom actions this manager needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the manager. By default, it does nothing.

Return type:

None

Parameters:

builder (Builder) – The builder object used to set up the manager.

class vivarium.framework.time.TimeInterface(manager)[source]
Parameters:

manager (SimulationClock)

clock()[source]

Gets a callable that returns the current simulation time.

Return type:

Callable[[], Timestamp | datetime | int]

step_size()[source]

Gets a callable that returns the current simulation step size.

Return type:

Callable[[], Timedelta | timedelta | int]

simulant_next_event_times()[source]

Gets a callable that returns the next event times for simulants.

Return type:

Callable[[pd.Index[int]], pd.Series[ClockTime]]

simulant_step_sizes()[source]

Gets a callable that returns the simulant step sizes.

Return type:

Callable[[pd.Index[int]], pd.Series[ClockStepSize]]

move_simulants_to_end()[source]

Gets a callable that moves simulants to the end of the simulation

Return type:

Callable[[pd.Index[int]], None]

register_step_size_modifier(modifier, requires_columns=[], requires_values=[], requires_streams=[])[source]

Registers a step size modifier.

Parameters:
  • modifier (Callable[[pd.Index[int]], pd.Series[ClockStepSize]]) – Modifier of the step size pipeline. Modifiers can take an index and should return a series of step sizes.

  • requires_columns (list[str]) – A list of the state table columns that already need to be present and populated in the state table before the modifier is called.

  • requires_values (list[str]) – A list of the value pipelines that need to be properly sourced before the modifier is called.

  • requires_streams (list[str]) – A list of the randomness streams that need to be properly sourced before the modifier is called.

Return type:

None