-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathenv_plugin.py
71 lines (60 loc) · 2.33 KB
/
env_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (C) 2018 Heron Systems, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
from adept.utils.requires_args import RequiresArgs
from adept.environments._env import HasEnvMetaData
class EnvPlugin(HasEnvMetaData, RequiresArgs, metaclass=abc.ABCMeta):
"""
Implement this class to add your custom environment. Don't forget to
implement defaults.
"""
def __init__(self, action_space, cpu_preprocessor, gpu_preprocessor):
"""
:param observation_space: ._spaces.Spaces
:param action_space: ._spaces.Spaces
:param cpu_preprocessor: adept.preprocess.observation.ObsPreprocessor
:param gpu_preprocessor: adept.preprocess.observation.ObsPreprocessor
"""
self._action_space = action_space
self._cpu_preprocessor = cpu_preprocessor
self._gpu_preprocessor = gpu_preprocessor
@classmethod
@abc.abstractmethod
def from_args(cls, args, seed, **kwargs):
"""
Construct from arguments. For convenience.
:param args: Arguments object
:param seed: Integer used to seed this environment.
:param kwargs: Any custom arguments are passed through kwargs.
:return: EnvPlugin instance.
"""
raise NotImplementedError
@classmethod
def from_args_curry(cls, args, seed, **kwargs):
def _f():
return cls.from_args(args, seed, **kwargs)
return _f
@property
def observation_space(self):
return self._gpu_preprocessor.observation_space
@property
def action_space(self):
return self._action_space
@property
def cpu_preprocessor(self):
return self._cpu_preprocessor
@property
def gpu_preprocessor(self):
return self._gpu_preprocessor