isaac-sim / IsaacLab

Unified framework for robot learning built on NVIDIA Isaac Sim
https://isaac-sim.github.io/IsaacLab
Other
2.22k stars 916 forks source link

[Bug Report] Setting DirectRLEnv max_episode_length Causing Crash when Env is truncated #1335

Open SuomiKP31 opened 2 weeks ago

SuomiKP31 commented 2 weeks ago

Describe the bug

When a DirectRLEnv is truncated by having a max_episode_length property set in gym.register,

Isaac Lab will crash when a truncate happens. The root cause being a single "True" is returned from env.step(action) as "truncate", instead of a tensor.

Steps to reproduce

When a DirectRLEnv is truncated by having a max_episode_length property set in gym.register, such as

gym.register(
    id="Isaac-Cartpole-Direct-v0",
    entry_point="omni.isaac.lab_tasks.direct.cartpole:CartpoleEnv",
    disable_env_checker=True,
    max_episode_steps=10,
    kwargs={
        "env_cfg_entry_point": CartpoleEnvCfg,
        "rl_games_cfg_entry_point": f"{agents.__name__}:rl_games_ppo_cfg.yaml",
        "rsl_rl_cfg_entry_point": f"{agents.__name__}.rsl_rl_ppo_cfg:CartpolePPORunnerCfg",
        "skrl_cfg_entry_point": f"{agents.__name__}:skrl_ppo_cfg.yaml",
        "sb3_cfg_entry_point": f"{agents.__name__}:sb3_ppo_cfg.yaml",
    },
)

Note that I set it to 10 to ensure a quick crash. Setting it for higher can delay the crash. If a truncate never happens, it doesn't crash.

running .\isaaclab.bat -p .\source\standalone\workflows\sb3\train.py --task=Isaac-Cartpole-Direct-v0 --num_envs=64 will cause a crash with error message:

  File "C:\Users\mbran\miniconda3\envs\isaaclab\lib\site-packages\stable_baselines3\common\on_policy_algorithm.py", line 300, in learn
    continue_training = self.collect_rollouts(self.env, callback, self.rollout_buffer, n_rollout_steps=self.n_steps)
  File "C:\Users\mbran\miniconda3\envs\isaaclab\lib\site-packages\stable_baselines3\common\on_policy_algorithm.py", line 195, in collect_rollouts
    new_obs, rewards, dones, infos = env.step(clipped_actions)
  File "C:\Users\mbran\miniconda3\envs\isaaclab\lib\site-packages\stable_baselines3\common\vec_env\base_vec_env.py", line 206, in step
    return self.step_wait()
  File "C:\Work_shin\IsaacLab\source\extensions\omni.isaac.lab_tasks\omni\isaac\lab_tasks\utils\wrappers\sb3.py", line 239, in step_wait
    truncated = truncated.detach().cpu().numpy()
AttributeError: 'bool' object has no attribute 'detach'

image

Here, a single bool "True" is returned instead of a vector. I also tested using rsl_rl, it crashes as well, just with a different error message.

System Info

Describe the characteristic of your environment:

Additional context

If you want your episodes to end at the specific episode length, you can directly modify max_episode_s or code additional behaviors in _get_dones() in your environment.

Checklist

Acceptance Criteria

Add the criteria for which this task is considered done. If not known at issue creation time, you can add this once the issue is assigned.

RandomOakForest commented 1 week ago

Thanks for filing this. Will fix.