Farama-Foundation / Gymnasium

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)

Home Page:https://gymnasium.farama.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

TimSchneider42 opened this issue · comments

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