# Time¶

## Overview¶

Schedulers maintain Clock objects to track time. The current time in relation to a Scheduler is stored in Scheduler.clock.time or Scheduler.clock.simple_time

class psyneulink.core.scheduling.time.Clock

Stores a history of TimeScales that have occurred, and keep track of a current Time. Used in relation to a Scheduler

history

a root TimeHistoryTree associated with this Clock

Type

TimeHistoryTree

simple_time

the current time in simple format

Type

SimpleTime

_increment_time(time_scale)
get_total_times_relative(query_time_scale, base_time_scale, base_index=None)

Convenience simplified wrapper for TimeHistoryTree.get_total_times_relative

Parameters
• query_time_scale (TimeScale) – the unit of time whose number of ticks to be returned

• base_time_scale (TimeScale) – the unit of time over which the number of query_time_scale ticks should be returned

• base_index (int) – the base_indexth base_time_scale over which the number of query_time_scale ticks should be returned

Returns

the number of query_time_scale s that have occurred during the scope of the base_index th base_time_scale

Return type

int

get_time_by_time_scale(time_scale)
Parameters

time_scale (TimeScale) –

Returns

the current value of the time unit corresponding to time_scale for this Clock

Return type

int

property time

Time

Type

the current time

property previous_time

Time

Type

the time that has occurred last

class psyneulink.core.scheduling.time.TimeScale(value)

Represents divisions of time used by the Scheduler, Conditions, and the time_scale argument of a Composition’s run method.

The values of TimeScale are defined as follows (in order of increasingly coarse granularity):

TIME_STEP

the nuclear unit of time, corresponding to the execution of all Mechanisms allowed to execute from a single consideration_set of a Scheduler, and which are considered to have executed simultaneously.

PASS

a full iteration through all of the consideration_sets in a Scheduler's consideration_queue, consisting of one or more TIME_STEPs, over which every Component specified to a Scheduler is considered for execution at least once.

TRIAL

an open-ended unit of time consisting of all actions that occurs within the scope of a single input to a Composition.

RUN

the scope of a call to the run method of a Composition, consisting of one or more TRIALs.

LIFE

the scope of time since the creation of an object.

classmethod get_parent(time_scale)
Returns

the TimeScale one level wider in scope than time_scale

Return type

TimeScale

classmethod get_child(time_scale)
Returns

the TimeScale one level smaller in scope than time_scale

Return type

TimeScale

class psyneulink.core.scheduling.time.Time(time_step=0, pass_=0, trial=0, run=0, life=0, absolute=<Quantity(0, 'millisecond')>, absolute_interval=<Quantity(1, 'millisecond')>, absolute_time_unit_scale=<TimeScale.TIME_STEP: 0>, absolute_enabled=False)

Represents an instance of time, having values for each TimeScale

life

the TimeScale.LIFE value

Type

int : 0

run

the TimeScale.RUN value

Type

int : 0

trial

the TimeScale.TRIAL value

Type

int : 0

pass_

the TimeScale.PASS value

Type

int : 0

time_step

the TimeScale.TIME_STEP value

Type

int : 0

absolute

the absolute time value

Type

pint.Quantity : 0ms

absolute_interval

the interval between units of absolute time

Type

pint.Quantity : 1ms

absolute_time_unit_scale

the TimeScale that corresponds to an interval of absolute time

Type

TimeScale : TimeScale.TIME_STEP

absolute_enabled

whether absolute time is used for this Time object

Type

bool : False

_get_by_time_scale(time_scale)
Parameters

time_scale (TimeScale) –

Returns

this Time’s value of a TimeScale by the TimeScale enum, rather than by attribute

Return type

int

_set_by_time_scale(time_scale, value)
Parameters

time_scale (TimeScale) –

Sets this Time’s value of a time_scale by the TimeScale enum, rather than by attribute

_increment_by_time_scale(time_scale)

Increments the value of time_scale in this Time by one

_reset_by_time_scale(time_scale)

Resets all the times for the time scale scope up to time_scale e.g. _reset_by_time_scale(TimeScale.TRIAL) will set the values for TimeScale.PASS and TimeScale.TIME_STEP to 0

class psyneulink.core.scheduling.time.SimpleTime(time_ref)

A subset class of Time, used to provide simple access to only run, trial, and time_step

class psyneulink.core.scheduling.time.TimeHistoryTree(time_scale=<TimeScale.LIFE: 4>, max_depth=<TimeScale.TRIAL: 2>, index=0, parent=None, enable_current_time=True)

A tree object that stores a history of time that has occurred at various TimeScales, typically used in conjunction with a Clock

time_scale

the TimeScale unit this tree/node represents

Type
child_time_scale

the TimeScale unit for this tree’s children

Type
children

an ordered list of this tree’s children

Type
max_depth

the finest grain TimeScale that should be created as a subtree Setting this value lower allows for more precise measurements (by default, you cannot query the number of TimeScale.TIME_STEPs in a certain TimeScale.PASS), but this may use a large amount of memory in large simulations

Type
index

the index this tree has in its parent’s children list

Type

int

parent

the parent node of this tree, if it exists. None represents no parent (i.e. root node)

Type
previous_time

a Time object that represents the last time that has occurred in the tree

Type

Time

current_time

a Time object that represents the current time in the tree

Type

Time

total_times

stores the total number of units of TimeScales that have occurred over this tree’s scope. Only contains entries for TimeScales of finer grain than time_scale

Type

dict{TimeScale: int}

Parameters

enable_current_time (bool : True) – sets this tree to maintain a Time object. If this tree is not a root (i.e. time_scale is TimeScale.LIFE)

increment_time(time_scale)

Increases this tree’s current_time by one time_scale

Parameters

time_scale (TimeScale) – the unit of time to increment

get_total_times_relative(query_time_scale, base_indices=None)
Parameters
Returns

the number of units of query_time_scale that have occurred within the scope of time specified by base_indices

Return type

int

exception psyneulink.core.scheduling.time.TimeScaleError(error_value)