Skip to content

Commit

Permalink
Fix Isaac Lab environments reset returns when called twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni-SM committed Aug 4, 2024
1 parent ebb2095 commit 2ef1049
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions skrl/envs/wrappers/torch/isaaclab_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ def __init__(self, env: Any) -> None:

self._reset_once = True
self._obs_dict = None
self._info = {}

@property
def state_space(self) -> gymnasium.Space:
"""State space
"""
try:
return self._unwrapped.single_observation_space["critic"]
except:
return self._unwrapped.state_space

@property
def observation_space(self) -> gymnasium.Space:
Expand Down Expand Up @@ -46,8 +56,8 @@ def step(self, actions: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch
:return: Observation, reward, terminated, truncated, info
:rtype: tuple of torch.Tensor and any other info
"""
self._obs_dict, reward, terminated, truncated, info = self._env.step(actions)
return self._obs_dict["policy"], reward.view(-1, 1), terminated.view(-1, 1), truncated.view(-1, 1), info
self._obs_dict, reward, terminated, truncated, self._info = self._env.step(actions)
return self._obs_dict["policy"], reward.view(-1, 1), terminated.view(-1, 1), truncated.view(-1, 1), self._info

def reset(self) -> Tuple[torch.Tensor, Any]:
"""Reset the environment
Expand All @@ -56,9 +66,9 @@ def reset(self) -> Tuple[torch.Tensor, Any]:
:rtype: torch.Tensor and any other info
"""
if self._reset_once:
self._obs_dict, info = self._env.reset()
self._obs_dict, self._info = self._env.reset()
self._reset_once = False
return self._obs_dict["policy"], info
return self._obs_dict["policy"], self._info

def render(self, *args, **kwargs) -> None:
"""Render the environment
Expand Down

0 comments on commit 2ef1049

Please sign in to comment.