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

Auto reset in Environment.step() means CartPole always returns reward = 1 #82

Open
garymm opened this issue Aug 3, 2024 · 2 comments
Open

Comments

@garymm
Copy link

garymm commented Aug 3, 2024

CartPole has this code which only sets reward = 0 if the previous state was terminal:

# Important: Reward is based on termination is previous step transition
reward = 1.0 - prev_terminal

Environment.step has this code which means a terminal state is never passed in to CartPole.step_env:

obs_st, state_st, reward, done, info = self.step_env(key, state, action, params)
obs_re, state_re = self.reset_env(key_reset, params)
# Auto-reset environment based on termination
state = jax.tree_map(
lambda x, y: jax.lax.select(done, x, y), state_re, state_st
)

Hence CartPole.step() always returns 1 which makes it entirely broken.

@samuelstevens
Copy link

I am experiencing the same issue.

@Michael190502
Copy link

Hi, I was looking into the same thing and I think there should not be a realistic scenario in which this zero reward is needed as it would only happen if you call step on an already terminated environment. This can also be seen in lines 212 and following of the gymnasium cartpole implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants