Gymnasium: [Bug Report] MujocoEnv only accepts frame_skip=5

Describe the bug

The AntEnv class in ant-v4.py calls the MujocoEnv class with frame_skip=5 by default. Changing this value to any other value (e.g., frame_skip=1) results in an error.

More generally, it would be useful to be able to directly control the time step (self.dt). Currently it seems like the only way to control self.dt is by modifying self.frame_skip, such that self.dt=self.model.opt.timestep * self.frame_skip.

Code example

MujocoEnv.__init__(
    self,
    xml_file,
    frame_skip=1,
    observation_space=observation_space,
    default_camera_config=DEFAULT_CAMERA_CONFIG,
    **kwargs,
)

    MujocoEnv.__init__(
  File "D:\programs\Python\Python310\lib\site-packages\gymnasium\envs\mujoco\mujoco_env.py", line 333, in __init__
    super().__init__(
  File "D:\programs\Python\Python310\lib\site-packages\gymnasium\envs\mujoco\mujoco_env.py", line 65, in __init__
    int(np.round(1.0 / self.dt)) == self.metadata["render_fps"]
AssertionError: Expected value: 100, Actual value: 20

System info

No response

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Having a bigger dt means there will be more information contained in a step() (s, a, r, s') and therefore get your learning algorithm to learn with higher sample efficiency

The downside is the inability to give learn finer control

@pseudo-rnd-thoughts Great, I will add the frame_skip arg to the mujoco-v5 environments, and compute metadata.render_fps on __init__ time

@Omer1Yuval1 The render_fps is independent from the number of actions taken per simulation second and can in theory be any value. But round(1000/dt) seems reasonable, you need a positive integer. For the frame_skip, this is more complex as I believe that this refers to the length of internal time the same action is taken and should definitely be separate from render_fps.

@Kallinteris-Andreas No, as the original error of modifying frame_skip has no been solved. @rodrigodelazcano I think you missed the last @, could you look at the original error and know if there is an easy solution

@younik Could we add a fps parameter to the RecordVideoV0 to let people choice a custom fps that is not the environment’s render_fps. It can default to 30 to keep backward compatibility

Sure; for backward compatibility, the default value should be None and in that case, we use the value in metadata, correct?