You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting an error from OrderEnforcingWrapper when trying to access env.action_spaces.
It comes from __getattr__, which I included in the code section for context.
I see several issues with that function as it's written:
value == "unwrapped" will never be triggered because the base class has an unwrapped property which returns the same result
value == "render_mode" duplicates the effect of the base class's __getattr__.
both "observation_spaces" and "action_spaces" have a misleading message (referring to possible_agents), and more importantly, don't check whether the base class has the attribute before raising an error claiming it doesn't exist.
Lastly, all of the cases except for the last elif statement are not related to the stated goal of the docstring and the intent of the class (as I understand it).
The chained wrappers are a bit unclear to me and it looks like there was already some work related to this on #1140 , so I wanted to see if I'm misunderstanding anything before submitting a change.
I'd like to address the items above as follows:
remove this
remove this
return the spaces if they exist, error otherwise; fix the text of the error
move all except last elif to BaseWrapper's __getattr__
Code example
def __getattr__(self, value: str) -> Any:
"""Raises an error message when data is gotten from the env. Should only be gotten after reset"""if value == "unwrapped":
return self.env.unwrapped
elif value == "render_mode" and hasattr(self.env, "render_mode"):
return self.env.render_mode # pyright: ignore[reportGeneralTypeIssues]elif value == "possible_agents":
try:
return self.env.possible_agents
except AttributeError:
EnvLogger.error_possible_agents_attribute_missing("possible_agents")
elif value == "observation_spaces":
raise AttributeError(
"The base environment does not have an possible_agents attribute. Use the environments `observation_space` method instead"
)
elif value == "action_spaces":
raise AttributeError(
"The base environment does not have an possible_agents attribute. Use the environments `action_space` method instead"
)
elif value == "agent_order":
raise AttributeError(
"agent_order has been removed from the API. Please consider using agent_iter instead."
)
elif (
value
in {
"rewards",
"terminations",
"truncations",
"infos",
"agent_selection",
"num_agents",
"agents",
}
and not self._has_reset
):
raise AttributeError(f"{value} cannot be accessed before reset")
else:
returnsuper().__getattr__(value)
Describe the bug
I'm getting an error from OrderEnforcingWrapper when trying to access env.action_spaces.
It comes from
__getattr__
, which I included in the code section for context.I see several issues with that function as it's written:
value == "unwrapped"
will never be triggered because the base class has an unwrapped property which returns the same resultvalue == "render_mode"
duplicates the effect of the base class's__getattr__
.possible_agents
), and more importantly, don't check whether the base class has the attribute before raising an error claiming it doesn't exist.elif
statement are not related to the stated goal of the docstring and the intent of the class (as I understand it).The chained wrappers are a bit unclear to me and it looks like there was already some work related to this on #1140 , so I wanted to see if I'm misunderstanding anything before submitting a change.
I'd like to address the items above as follows:
elif
toBaseWrapper
's__getattr__
Code example
System info
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: