Time

Overview

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

class graph_scheduler.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

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 : 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 : int

property time

Time

Type:

the current time

property previous_time

Time

Type:

the time that has occurred last

class graph_scheduler.time.TimeScale(value)

Represents divisions of time used by the Scheduler and Conditions.

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

CONSIDERATION_SET_EXECUTION

the nuclear unit of time, corresponding to the execution of all nodes 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 CONSIDERATION_SET_EXECUTIONs, over which every node specified to a Scheduler is considered for execution at least once.

ENVIRONMENT_STATE_UPDATE

an open-ended unit of time consisting of all actions that occurs within the scope of a single call to run

ENVIRONMENT_SEQUENCE

the scope of a batch of one or more ENVIRONMENT_STATE_UPDATEs, managed by the environment using the Scheduler.

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 : TimeScale

classmethod get_child(time_scale)
Returns:

the TimeScale one level smaller in scope than time_scale : TimeScale

class graph_scheduler.time.Time(consideration_set_execution=0, pass_=0, environment_state_update=0, environment_sequence=0, life=0, absolute=<Quantity(0, 'millisecond')>, absolute_interval=<Quantity(1, 'millisecond')>, absolute_time_unit_scale=TimeScale.CONSIDERATION_SET_EXECUTION, absolute_enabled=False, **alias_time_values)

Represents an instance of time, having values for each TimeScale

life

the TimeScale.LIFE value

Type:

int : 0

environment_sequence

the TimeScale.ENVIRONMENT_SEQUENCE value

Type:

int : 0

environment_state_update

the TimeScale.ENVIRONMENT_STATE_UPDATE value

Type:

int : 0

pass_

the TimeScale.PASS value

Type:

int : 0

consideration_set_execution

the TimeScale.CONSIDERATION_SET_EXECUTION 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.CONSIDERATION_SET_EXECUTION

absolute_enabled

whether absolute time is used for this Time object

Type:

bool : False

class graph_scheduler.time.SimpleTime(time_ref)

A subset class of Time, used to provide simple access to only environment_sequence, environment_state_update, and consideration_set_execution

class graph_scheduler.time.TimeHistoryTree(time_scale=TimeScale.LIFE, max_depth=TimeScale.ENVIRONMENT_STATE_UPDATE, 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:

TimeScale : TimeScale.LIFE

child_time_scale

the TimeScale unit for this tree’s children

Type:

TimeScale : TimeScale.ENVIRONMENT_SEQUENCE

children

an ordered list of this tree’s children

Type:

list[TimeHistoryTree]

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.CONSIDERATION_SET_EXECUTIONs in a certain TimeScale.PASS), but this may use a large amount of memory in large simulations

Type:

TimeScale : TimeScale.ENVIRONMENT_STATE_UPDATE

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:

TimeHistoryTree : None

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:
  • query_time_scale (TimeScale) – the TimeScale of units to be returned

  • base_indices (dict{TimeScale: int}) –

    a dictionary specifying what scope of time query_time_scale is over. e.g.

    base_indices = {TimeScale.ENVIRONMENT_SEQUENCE: 1, TimeScale.ENVIRONMENT_STATE_UPDATE: 5}

    gives the number of query_time_scales that have occurred in the 5th ENVIRONMENT_STATE_UPDATE of the 1st ENVIRONMENT_SEQUENCE. If an entry for a TimeScale is not specified but is coarser than query_time_scale, the latest value for that entry will be used

Returns:

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

graph_scheduler.time.set_time_scale_alias(name, target)

Sets an alias named name of TimeScale target

Parameters:
  • name (str) – name of the alias

  • target (TimeScale) – TimeScale that name will refer to

graph_scheduler.time.remove_time_scale_alias(name)

Removes an alias previously set by set_time_scale_alias

Parameters:

name (str) – name of the TimeScale alias to remove