diff --git a/alr_envs/open_ai/__init__.py b/alr_envs/open_ai/__init__.py index 04610fa..601e3b1 100644 --- a/alr_envs/open_ai/__init__.py +++ b/alr_envs/open_ai/__init__.py @@ -1,85 +1,48 @@ from gym import register -from gym.wrappers import FlattenObservation +from copy import deepcopy -from . import classic_control, mujoco, robotics +from . import mujoco +from .deprecated_needs_gym_robotics import robotics ALL_GYM_MOTION_PRIMITIVE_ENVIRONMENTS = {"DMP": [], "ProMP": []} -# Short Continuous Mountain Car -register( - id="MountainCarContinuous-v1", - entry_point="gym.envs.classic_control:Continuous_MountainCarEnv", - max_episode_steps=100, - reward_threshold=90.0, -) - -# Open AI -# Classic Control -register( - id='ContinuousMountainCarProMP-v1', - entry_point='alr_envs.utils.make_env_helpers:make_promp_env_helper', - kwargs={ - "name": "alr_envs:MountainCarContinuous-v1", - "wrappers": [classic_control.continuous_mountain_car.MPWrapper], - "traj_gen_kwargs": { - "num_dof": 1, - "num_basis": 4, - "duration": 2, - "post_traj_time": 0, - "zero_start": True, - "policy_type": "motor", - "policy_kwargs": { - "p_gains": 1., - "d_gains": 1. - } - } +DEFAULT_BB_DICT_ProMP = { + "name": 'EnvName', + "wrappers": [], + "trajectory_generator_kwargs": { + 'trajectory_generator_type': 'promp' + }, + "phase_generator_kwargs": { + 'phase_generator_type': 'linear' + }, + "controller_kwargs": { + 'controller_type': 'motor', + "p_gains": 1.0, + "d_gains": 0.1, + }, + "basis_generator_kwargs": { + 'basis_generator_type': 'zero_rbf', + 'num_basis': 5, + 'num_basis_zero_start': 1 } -) -ALL_GYM_MOTION_PRIMITIVE_ENVIRONMENTS["ProMP"].append("ContinuousMountainCarProMP-v1") +} -register( - id='ContinuousMountainCarProMP-v0', - entry_point='alr_envs.utils.make_env_helpers:make_promp_env_helper', - kwargs={ - "name": "gym.envs.classic_control:MountainCarContinuous-v0", - "wrappers": [classic_control.continuous_mountain_car.MPWrapper], - "traj_gen_kwargs": { - "num_dof": 1, - "num_basis": 4, - "duration": 19.98, - "post_traj_time": 0, - "zero_start": True, - "policy_type": "motor", - "policy_kwargs": { - "p_gains": 1., - "d_gains": 1. - } - } - } -) -ALL_GYM_MOTION_PRIMITIVE_ENVIRONMENTS["ProMP"].append("ContinuousMountainCarProMP-v0") +kwargs_dict_reacher_promp = deepcopy(DEFAULT_BB_DICT_ProMP) +kwargs_dict_reacher_promp['controller_kwargs']['p_gains'] = 0.6 +kwargs_dict_reacher_promp['controller_kwargs']['d_gains'] = 0.075 +kwargs_dict_reacher_promp['basis_generator_kwargs']['num_basis'] = 6 +kwargs_dict_reacher_promp['name'] = "Reacher-v2" +kwargs_dict_reacher_promp['wrappers'].append(mujoco.reacher_v2.MPWrapper) register( - id='ReacherProMP-v2', - entry_point='alr_envs.utils.make_env_helpers:make_promp_env_helper', - kwargs={ - "name": "gym.envs.mujoco:Reacher-v2", - "wrappers": [mujoco.reacher_v2.MPWrapper], - "traj_gen_kwargs": { - "num_dof": 2, - "num_basis": 6, - "duration": 1, - "post_traj_time": 0, - "zero_start": True, - "policy_type": "motor", - "policy_kwargs": { - "p_gains": .6, - "d_gains": .075 - } - } - } + id='Reacher2dProMP-v2', + entry_point='alr_envs.utils.make_env_helpers:make_bb_env_helper', + kwargs=kwargs_dict_reacher_promp ) ALL_GYM_MOTION_PRIMITIVE_ENVIRONMENTS["ProMP"].append("ReacherProMP-v2") +""" +The Fetch environments are not supported by gym anymore. A new repository (gym_robotics) is supporting the environments. +However, the usage and so on needs to be checked register( id='FetchSlideDenseProMP-v1', @@ -152,3 +115,4 @@ register( } ) ALL_GYM_MOTION_PRIMITIVE_ENVIRONMENTS["ProMP"].append("FetchReachProMP-v1") +""" diff --git a/alr_envs/open_ai/classic_control/__init__.py b/alr_envs/open_ai/classic_control/__init__.py deleted file mode 100644 index b998494..0000000 --- a/alr_envs/open_ai/classic_control/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import continuous_mountain_car \ No newline at end of file diff --git a/alr_envs/open_ai/classic_control/continuous_mountain_car/mp_wrapper.py b/alr_envs/open_ai/classic_control/continuous_mountain_car/mp_wrapper.py deleted file mode 100644 index db9f1f2..0000000 --- a/alr_envs/open_ai/classic_control/continuous_mountain_car/mp_wrapper.py +++ /dev/null @@ -1,23 +0,0 @@ -from typing import Union - -import numpy as np - -from alr_envs.black_box.raw_interface_wrapper import RawInterfaceWrapper - - -class MPWrapper(RawInterfaceWrapper): - @property - def current_vel(self) -> Union[float, int, np.ndarray]: - return np.array([self.state[1]]) - - @property - def current_pos(self) -> Union[float, int, np.ndarray]: - return np.array([self.state[0]]) - - @property - def goal_pos(self): - raise ValueError("Goal position is not available and has to be learnt based on the environment.") - - @property - def dt(self) -> Union[float, int]: - return 0.02 \ No newline at end of file diff --git a/alr_envs/open_ai/deprecated_needs_gym_robotics/__init__.py b/alr_envs/open_ai/deprecated_needs_gym_robotics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/alr_envs/open_ai/robotics/__init__.py b/alr_envs/open_ai/deprecated_needs_gym_robotics/robotics/__init__.py similarity index 100% rename from alr_envs/open_ai/robotics/__init__.py rename to alr_envs/open_ai/deprecated_needs_gym_robotics/robotics/__init__.py diff --git a/alr_envs/open_ai/classic_control/continuous_mountain_car/__init__.py b/alr_envs/open_ai/deprecated_needs_gym_robotics/robotics/fetch/__init__.py similarity index 100% rename from alr_envs/open_ai/classic_control/continuous_mountain_car/__init__.py rename to alr_envs/open_ai/deprecated_needs_gym_robotics/robotics/fetch/__init__.py diff --git a/alr_envs/open_ai/robotics/fetch/mp_wrapper.py b/alr_envs/open_ai/deprecated_needs_gym_robotics/robotics/fetch/mp_wrapper.py similarity index 100% rename from alr_envs/open_ai/robotics/fetch/mp_wrapper.py rename to alr_envs/open_ai/deprecated_needs_gym_robotics/robotics/fetch/mp_wrapper.py diff --git a/alr_envs/open_ai/mujoco/reacher_v2/mp_wrapper.py b/alr_envs/open_ai/mujoco/reacher_v2/mp_wrapper.py index 1e02f10..5833f6c 100644 --- a/alr_envs/open_ai/mujoco/reacher_v2/mp_wrapper.py +++ b/alr_envs/open_ai/mujoco/reacher_v2/mp_wrapper.py @@ -14,3 +14,13 @@ class MPWrapper(RawInterfaceWrapper): @property def current_pos(self) -> Union[float, int, np.ndarray]: return self.sim.data.qpos[:2] + + @property + def context_mask(self): + return np.concatenate([ + [False] * 2, # cos of two links + [False] * 2, # sin of two links + [True] * 2, # goal position + [False] * 2, # angular velocity + [False] * 3, # goal distance + ]) diff --git a/alr_envs/open_ai/robotics/fetch/__init__.py b/alr_envs/open_ai/robotics/fetch/__init__.py deleted file mode 100644 index 989b5a9..0000000 --- a/alr_envs/open_ai/robotics/fetch/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .mp_wrapper import MPWrapper \ No newline at end of file