isaac-sim / IsaacGymEnvs

Isaac Gym Reinforcement Learning Environments
Other
1.79k stars 392 forks source link

Funny Bug #125

Open GuoPingPan opened 1 year ago

GuoPingPan commented 1 year ago

As soon as I call self.gym.set_dof_state_tensor_indexed, env_ids becomes inaccessible

        env_ids_int32 = env_ids.to(dtype=torch.int32)
        # env_ids_int32 = torch.arange(len(env_ids)).to(self.device).to(dtype=torch.int32)
        print(self.dof_pos.shape, env_ids_int32.shape)
        self.gym.set_dof_state_tensor_indexed(self.sim,
                                              gymtorch.unwrap_tensor(self.dof_state),
                                              gymtorch.unwrap_tensor(env_ids_int32), len(env_ids_int32))
        # print("type env_ids1: ", type(env_ids))
        print("env_ids1: ", env_ids)

Output:

[Error] [carb.gym.plugin] Gym cuda error: an illegal memory access was encountered: ../../../source/plugins/carb/gym/impl/Gym/GymPhysX.cpp: 6219
env_ids1:  Traceback (most recent call last):
  File "scripts/play.py", line 121, in <module>
    play(args)
  File "scripts/play.py", line 58, in play
    ppo_runner, train_cfg = task_registry.make_alg_runner(env=env, name=args.task, args=args, train_cfg=train_cfg)
  File "/home/hello/pgp_eai/legdog/legged_gym/legged_gym/utils/task_registry.py", line 147, in make_alg_runner
    runner = OnPolicyRunner(env, train_cfg_dict, log_dir, device=args.rl_device)
  File "/home/hello/pgp_eai/legdog/rsl_rl/rsl_rl/runners/on_policy_runner.py", line 81, in __init__
    _, _ = self.env.reset()
  File "/home/hello/pgp_eai/legdog/legged_gym/legged_gym/envs/base/base_task.py", line 115, in reset
    self.reset_idx(torch.arange(self.num_envs, device=self.device))
  File "/home/hello/pgp_eai/legdog/legged_gym/legged_gym/envs/anymal_c_flat_play_ball_and_cube/task.py", line 77, in reset_idx
    self._reset_dofs(env_ids)
  File "/home/hello/pgp_eai/legdog/legged_gym/legged_gym/envs/anymal_c_flat_play_ball_and_cube/task.py", line 142, in _reset_dofs
    print("env_ids1: ", env_ids)
  File "/home/hello/anaconda3/envs/eai/lib/python3.8/site-packages/torch/_tensor.py", line 249, in __repr__
    return torch._tensor_str._str(self)
  File "/home/hello/anaconda3/envs/eai/lib/python3.8/site-packages/torch/_tensor_str.py", line 415, in _str
    return _str_intern(self)
  File "/home/hello/anaconda3/envs/eai/lib/python3.8/site-packages/torch/_tensor_str.py", line 390, in _str_intern
    tensor_str = _tensor_str(self, indent)
  File "/home/hello/anaconda3/envs/eai/lib/python3.8/site-packages/torch/_tensor_str.py", line 251, in _tensor_str
    formatter = _Formatter(get_summarized_data(self) if summarize else self)
  File "/home/hello/anaconda3/envs/eai/lib/python3.8/site-packages/torch/_tensor_str.py", line 86, in __init__
    value_str = '{}'.format(value)
  File "/home/hello/anaconda3/envs/eai/lib/python3.8/site-packages/torch/_tensor.py", line 571, in __format__
    return self.item().__format__(format_spec)
RuntimeError: CUDA error: an illegal memory access was encountered
hankpan99 commented 1 year ago

Hi, I met the same bug. In my case, adding 1 URDF to each env is fine, after adding another URDF this error appears. Have you found any solution, thanks!!!

clwmrndl92 commented 1 year ago

If you use multiple actors, when using "set_dof_state_tensor_indexed", it works well if you use only the index of the actor with dof.

For example..

        env_ids_int32 = env_ids.to(dtype=torch.int32)
        self.gym.set_actor_root_state_tensor_indexed(self.sim,
                                                     gymtorch.unwrap_tensor(self.root_state),
                                                     gymtorch.unwrap_tensor(env_ids_int32), len(env_ids_int32))

        human_indices = self.gym_indices["human"][env_ids].to(torch.int32)
        self.gym.set_dof_state_tensor_indexed(self.sim,
                                              gymtorch.unwrap_tensor(self.dof_state),
                                              gymtorch.unwrap_tensor(human_indices), len(human_indices))

See "trifinger" example env code