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

[Bug Report] CartPoleVectorEnv resets one step to early, not following the new VectorEnv API #914

Closed
1 task done
TimSchneider42 opened this issue Feb 6, 2024 · 0 comments · Fixed by #915
Closed
1 task done
Labels
bug Something isn't working

Comments

@TimSchneider42
Copy link
Contributor

TimSchneider42 commented Feb 6, 2024

Describe the bug

Hi,

according to #785, vector environments are supposed to return the final observation when the current episode is done, instead of immediately returning the first observation of the new episode. CartPoleVectorEnv currently does not do this and instead resets its done sub-environments immediately. To fix this issue, the reset of the sub-environments must be delayed, as in SyncVectorEnv.

Best,
Tim

Code example

from gymnasium.envs.classic_control.cartpole import CartPoleVectorEnv

env = CartPoleVectorEnv(num_envs=1)
env.reset()
while True:
    obs, _, terminated, _, _ = env.step(env.action_space.sample())
    print(obs[0, 0], terminated[0])

# Returns
# 0.0015773153863847256 False
# 0.006231468002155859 False
# 0.014796511112512602 False
# 0.027273956011089992 False
# 0.04366651893222766 False
# 0.06397767074946197 False
# 0.08041100911469909 False
# 0.10077359772242583 False
# -0.011319671757519245 True  <- This value should be from the final observation of the previous
#                                episode (somewhere around 0.1, not -0.01)

System info

No response

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo
@TimSchneider42 TimSchneider42 added the bug Something isn't working label Feb 6, 2024
TimSchneider42 pushed a commit to TimSchneider42/Gymnasium that referenced this issue Feb 6, 2024
…ng the reset of done environments until the next step. Fixes Farama-Foundation#914.
TimSchneider42 pushed a commit to TimSchneider42/Gymnasium that referenced this issue Feb 6, 2024
…ng the reset of done environments until the next step. Fixes Farama-Foundation#914.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant