ding.utils.autolog.time_ctl¶
ding.utils.autolog.time_ctl
¶
BaseTime
¶
Overview
Abstract time interface
Interfaces:
time
time()
abstractmethod
¶
Overview
Get time information
Returns:
| Type | Description |
|---|---|
Union[int, float]
|
|
NaturalTime
¶
Bases: BaseTime
Overview
Natural time object
Interfaces:
__init__, time
Example:
>>> from ding.utils.autolog.time_ctl import NaturalTime
>>> time_ = NaturalTime()
time()
¶
Overview
Get current natural time (float format, unix timestamp)
Returns:
| Type | Description |
|---|---|
float
|
|
Example
from ding.utils.autolog.time_ctl import NaturalTime time_ = NaturalTime() time_.time() 1603896383.8811457
TickTime
¶
Bases: BaseTime
Overview
Tick time object
Interfaces:
__init__, step, time
Example:
>>> from ding.utils.autolog.time_ctl import TickTime
>>> time_ = TickTime()
__init__(init=0)
¶
Overview
Constructor of TickTime
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- init (
|
obj: |
required |
step(delta=1)
¶
Overview Step the time forward for this TickTime
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- delta (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
int
|
|
Example
from ding.utils.autolog.time_ctl import TickTime time_ = TickTime(0) time_.step() 1 time_.step(2) 3
time()
¶
Overview Get current tick time
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
current tick time |
Example
from ding.utils.autolog.time_ctl import TickTime time_ = TickTime(0) time_.step() time_.time() 1
TimeProxy
¶
Bases: BaseTime
Overview
Proxy of time object, it can freeze time, sometimes useful when reproducing. This object is thread-safe, and also freeze and unfreeze operation is strictly ordered.
Interfaces:
__init__, freeze, unfreeze, time, current_time
Examples:
>>> from ding.utils.autolog.time_ctl import TickTime, TimeProxy
>>> tick_time_ = TickTime()
>>> time_ = TimeProxy(tick_time_)
>>> tick_time_.step()
>>> print(tick_time_.time(), time_.time(), time_.current_time())
1 1 1
>>> time_.freeze()
>>> tick_time_.step()
>>> print(tick_time_.time(), time_.time(), time_.current_time())
2 1 2
>>> time_.unfreeze()
>>> print(tick_time_.time(), time_.time(), time_.current_time())
2 2 2
is_frozen
property
¶
Overview
Get if this time proxy object is frozen
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
true if it is frozen, otherwise false |
__init__(time_, frozen=False, lock_type=LockContextType.THREAD_LOCK)
¶
Overview
Constructor for Time proxy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- time_ (
|
obj: |
required | |
- frozen (
|
obj: |
required | |
- lock_type (
|
obj: |
required |
freeze()
¶
Overview
Freeze this time proxy
unfreeze()
¶
Overview
Unfreeze this time proxy
time()
¶
Overview
Get time (may be frozen time)
Returns:
| Type | Description |
|---|---|
Union[int, float]
|
int or float: the time |
current_time()
¶
Overview
Get current time (will not be frozen time)
Returns:
| Type | Description |
|---|---|
Union[int, float]
|
int or float: current time |
Full Source Code
../ding/utils/autolog/time_ctl.py