Skip to content

Commit

Permalink
refactor: enhance making of safe isaac gym (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaiejj authored Apr 30, 2024
1 parent be4a7db commit 0865ff6
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 87 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ci:
default_stages: [commit, push, manual]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-symlinks
- id: destroyed-symlinks
Expand Down Expand Up @@ -45,7 +45,7 @@ repos:
)
- id: double-quote-string-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.285
rev: v0.4.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -54,15 +54,15 @@ repos:
^safety_gymnasium/tasks/safe_isaac_gym/
)
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 24.4.0
hooks:
- id: black-jupyter
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py38-plus] # sync with requires-python
Expand All @@ -71,7 +71,7 @@ repos:
^examples/
)
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -88,7 +88,7 @@ repos:
^docs/conf.py$
)
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies: [".[toml]"]
Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_multi_agent/multi_goal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Agents are mandated to approach and reach the targets that **match their own col
Episode End
-----------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _MultiGoal0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_navigation/button.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Specific Setting
Episode End
------------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _Button0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_navigation/circle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Rewards
Episode End
-----------

- When episode length is greater than 500: ``Trucated = True``.
- When episode length is greater than 500: ``Truncated = True``.

.. _Circle0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_navigation/goal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Rewards
Episode End
-----------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _Goal0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_navigation/push.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Specific Setting
Episode End
-----------

- When episode length is greater than 1000: ``Trucated == True``.
- When episode length is greater than 1000: ``Truncated == True``.

.. _Push0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_vision/building_button.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Specific Setting
Episode End
------------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _BuildingButton0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_vision/building_goal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Rewards
Episode End
-----------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _BuildingGoal0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_vision/building_push.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Specific Setting
Episode End
-----------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _BuildingPush0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_vision/fading_easy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Rewards
Episode End
-----------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _FadingEasy0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_vision/fading_hard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Rewards
Episode End
-----------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _FadingHard0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_vision/formula_one.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Rewards
Episode End
-----------

- When episode length is greater than 1000: ``Trucated = True``.
- When episode length is greater than 1000: ``Truncated = True``.

.. _FormulaOne0:

Expand Down
2 changes: 1 addition & 1 deletion docs/environments/safe_vision/race.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Rewards
Episode End
-----------

- When episode length is greater than 500: ``Trucated = True``.
- When episode length is greater than 500: ``Truncated = True``.
- Upon the agent's arrival at the "Goal": ``goal_achieved = True``.

.. _Race0:
Expand Down
6 changes: 3 additions & 3 deletions safety_gymnasium/bases/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ def build_staged_goal_position(self) -> None:
self.staged_goal.get_next_goal_xy(), # pylint: disable=no-member
)
# Move goal geom to new layout position
self.world_info.world_config_dict['geoms']['staged_goal']['pos'][
:2
] = self.world_info.layout['staged_goal']
self.world_info.world_config_dict['geoms']['staged_goal']['pos'][:2] = (
self.world_info.layout['staged_goal']
)
self._set_goal(self.world_info.layout['staged_goal'], 'staged_goal')
mujoco.mj_forward(self.model, self.data) # pylint: disable=no-member

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
resetDofPosRandomInterval: 0.2
resetDofVelRandomInterval: 0.0

distRewardScale: 50.0
distRewardScale: 50
transition_scale: 0.05
orientation_scale: 0.5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import numpy as np
import torch
from isaacgym import gymapi, gymtorch
from matplotlib.pyplot import axis
import yaml
from isaacgym import gymapi, gymtorch, gymutil

from safety_gymnasium.tasks.safe_isaac_gym.envs.tasks.hand_base.base_task import BaseTask
from safety_gymnasium.tasks.safe_isaac_gym.utils.torch_jit_utils import *
Expand All @@ -20,16 +20,30 @@
class ShadowHandCatchOver2Underarm_Safe_finger(BaseTask):
def __init__(
self,
cfg,
sim_params,
physics_engine,
device_type,
device_id,
headless,
num_envs=None,
cfg=None,
agent_index=[[[0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5]]],
is_multi_agent=False,
):
self.cfg = cfg
yaml_path = (
os.path.abspath(__file__).replace('envs/tasks', 'envs/cfgs').replace('.py', '.yaml')
)
with open(yaml_path) as f:
self.cfg = yaml.load(f, Loader=yaml.FullLoader)
if cfg:
self.cfg.update(cfg)

if num_envs:
self.cfg['env']['numEnvs'] = num_envs

if 'sim' in self.cfg:
gymutil.parse_sim_config(self.cfg['sim'], sim_params)

self.sim_params = sim_params
self.physics_engine = physics_engine
self.agent_index = agent_index
Expand Down Expand Up @@ -743,9 +757,9 @@ def compute_full_state(self, asymm_obs=False):
)

fingertip_obs_start = 72 # 168 = 157 + 11
self.obs_buf[
:, fingertip_obs_start : fingertip_obs_start + num_ft_states
] = self.fingertip_state.reshape(self.num_envs, num_ft_states)
self.obs_buf[:, fingertip_obs_start : fingertip_obs_start + num_ft_states] = (
self.fingertip_state.reshape(self.num_envs, num_ft_states)
)
self.obs_buf[
:,
fingertip_obs_start
Expand Down Expand Up @@ -775,12 +789,12 @@ def compute_full_state(self, asymm_obs=False):

# another_hand
another_hand_start = action_obs_start + 26
self.obs_buf[
:, another_hand_start : self.num_shadow_hand_dofs + another_hand_start
] = unscale(
self.shadow_hand_another_dof_pos,
self.shadow_hand_dof_lower_limits,
self.shadow_hand_dof_upper_limits,
self.obs_buf[:, another_hand_start : self.num_shadow_hand_dofs + another_hand_start] = (
unscale(
self.shadow_hand_another_dof_pos,
self.shadow_hand_dof_lower_limits,
self.shadow_hand_dof_upper_limits,
)
)
self.obs_buf[
:,
Expand Down Expand Up @@ -814,9 +828,9 @@ def compute_full_state(self, asymm_obs=False):
)

hand_another_pose_start = fingertip_another_obs_start + 95
self.obs_buf[
:, hand_another_pose_start : hand_another_pose_start + 3
] = self.hand_positions[self.another_hand_indices, :]
self.obs_buf[:, hand_another_pose_start : hand_another_pose_start + 3] = (
self.hand_positions[self.another_hand_indices, :]
)
self.obs_buf[:, hand_another_pose_start + 3 : hand_another_pose_start + 4] = get_euler_xyz(
self.hand_orientations[self.another_hand_indices, :]
)[0].unsqueeze(-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import numpy as np
import torch
from isaacgym import gymapi, gymtorch
from matplotlib.pyplot import axis
import yaml
from isaacgym import gymapi, gymtorch, gymutil

from safety_gymnasium.tasks.safe_isaac_gym.envs.tasks.hand_base.base_task import BaseTask
from safety_gymnasium.tasks.safe_isaac_gym.utils.torch_jit_utils import *
Expand All @@ -20,16 +20,30 @@
class ShadowHandCatchOver2Underarm_Safe_joint(BaseTask):
def __init__(
self,
cfg,
sim_params,
physics_engine,
device_type,
device_id,
headless,
num_envs=None,
cfg=None,
agent_index=[[[0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5]]],
is_multi_agent=False,
):
self.cfg = cfg
yaml_path = (
os.path.abspath(__file__).replace('envs/tasks', 'envs/cfgs').replace('.py', '.yaml')
)
with open(yaml_path) as f:
self.cfg = yaml.load(f, Loader=yaml.FullLoader)
if cfg:
self.cfg.update(cfg)

if num_envs:
self.cfg['env']['numEnvs'] = num_envs

if 'sim' in self.cfg:
gymutil.parse_sim_config(self.cfg['sim'], sim_params)

self.sim_params = sim_params
self.physics_engine = physics_engine
self.agent_index = agent_index
Expand Down Expand Up @@ -731,9 +745,9 @@ def compute_full_state(self, asymm_obs=False):
)

fingertip_obs_start = 72 # 168 = 157 + 11
self.obs_buf[
:, fingertip_obs_start : fingertip_obs_start + num_ft_states
] = self.fingertip_state.reshape(self.num_envs, num_ft_states)
self.obs_buf[:, fingertip_obs_start : fingertip_obs_start + num_ft_states] = (
self.fingertip_state.reshape(self.num_envs, num_ft_states)
)
self.obs_buf[
:,
fingertip_obs_start
Expand Down Expand Up @@ -763,12 +777,12 @@ def compute_full_state(self, asymm_obs=False):

# another_hand
another_hand_start = action_obs_start + 26
self.obs_buf[
:, another_hand_start : self.num_shadow_hand_dofs + another_hand_start
] = unscale(
self.shadow_hand_another_dof_pos,
self.shadow_hand_dof_lower_limits,
self.shadow_hand_dof_upper_limits,
self.obs_buf[:, another_hand_start : self.num_shadow_hand_dofs + another_hand_start] = (
unscale(
self.shadow_hand_another_dof_pos,
self.shadow_hand_dof_lower_limits,
self.shadow_hand_dof_upper_limits,
)
)
self.obs_buf[
:,
Expand Down Expand Up @@ -802,9 +816,9 @@ def compute_full_state(self, asymm_obs=False):
)

hand_another_pose_start = fingertip_another_obs_start + 95
self.obs_buf[
:, hand_another_pose_start : hand_another_pose_start + 3
] = self.hand_positions[self.another_hand_indices, :]
self.obs_buf[:, hand_another_pose_start : hand_another_pose_start + 3] = (
self.hand_positions[self.another_hand_indices, :]
)
self.obs_buf[:, hand_another_pose_start + 3 : hand_another_pose_start + 4] = get_euler_xyz(
self.hand_orientations[self.another_hand_indices, :]
)[0].unsqueeze(-1)
Expand Down
Loading

0 comments on commit 0865ff6

Please sign in to comment.