ray/rllib/utils/tuple_actions.py
Sven Mika 1775e89f26
[RLlib] Remove TupleActions and support arbitrarily nested action spaces. (#8143)
Deprecate TupleActions and support arbitrarily nested action spaces.
Closes issue #8143.
2020-04-28 14:59:16 +02:00

19 lines
740 B
Python

from collections import namedtuple
from ray.rllib.utils.deprecation import deprecation_warning
# NOTE: This is a deprecated class. Use native python tuples
# or dicts (both arbitrarily nested) for multi-actions from here on.
class TupleActions(namedtuple("TupleActions", ["batches"])):
"""Used to return tuple actions as a list of batches per tuple element."""
def __new__(cls, batches):
# Throw an informative error if used.
deprecation_warning(
old="TupleActions",
new="`native python tuples (arbitrarily nested)`",
error=True)
return super(TupleActions, cls).__new__(cls, batches)
def numpy(self):
return TupleActions([b.numpy() for b in self.batches])