From 5dd3f55cc11b910f1a733ed9bba99d0875993eb3 Mon Sep 17 00:00:00 2001 From: romesco Date: Fri, 12 May 2023 20:05:28 -0700 Subject: [PATCH] Update random_policy.py to sample actions on GPU --- omniisaacgymenvs/scripts/random_policy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/omniisaacgymenvs/scripts/random_policy.py b/omniisaacgymenvs/scripts/random_policy.py index 7c06d88f..26debd3c 100644 --- a/omniisaacgymenvs/scripts/random_policy.py +++ b/omniisaacgymenvs/scripts/random_policy.py @@ -59,7 +59,12 @@ def parse_hydra_configs(cfg: DictConfig): if env._world.is_playing(): if env._world.current_time_step_index == 0: env._world.reset(soft=True) - actions = torch.tensor(np.array([env.action_space.sample() for _ in range(env.num_envs)]), device=task.rl_device) + + # get upper and lower bounds of action space, sample actions randomly on this interval + action_high = env.action_space.high[0] + action_low = env.action_space.low[0] + actions = (action_high - action_low) * torch.rand(env.num_envs, env.action_space.shape[0]), device=task.rl_device) - action_high + env._task.pre_physics_step(actions) env._world.step(render=render) env.sim_frame_count += 1