Skip to content

Commit

Permalink
refactor: refactor making warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaiejj committed May 2, 2024
1 parent bb6e62a commit a7e7e8c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 1 addition & 2 deletions omnisafe/algorithms/algo_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ def _init_checks(self) -> None:
assert self.cfgs.train_cfgs.parallel > 0, 'parallel must be greater than 0!'
assert (
self.env_id in support_envs()
), f"{self.env_id} doesn't exist. Please choose from {support_envs()}.\
\nIf you are using Safe Isaac Gym environments, please install Isaac Gym first."
), f"{self.env_id} doesn't exist. Please choose from {support_envs()}."

def _init_algo(self) -> None:
"""Initialize the algorithm."""
Expand Down
5 changes: 1 addition & 4 deletions omnisafe/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@
from omnisafe.envs.mujoco_env import MujocoEnv
from omnisafe.envs.safety_gymnasium_env import SafetyGymnasiumEnv
from omnisafe.envs.safety_gymnasium_modelbased import SafetyGymnasiumModelBased


with suppress(ImportError):
from omnisafe.envs.safety_isaac_gym_env import SafetyIsaacGymEnv
from omnisafe.envs.safety_isaac_gym_env import SafetyIsaacGymEnv
13 changes: 11 additions & 2 deletions omnisafe/envs/safety_isaac_gym_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@

from omnisafe.envs.core import CMDP, env_register
from omnisafe.typing import DEVICE_CPU
from omnisafe.utils.isaac_gym_utils import make_isaac_gym_env


ISAAC_GYM_AVAILABLE = True
try:
from omnisafe.utils.isaac_gym_utils import make_isaac_gym_env
except ImportError:
ISAAC_GYM_AVAILABLE = False


@env_register
Expand Down Expand Up @@ -64,7 +70,10 @@ def __init__(
super().__init__(env_id)
self._num_envs = num_envs
self._device = torch.device(device)
self._env = make_isaac_gym_env(env_id=env_id, device=device, num_envs=num_envs)
if ISAAC_GYM_AVAILABLE:
self._env = make_isaac_gym_env(env_id=env_id, device=device, num_envs=num_envs)
else:
raise ImportError('Please install Isaac Gym to use Safe Isaac Gym!')
self._action_space = self._env.action_space
self._observation_space = self._env.observation_space
self.need_evaluation = False
Expand Down

0 comments on commit a7e7e8c

Please sign in to comment.