Skip to content

Commit

Permalink
Merge pull request #40 from OliEfr/dev2
Browse files Browse the repository at this point in the history
support dynamic setting of action space in gymnasium envs
  • Loading branch information
robfiras authored Sep 9, 2024
2 parents 41a020c + 27c5e02 commit e21b63e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions loco_mujoco/environments/gymnasium.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def __init__(self, env_name, render_mode=None, **kwargs):
self.metadata["render_fps"] = 1.0 / self._env.dt

self.observation_space = self._convert_space(self._env.info.observation_space)
self.action_space = self._convert_space(self._env.info.action_space)
self._set_action_space()


def step(self, action):
"""
Expand Down Expand Up @@ -150,10 +151,17 @@ def unwrapped(self):
"""
return self._env

def _set_action_space(self):
"""
Setter for the action space.
"""
self.action_space = self._convert_space(self._env.info.action_space)
return self.action_space

@staticmethod
def _convert_space(space):
""" Converts the observation and action space from mushroom-rl to gymnasium. """
low = np.min(space.low)
high = np.max(space.high)
shape = space.shape
return Box(low, high, shape, np.float64)
return Box(low, high, shape, np.float64)

0 comments on commit e21b63e

Please sign in to comment.