Skip to content

Commit

Permalink
Merge f561b6b into c7acbe9
Browse files Browse the repository at this point in the history
  • Loading branch information
kmantel committed Feb 14, 2023
2 parents c7acbe9 + f561b6b commit d537d1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/graph_scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
All, AllHaveRun, Always, Condition, ConditionSet, EveryNCalls, Never,
_parse_absolute_unit, _quantity_as_integer,
)
from graph_scheduler.time import Clock, TimeScale
from graph_scheduler.time import _get_pint_unit, Clock, TimeScale

__all__ = [
'Scheduler', 'SchedulerError', 'SchedulingMode',
Expand Down Expand Up @@ -419,7 +419,7 @@ def __init__(
termination_conds=None,
default_execution_id=None,
mode: SchedulingMode = SchedulingMode.STANDARD,
default_absolute_time_unit: typing.Union[str, pint.Quantity] = 1 * _unit_registry.ms,
default_absolute_time_unit: typing.Union[str, pint.Quantity] = _get_pint_unit(1, 'ms'),
**kwargs
):
"""
Expand Down
16 changes: 12 additions & 4 deletions src/graph_scheduler/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
"""


# use a cached call because each call to getattr on a pint unit_registry
# creates new instances of Unit, and this becomes a significant time
# cost compared even to deepcopying
@functools.lru_cache()
def _get_pint_unit(num, unit):
return num * getattr(_unit_registry, unit)


class TimeScaleError(Exception):

def __init__(self, error_value):
Expand Down Expand Up @@ -232,8 +240,8 @@ def __init__(
environment_state_update=0,
environment_sequence=0,
life=0,
absolute=0 * _unit_registry.ms,
absolute_interval=1 * _unit_registry.ms,
absolute=_get_pint_unit(0, 'ms'),
absolute_interval=_get_pint_unit(1, 'ms'),
absolute_time_unit_scale=TimeScale.CONSIDERATION_SET_EXECUTION,
absolute_enabled=False,
**alias_time_values,
Expand All @@ -252,8 +260,8 @@ def __init__(
**{
_time_scale_to_attr_str(ts): v for ts, v in time_scale_values.items()
},
absolute=0 * _unit_registry.ms,
absolute_interval=1 * _unit_registry.ms,
absolute=_get_pint_unit(0, 'ms'),
absolute_interval=_get_pint_unit(1, 'ms'),
absolute_time_unit_scale=TimeScale.CONSIDERATION_SET_EXECUTION,
absolute_enabled=False,
)
Expand Down

0 comments on commit d537d1a

Please sign in to comment.