0

Aim : For a mujoco environment (I'm using Metaworld) for example - "Sweep-into", I want to do this :

Reset Environment : Take some actions ... sim_state = Save the current state Take some actions ...

    env.seed(0)
    env.reset()
    env.step() ... several times
    sim_state = env.sim.get_state()
    img = env.render('rgb_array')
    env.step() ... several actions

Then : Reset Environment

    env.seed(0)
    env.reset()
    env.sim.set_state(sim_state)
    img_loaded = env.render('rgb_array') 
    sim_state_loaded = env.sim.get_state()

I find that sim_state_loaded is same as env.sim.get_state() but the image (img != img_loaded) is not the same. I only care about getting the image after setting the state.

I have already tried playing around by setting the seed before hand.

There are some domains where using env.set_state(qpos, qvel) [not env.sim.set_state] will return the same image observation but using that same env object doesn't render valid images / states etc.

Mudit Verma
  • 374
  • 2
  • 6

1 Answers1

1

I'm not familiar with Metaworld, but in principle some computation (e.g., kinematics) is needed between writing a new value into the state vector and calling the render function. If neither set_state nor render call these functions, this would explain the failure mode you've hit.

Try to call env.step before calling render, and if that fixes things you know what's missing. If calling step is unacceptable (e.g., because you don't want to advance the simulation), look for a way to call mj_forward with the underlying mjModel and mjData structs.

Tom Erez
  • 11
  • 1