Skip to content

Commit

Permalink
cartpole fix (openai#457)
Browse files Browse the repository at this point in the history
minor fixes related to configure() and cartpole
  • Loading branch information
joschu authored Jan 4, 2017
1 parent c6f337e commit a67653c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
4 changes: 1 addition & 3 deletions gym/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ def __init__(self, env=None):

self._update_wrapper_stack()
if env and env._configured:
# TODO: CartPole currently calls configure on `make`. Fix this so that we can use WrapAfterConfigureError
# raise error.WrapAfterConfigureError("Attempted to wrap env {} after .configure() was called. All wrappers must be applied before calling .configure()".format(env))
logger.warn("Attempted to wrap env {} after .configure() was called. All wrappers must be applied before calling .configure()".format(env))
logger.warning("Attempted to wrap env %s after .configure() was called.", env)

def _update_wrapper_stack(self):
"""
Expand Down
11 changes: 2 additions & 9 deletions gym/envs/classic_control/cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ def __init__(self):
self.observation_space = spaces.Box(-high, high)

self._seed()
self.reset()
self.viewer = None

self.steps_beyond_done = None

# Just need to initialize the relevant attributes
self._configure()

def _configure(self, display=None):
self.display = display

def _seed(self, seed=None):
self.np_random, seed = seeding.np_random(seed)
return [seed]
Expand Down Expand Up @@ -87,7 +80,7 @@ def _step(self, action):
reward = 1.0
else:
if self.steps_beyond_done == 0:
logger.warn("You are calling 'step()' even though this environment has already returned done = True. You should always call 'reset()' once you receive 'done = True' -- any further steps are undefined behavior.")
logger.warning("You are calling 'step()' even though this environment has already returned done = True. You should always call 'reset()' once you receive 'done = True' -- any further steps are undefined behavior.")
self.steps_beyond_done += 1
reward = 0.0

Expand Down Expand Up @@ -118,7 +111,7 @@ def _render(self, mode='human', close=False):

if self.viewer is None:
from gym.envs.classic_control import rendering
self.viewer = rendering.Viewer(screen_width, screen_height, display=self.display)
self.viewer = rendering.Viewer(screen_width, screen_height)
l,r,t,b = -cartwidth/2, cartwidth/2, cartheight/2, -cartheight/2
axleoffset =cartheight/4.0
cart = rendering.FilledPolygon([(l,b), (l,t), (r,t), (r,b)])
Expand Down

0 comments on commit a67653c

Please sign in to comment.