1
1
from __future__ import annotations
2
2
3
- import warnings
4
3
from typing import Any
5
4
6
5
import gymnasium .spaces
@@ -19,72 +18,12 @@ def __init__(self, env: AECEnv[AgentID, ObsType, ActionType]):
19
18
super ().__init__ ()
20
19
self .env = env
21
20
22
- try :
23
- self .possible_agents = self .env .possible_agents
24
- except AttributeError :
25
- pass
26
-
27
- self .metadata = self .env .metadata
28
-
29
- # we don't want these defined as we don't want them used before they are gotten
30
-
31
- # self.agent_selection = self.env.agent_selection
32
-
33
- # self.rewards = self.env.rewards
34
- # self.dones = self.env.dones
35
-
36
- # we don't want to care one way or the other whether environments have an infos or not before reset
37
- try :
38
- self .infos = self .env .infos
39
- except AttributeError :
40
- pass
41
-
42
- # Not every environment has the .state_space attribute implemented
43
- try :
44
- self .state_space = (
45
- self .env .state_space # pyright: ignore[reportGeneralTypeIssues]
46
- )
47
- except AttributeError :
48
- pass
49
-
50
21
def __getattr__ (self , name : str ) -> Any :
51
22
"""Returns an attribute with ``name``, unless ``name`` starts with an underscore."""
52
- if name .startswith ("_" ):
23
+ if name .startswith ("_" ) and name != "_cumulative_rewards" :
53
24
raise AttributeError (f"accessing private attribute '{ name } ' is prohibited" )
54
25
return getattr (self .env , name )
55
26
56
- @property
57
- def observation_spaces (self ) -> dict [AgentID , gymnasium .spaces .Space ]:
58
- warnings .warn (
59
- "The `observation_spaces` dictionary is deprecated. Use the `observation_space` function instead."
60
- )
61
- try :
62
- return {
63
- agent : self .observation_space (agent ) for agent in self .possible_agents
64
- }
65
- except AttributeError as e :
66
- raise AttributeError (
67
- "The base environment does not have an `observation_spaces` dict attribute. Use the environment's `observation_space` method instead"
68
- ) from e
69
-
70
- @property
71
- def action_spaces (self ) -> dict [AgentID , gymnasium .spaces .Space ]:
72
- warnings .warn (
73
- "The `action_spaces` dictionary is deprecated. Use the `action_space` function instead."
74
- )
75
- try :
76
- return {agent : self .action_space (agent ) for agent in self .possible_agents }
77
- except AttributeError as e :
78
- raise AttributeError (
79
- "The base environment does not have an action_spaces dict attribute. Use the environment's `action_space` method instead"
80
- ) from e
81
-
82
- def observation_space (self , agent : AgentID ) -> gymnasium .spaces .Space :
83
- return self .env .observation_space (agent )
84
-
85
- def action_space (self , agent : AgentID ) -> gymnasium .spaces .Space :
86
- return self .env .action_space (agent )
87
-
88
27
@property
89
28
def unwrapped (self ) -> AECEnv :
90
29
return self .env .unwrapped
@@ -98,14 +37,6 @@ def render(self) -> None | np.ndarray | str | list:
98
37
def reset (self , seed : int | None = None , options : dict | None = None ):
99
38
self .env .reset (seed = seed , options = options )
100
39
101
- self .agent_selection = self .env .agent_selection
102
- self .rewards = self .env .rewards
103
- self .terminations = self .env .terminations
104
- self .truncations = self .env .truncations
105
- self .infos = self .env .infos
106
- self .agents = self .env .agents
107
- self ._cumulative_rewards = self .env ._cumulative_rewards
108
-
109
40
def observe (self , agent : AgentID ) -> ObsType | None :
110
41
return self .env .observe (agent )
111
42
@@ -115,13 +46,11 @@ def state(self) -> np.ndarray:
115
46
def step (self , action : ActionType ) -> None :
116
47
self .env .step (action )
117
48
118
- self .agent_selection = self .env .agent_selection
119
- self .rewards = self .env .rewards
120
- self .terminations = self .env .terminations
121
- self .truncations = self .env .truncations
122
- self .infos = self .env .infos
123
- self .agents = self .env .agents
124
- self ._cumulative_rewards = self .env ._cumulative_rewards
49
+ def observation_space (self , agent : AgentID ) -> gymnasium .spaces .Space :
50
+ return self .env .observation_space (agent )
51
+
52
+ def action_space (self , agent : AgentID ) -> gymnasium .spaces .Space :
53
+ return self .env .action_space (agent )
125
54
126
55
def __str__ (self ) -> str :
127
56
"""Returns a name which looks like: "max_observation<space_invaders_v1>"."""
0 commit comments