2020-01-23 02:02:58 +01:00
|
|
|
from functools import partial
|
|
|
|
|
2019-12-30 15:27:32 -05:00
|
|
|
from ray.rllib.utils.annotations import override, PublicAPI, DeveloperAPI
|
|
|
|
from ray.rllib.utils.framework import try_import_tf, try_import_tfp, \
|
2020-06-08 23:04:50 -07:00
|
|
|
try_import_torch
|
2019-12-30 15:27:32 -05:00
|
|
|
from ray.rllib.utils.deprecation import deprecation_warning, renamed_agent, \
|
|
|
|
renamed_class, renamed_function
|
2017-12-30 00:24:54 -08:00
|
|
|
from ray.rllib.utils.filter_manager import FilterManager
|
2018-07-01 00:05:08 -07:00
|
|
|
from ray.rllib.utils.filter import Filter
|
2019-12-30 15:27:32 -05:00
|
|
|
from ray.rllib.utils.numpy import sigmoid, softmax, relu, one_hot, fc, lstm, \
|
2020-02-22 23:19:49 +01:00
|
|
|
SMALL_NUMBER, LARGE_INTEGER, MIN_LOG_NN_OUTPUT, MAX_LOG_NN_OUTPUT
|
2020-01-28 20:07:55 +01:00
|
|
|
from ray.rllib.utils.schedules import LinearSchedule, PiecewiseSchedule, \
|
|
|
|
PolynomialSchedule, ExponentialSchedule, ConstantSchedule
|
2020-06-13 17:51:50 +02:00
|
|
|
from ray.rllib.utils.test_utils import check, check_compute_single_action, \
|
|
|
|
framework_iterator
|
2020-01-06 21:11:03 -05:00
|
|
|
from ray.tune.utils import merge_dicts, deep_update
|
2017-12-30 00:24:54 -08:00
|
|
|
|
2019-05-20 16:46:05 -07:00
|
|
|
|
2019-06-07 16:45:36 -07:00
|
|
|
def add_mixins(base, mixins):
|
|
|
|
"""Returns a new class with mixins applied in priority order."""
|
|
|
|
|
|
|
|
mixins = list(mixins or [])
|
|
|
|
|
|
|
|
while mixins:
|
|
|
|
|
|
|
|
class new_base(mixins.pop(), base):
|
|
|
|
pass
|
|
|
|
|
|
|
|
base = new_base
|
|
|
|
|
|
|
|
return base
|
|
|
|
|
|
|
|
|
2020-01-23 02:02:58 +01:00
|
|
|
def force_list(elements=None, to_tuple=False):
|
|
|
|
"""
|
|
|
|
Makes sure `elements` is returned as a list, whether `elements` is a single
|
|
|
|
item, already a list, or a tuple.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
elements (Optional[any]): The inputs as single item, list, or tuple to
|
|
|
|
be converted into a list/tuple. If None, returns empty list/tuple.
|
|
|
|
to_tuple (bool): Whether to use tuple (instead of list).
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Union[list,tuple]: All given elements in a list/tuple depending on
|
|
|
|
`to_tuple`'s value. If elements is None,
|
|
|
|
returns an empty list/tuple.
|
|
|
|
"""
|
|
|
|
ctor = list
|
|
|
|
if to_tuple is True:
|
|
|
|
ctor = tuple
|
|
|
|
return ctor() if elements is None else ctor(elements) \
|
|
|
|
if type(elements) in [list, tuple] else ctor([elements])
|
|
|
|
|
|
|
|
|
2020-12-26 20:14:18 -05:00
|
|
|
class NullContextManager:
|
|
|
|
"""No-op context manager"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-01-23 02:02:58 +01:00
|
|
|
force_tuple = partial(force_list, to_tuple=True)
|
|
|
|
|
2018-12-26 03:07:11 -08:00
|
|
|
__all__ = [
|
2019-12-30 15:27:32 -05:00
|
|
|
"add_mixins",
|
|
|
|
"check",
|
2020-06-13 17:51:50 +02:00
|
|
|
"check_compute_single_action",
|
2020-10-02 23:07:44 +02:00
|
|
|
"deep_update",
|
2019-12-30 15:27:32 -05:00
|
|
|
"deprecation_warning",
|
|
|
|
"fc",
|
2020-01-23 02:02:58 +01:00
|
|
|
"force_list",
|
|
|
|
"force_tuple",
|
2020-04-03 21:24:25 +02:00
|
|
|
"framework_iterator",
|
2019-12-30 15:27:32 -05:00
|
|
|
"lstm",
|
|
|
|
"merge_dicts",
|
2020-10-02 23:07:44 +02:00
|
|
|
"one_hot",
|
2019-12-30 15:27:32 -05:00
|
|
|
"override",
|
2020-10-02 23:07:44 +02:00
|
|
|
"relu",
|
2019-12-30 15:27:32 -05:00
|
|
|
"renamed_function",
|
|
|
|
"renamed_agent",
|
|
|
|
"renamed_class",
|
2020-10-02 23:07:44 +02:00
|
|
|
"sigmoid",
|
|
|
|
"softmax",
|
2019-12-30 15:27:32 -05:00
|
|
|
"try_import_tf",
|
|
|
|
"try_import_tfp",
|
|
|
|
"try_import_torch",
|
2020-01-28 20:07:55 +01:00
|
|
|
"ConstantSchedule",
|
2019-12-30 15:27:32 -05:00
|
|
|
"DeveloperAPI",
|
2020-01-28 20:07:55 +01:00
|
|
|
"ExponentialSchedule",
|
2019-04-07 00:36:18 -07:00
|
|
|
"Filter",
|
|
|
|
"FilterManager",
|
2019-12-30 15:27:32 -05:00
|
|
|
"LARGE_INTEGER",
|
2020-01-28 20:07:55 +01:00
|
|
|
"LinearSchedule",
|
2020-02-22 23:19:49 +01:00
|
|
|
"MAX_LOG_NN_OUTPUT",
|
|
|
|
"MIN_LOG_NN_OUTPUT",
|
2020-01-28 20:07:55 +01:00
|
|
|
"PiecewiseSchedule",
|
|
|
|
"PolynomialSchedule",
|
2019-12-30 15:27:32 -05:00
|
|
|
"PublicAPI",
|
|
|
|
"SMALL_NUMBER",
|
2018-12-26 03:07:11 -08:00
|
|
|
]
|