Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug in D4RL that the seed parameter is ignored. #223

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions d4rl/locomotion/ant.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def reset(self):
def set_target(self, target_location=None):
return self.set_target_goal(target_location)

def seed(self, seed=0):
mujoco_env.MujocoEnv.seed(self, seed)
def seed(self, seed=None):
mujoco_env.MujocoEnv.seed(self, seed)

def make_ant_maze_env(**kwargs):
env = AntMazeEnv(**kwargs)
Expand Down
20 changes: 10 additions & 10 deletions d4rl/locomotion/maze_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ def _xy_to_rowcol(self, xy):
def _get_reset_location(self,):
prob = (1.0 - self._np_maze_map) / np.sum(1.0 - self._np_maze_map)
prob_row = np.sum(prob, 1)
row_sample = np.random.choice(np.arange(self._np_maze_map.shape[0]), p=prob_row)
col_sample = np.random.choice(np.arange(self._np_maze_map.shape[1]), p=prob[row_sample] * 1.0 / prob_row[row_sample])
row_sample = self.np_random.choice(np.arange(self._np_maze_map.shape[0]), p=prob_row)
col_sample = self.np_random.choice(np.arange(self._np_maze_map.shape[1]), p=prob[row_sample] * 1.0 / prob_row[row_sample])
reset_location = self._rowcol_to_xy((row_sample, col_sample))

# Add some random noise
random_x = np.random.uniform(low=0, high=0.5) * 0.5 * self._maze_size_scaling
random_y = np.random.uniform(low=0, high=0.5) * 0.5 * self._maze_size_scaling
random_x = self.np_random.uniform(low=0, high=0.5) * 0.5 * self._maze_size_scaling
random_y = self.np_random.uniform(low=0, high=0.5) * 0.5 * self._maze_size_scaling

return (max(reset_location[0] + random_x, 0), max(reset_location[1] + random_y, 0))

Expand All @@ -229,8 +229,8 @@ def _rowcol_to_xy(self, rowcol, add_random_noise=False):
x = col * self._maze_size_scaling - self._init_torso_x
y = row * self._maze_size_scaling - self._init_torso_y
if add_random_noise:
x = x + np.random.uniform(low=0, high=self._maze_size_scaling * 0.25)
y = y + np.random.uniform(low=0, high=self._maze_size_scaling * 0.25)
x = x + self.np_random.uniform(low=0, high=self._maze_size_scaling * 0.25)
y = y + self.np_random.uniform(low=0, high=self._maze_size_scaling * 0.25)
return (x, y)

def goal_sampler(self, np_random, only_free_cells=True, interpolate=True):
Expand All @@ -247,19 +247,19 @@ def goal_sampler(self, np_random, only_free_cells=True, interpolate=True):
# If there is a 'goal' designated, use that. Otherwise, any valid cell can
# be a goal.
sample_choices = goal_cells if goal_cells else valid_cells
cell = sample_choices[np_random.choice(len(sample_choices))]
cell = sample_choices[self.np_random.choice(len(sample_choices))]
xy = self._rowcol_to_xy(cell, add_random_noise=True)

random_x = np.random.uniform(low=0, high=0.5) * 0.25 * self._maze_size_scaling
random_y = np.random.uniform(low=0, high=0.5) * 0.25 * self._maze_size_scaling
random_x = self.np_random.uniform(low=0, high=0.5) * 0.25 * self._maze_size_scaling
random_y = self.np_random.uniform(low=0, high=0.5) * 0.25 * self._maze_size_scaling

xy = (max(xy[0] + random_x, 0), max(xy[1] + random_y, 0))

return xy

def set_target_goal(self, goal_input=None):
if goal_input is None:
self.target_goal = self.goal_sampler(np.random)
self.target_goal = self.goal_sampler(self.np_random)
else:
self.target_goal = goal_input

Expand Down
3 changes: 3 additions & 0 deletions d4rl/locomotion/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def reset(self, **kwargs):

def step(self, action):
return self._wrapped_env.step(action)

def seed(self, seed=None):
return self._wrapped_env.seed(seed)

def render(self, *args, **kwargs):
return self._wrapped_env.render(*args, **kwargs)
Expand Down