openai/gym

Reset the environment to a specific state in Mujoco tasks.

Closed this issue · 2 comments

Hello, I'm training my mujoco agent with gym == 0.9.5, mujoco-py == 0.5.7, mjpro131 and on Windows 7. Currently, I'm good with the original API.

My question is, how to reset the environment to a specific state ? I want this function to do some analysis work.

I see that the original API in (for example) 'half_cheetah.py', the original reset_model() function does not take any params and reset the env to a random initialized state.
图片

Is there any built-in function to do this, or I have to overwrite the original API with a new reset_model(some_state) function? If so, please tell me which upstream files of 'half_cheetah.py' to modify?

Thanks in advance !

As you've noticed this is not a feature of the current API, it looks like you'll have to make your own environment (possibly starting with a copy-and-pasted version of half_cheetah or wrapper) that allows passing in the desired state.

As far as I know there is no built-in way to do this, but there is an existing issue about saving and restoring environment state here: #402

For a retro example, I had a get_state() and reset(state=state) functions that I added in a wrapper: https://github.com/openai/retro/blob/master/retro/examples/determinism.py#L35

Reset doesn't offer you this option, however the source code for mujoco_env.py shows there is a set_state( ) function you can use after you've performed the reset.

Keep in mind that set_state( ) expects the full input size, including the input related to the x position for the center of mass (which is normally hidden under default parameters).