Skip to content

Commit a7e1861

Browse files
authored
Fix: add mujoco render arguments to init (openai#2891)
* fix: add render_mode getter to Wrappers * fix: add render args to mujoco init * reformat * add type hints
1 parent f2aeb82 commit a7e1861

29 files changed

+88
-151
lines changed

gym/envs/mujoco/ant.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
from typing import Optional
2-
31
import numpy as np
42

53
from gym import utils
64
from gym.envs.mujoco import mujoco_env
75

86

97
class AntEnv(mujoco_env.MujocoEnv, utils.EzPickle):
10-
def __init__(self, render_mode: Optional[str] = None):
8+
def __init__(self, **kwargs):
119
mujoco_env.MujocoEnv.__init__(
12-
self, "ant.xml", 5, render_mode=render_mode, mujoco_bindings="mujoco_py"
10+
self, "ant.xml", 5, mujoco_bindings="mujoco_py", **kwargs
1311
)
1412
utils.EzPickle.__init__(self)
1513

gym/envs/mujoco/ant_v3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
import numpy as np
42

53
from gym import utils
@@ -13,7 +11,6 @@
1311
class AntEnv(mujoco_env.MujocoEnv, utils.EzPickle):
1412
def __init__(
1513
self,
16-
render_mode: Optional[str] = None,
1714
xml_file="ant.xml",
1815
ctrl_cost_weight=0.5,
1916
contact_cost_weight=5e-4,
@@ -23,6 +20,7 @@ def __init__(
2320
contact_force_range=(-1.0, 1.0),
2421
reset_noise_scale=0.1,
2522
exclude_current_positions_from_observation=True,
23+
**kwargs
2624
):
2725
utils.EzPickle.__init__(**locals())
2826

@@ -41,7 +39,9 @@ def __init__(
4139
exclude_current_positions_from_observation
4240
)
4341

44-
mujoco_env.MujocoEnv.__init__(self, xml_file, 5, mujoco_bindings="mujoco_py")
42+
mujoco_env.MujocoEnv.__init__(
43+
self, xml_file, 5, mujoco_bindings="mujoco_py", **kwargs
44+
)
4545

4646
@property
4747
def healthy_reward(self):

gym/envs/mujoco/ant_v4.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
import numpy as np
42

53
from gym import utils
@@ -166,7 +164,6 @@ class AntEnv(mujoco_env.MujocoEnv, utils.EzPickle):
166164

167165
def __init__(
168166
self,
169-
render_mode: Optional[str] = None,
170167
xml_file="ant.xml",
171168
ctrl_cost_weight=0.5,
172169
use_contact_forces=False,
@@ -177,6 +174,7 @@ def __init__(
177174
contact_force_range=(-1.0, 1.0),
178175
reset_noise_scale=0.1,
179176
exclude_current_positions_from_observation=True,
177+
**kwargs
180178
):
181179
utils.EzPickle.__init__(**locals())
182180

@@ -197,7 +195,7 @@ def __init__(
197195
exclude_current_positions_from_observation
198196
)
199197

200-
mujoco_env.MujocoEnv.__init__(self, xml_file, 5, render_mode=render_mode)
198+
mujoco_env.MujocoEnv.__init__(self, xml_file, 5, **kwargs)
201199

202200
@property
203201
def healthy_reward(self):

gym/envs/mujoco/half_cheetah.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
from typing import Optional
2-
31
import numpy as np
42

53
from gym import utils
64
from gym.envs.mujoco import mujoco_env
75

86

97
class HalfCheetahEnv(mujoco_env.MujocoEnv, utils.EzPickle):
10-
def __init__(self, render_mode: Optional[str] = None):
8+
def __init__(self, **kwargs):
119
mujoco_env.MujocoEnv.__init__(
12-
self,
13-
"half_cheetah.xml",
14-
5,
15-
render_mode=render_mode,
16-
mujoco_bindings="mujoco_py",
10+
self, "half_cheetah.xml", 5, mujoco_bindings="mujoco_py", **kwargs
1711
)
1812
utils.EzPickle.__init__(self)
1913

gym/envs/mujoco/half_cheetah_v3.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
__credits__ = ["Rushiv Arora"]
22

3-
from typing import Optional
4-
53
import numpy as np
64

75
from gym import utils
@@ -15,12 +13,12 @@
1513
class HalfCheetahEnv(mujoco_env.MujocoEnv, utils.EzPickle):
1614
def __init__(
1715
self,
18-
render_mode: Optional[str] = None,
1916
xml_file="half_cheetah.xml",
2017
forward_reward_weight=1.0,
2118
ctrl_cost_weight=0.1,
2219
reset_noise_scale=0.1,
2320
exclude_current_positions_from_observation=True,
21+
**kwargs
2422
):
2523
utils.EzPickle.__init__(**locals())
2624

@@ -35,7 +33,7 @@ def __init__(
3533
)
3634

3735
mujoco_env.MujocoEnv.__init__(
38-
self, xml_file, 5, render_mode=render_mode, mujoco_bindings="mujoco_py"
36+
self, xml_file, 5, mujoco_bindings="mujoco_py", **kwargs
3937
)
4038

4139
def control_cost(self, action):

gym/envs/mujoco/half_cheetah_v4.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
__credits__ = ["Rushiv Arora"]
22

3-
from typing import Optional
4-
53
import numpy as np
64

75
from gym import utils
@@ -151,11 +149,11 @@ class HalfCheetahEnv(mujoco_env.MujocoEnv, utils.EzPickle):
151149

152150
def __init__(
153151
self,
154-
render_mode: Optional[str] = None,
155152
forward_reward_weight=1.0,
156153
ctrl_cost_weight=0.1,
157154
reset_noise_scale=0.1,
158155
exclude_current_positions_from_observation=True,
156+
**kwargs
159157
):
160158
utils.EzPickle.__init__(**locals())
161159

@@ -169,9 +167,7 @@ def __init__(
169167
exclude_current_positions_from_observation
170168
)
171169

172-
mujoco_env.MujocoEnv.__init__(
173-
self, "half_cheetah.xml", 5, render_mode=render_mode
174-
)
170+
mujoco_env.MujocoEnv.__init__(self, "half_cheetah.xml", 5, **kwargs)
175171

176172
def control_cost(self, action):
177173
control_cost = self._ctrl_cost_weight * np.sum(np.square(action))

gym/envs/mujoco/hopper.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
from typing import Optional
2-
31
import numpy as np
42

53
from gym import utils
64
from gym.envs.mujoco import mujoco_env
75

86

97
class HopperEnv(mujoco_env.MujocoEnv, utils.EzPickle):
10-
def __init__(self, render_mode: Optional[str] = None):
8+
def __init__(self, **kwargs):
119
mujoco_env.MujocoEnv.__init__(
12-
self, "hopper.xml", 4, render_mode=render_mode, mujoco_bindings="mujoco_py"
10+
self, "hopper.xml", 4, mujoco_bindings="mujoco_py", **kwargs
1311
)
1412
utils.EzPickle.__init__(self)
1513

gym/envs/mujoco/hopper_v3.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
__credits__ = ["Rushiv Arora"]
22

3-
from typing import Optional
4-
53
import numpy as np
64

75
from gym import utils
@@ -18,7 +16,6 @@
1816
class HopperEnv(mujoco_env.MujocoEnv, utils.EzPickle):
1917
def __init__(
2018
self,
21-
render_mode: Optional[str] = None,
2219
xml_file="hopper.xml",
2320
forward_reward_weight=1.0,
2421
ctrl_cost_weight=1e-3,
@@ -29,6 +26,7 @@ def __init__(
2926
healthy_angle_range=(-0.2, 0.2),
3027
reset_noise_scale=5e-3,
3128
exclude_current_positions_from_observation=True,
29+
**kwargs
3230
):
3331
utils.EzPickle.__init__(**locals())
3432

@@ -50,7 +48,7 @@ def __init__(
5048
)
5149

5250
mujoco_env.MujocoEnv.__init__(
53-
self, xml_file, 4, render_mode=render_mode, mujoco_bindings="mujoco_py"
51+
self, xml_file, 4, mujoco_bindings="mujoco_py", **kwargs
5452
)
5553

5654
@property

gym/envs/mujoco/hopper_v4.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
import numpy as np
42

53
from gym import utils
@@ -142,7 +140,6 @@ class HopperEnv(mujoco_env.MujocoEnv, utils.EzPickle):
142140

143141
def __init__(
144142
self,
145-
render_mode: Optional[str] = None,
146143
forward_reward_weight=1.0,
147144
ctrl_cost_weight=1e-3,
148145
healthy_reward=1.0,
@@ -152,6 +149,7 @@ def __init__(
152149
healthy_angle_range=(-0.2, 0.2),
153150
reset_noise_scale=5e-3,
154151
exclude_current_positions_from_observation=True,
152+
**kwargs
155153
):
156154
utils.EzPickle.__init__(**locals())
157155

@@ -172,7 +170,7 @@ def __init__(
172170
exclude_current_positions_from_observation
173171
)
174172

175-
mujoco_env.MujocoEnv.__init__(self, "hopper.xml", 4, render_mode=render_mode)
173+
mujoco_env.MujocoEnv.__init__(self, "hopper.xml", 4, **kwargs)
176174

177175
@property
178176
def healthy_reward(self):

gym/envs/mujoco/humanoid.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
import numpy as np
42

53
from gym import utils
@@ -13,13 +11,9 @@ def mass_center(model, sim):
1311

1412

1513
class HumanoidEnv(mujoco_env.MujocoEnv, utils.EzPickle):
16-
def __init__(self, render_mode: Optional[str] = None):
14+
def __init__(self, **kwargs):
1715
mujoco_env.MujocoEnv.__init__(
18-
self,
19-
"humanoid.xml",
20-
5,
21-
render_mode=render_mode,
22-
mujoco_bindings="mujoco_py",
16+
self, "humanoid.xml", 5, mujoco_bindings="mujoco_py", **kwargs
2317
)
2418
utils.EzPickle.__init__(self)
2519

0 commit comments

Comments
 (0)