diff --git a/fancy_gym/black_box/black_box_wrapper.py b/fancy_gym/black_box/black_box_wrapper.py index fb2bbbf..df2206a 100644 --- a/fancy_gym/black_box/black_box_wrapper.py +++ b/fancy_gym/black_box/black_box_wrapper.py @@ -50,7 +50,7 @@ class BlackBoxWrapper(gym.ObservationWrapper): self.tracking_controller = tracking_controller # self.time_steps = np.linspace(0, self.duration, self.traj_steps) # self.traj_gen.set_mp_times(self.time_steps) - self.traj_gen.set_duration(np.array([self.duration]), np.array([self.dt])) + self.traj_gen.set_duration(self.duration - self.dt, self.dt) # reward computation self.reward_aggregation = reward_aggregation @@ -78,8 +78,8 @@ class BlackBoxWrapper(gym.ObservationWrapper): self.traj_gen.set_boundary_conditions( bc_time=np.array(0) if not self.do_replanning else np.array([self.current_traj_steps * self.dt]), bc_pos=self.current_pos, bc_vel=self.current_vel) - self.traj_gen.set_duration(None if self.learn_sub_trajectories else np.array([self.duration]), - np.array([self.dt])) + # TODO remove the - self.dt after Bruces fix. + self.traj_gen.set_duration(None if self.learn_sub_trajectories else self.duration - self.dt, self.dt) traj_dict = self.traj_gen.get_trajs(get_pos=True, get_vel=True) trajectory_tensor, velocity_tensor = traj_dict['pos'], traj_dict['vel'] @@ -87,7 +87,7 @@ class BlackBoxWrapper(gym.ObservationWrapper): def _get_traj_gen_action_space(self): """This function can be used to set up an individual space for the parameters of the traj_gen.""" - min_action_bounds, max_action_bounds = self.traj_gen.get_param_bounds() + min_action_bounds, max_action_bounds = self.traj_gen.get_params_bounds().t() action_space = gym.spaces.Box(low=min_action_bounds.numpy(), high=max_action_bounds.numpy(), dtype=self.env.action_space.dtype) return action_space diff --git a/fancy_gym/black_box/factory/basis_generator_factory.py b/fancy_gym/black_box/factory/basis_generator_factory.py index 610ad20..4601953 100644 --- a/fancy_gym/black_box/factory/basis_generator_factory.py +++ b/fancy_gym/black_box/factory/basis_generator_factory.py @@ -1,5 +1,5 @@ -from mp_pytorch import PhaseGenerator, NormalizedRBFBasisGenerator, ZeroStartNormalizedRBFBasisGenerator -from mp_pytorch.basis_gn.rhytmic_basis import RhythmicBasisGenerator +from mp_pytorch.basis_gn import NormalizedRBFBasisGenerator, ZeroPaddingNormalizedRBFBasisGenerator +from mp_pytorch.phase_gn import PhaseGenerator ALL_TYPES = ["rbf", "zero_rbf", "rhythmic"] @@ -9,9 +9,10 @@ def get_basis_generator(basis_generator_type: str, phase_generator: PhaseGenerat if basis_generator_type == "rbf": return NormalizedRBFBasisGenerator(phase_generator, **kwargs) elif basis_generator_type == "zero_rbf": - return ZeroStartNormalizedRBFBasisGenerator(phase_generator, **kwargs) + return ZeroPaddingNormalizedRBFBasisGenerator(phase_generator, **kwargs) elif basis_generator_type == "rhythmic": - return RhythmicBasisGenerator(phase_generator, **kwargs) + raise NotImplementedError() + # return RhythmicBasisGenerator(phase_generator, **kwargs) else: raise ValueError(f"Specified basis generator type {basis_generator_type} not supported, " f"please choose one of {ALL_TYPES}.") diff --git a/fancy_gym/black_box/factory/phase_generator_factory.py b/fancy_gym/black_box/factory/phase_generator_factory.py index ca0dd84..67e17f8 100644 --- a/fancy_gym/black_box/factory/phase_generator_factory.py +++ b/fancy_gym/black_box/factory/phase_generator_factory.py @@ -1,6 +1,7 @@ -from mp_pytorch import LinearPhaseGenerator, ExpDecayPhaseGenerator -from mp_pytorch.phase_gn.rhythmic_phase_generator import RhythmicPhaseGenerator -from mp_pytorch.phase_gn.smooth_phase_generator import SmoothPhaseGenerator +from mp_pytorch.phase_gn import LinearPhaseGenerator, ExpDecayPhaseGenerator + +# from mp_pytorch.phase_gn.rhythmic_phase_generator import RhythmicPhaseGenerator +# from mp_pytorch.phase_gn.smooth_phase_generator import SmoothPhaseGenerator ALL_TYPES = ["linear", "exp", "rhythmic", "smooth"] @@ -12,9 +13,11 @@ def get_phase_generator(phase_generator_type, **kwargs): elif phase_generator_type == "exp": return ExpDecayPhaseGenerator(**kwargs) elif phase_generator_type == "rhythmic": - return RhythmicPhaseGenerator(**kwargs) + raise NotImplementedError() + # return RhythmicPhaseGenerator(**kwargs) elif phase_generator_type == "smooth": - return SmoothPhaseGenerator(**kwargs) + raise NotImplementedError() + # return SmoothPhaseGenerator(**kwargs) else: raise ValueError(f"Specified phase generator type {phase_generator_type} not supported, " f"please choose one of {ALL_TYPES}.") diff --git a/fancy_gym/black_box/factory/trajectory_generator_factory.py b/fancy_gym/black_box/factory/trajectory_generator_factory.py index f7ca6e2..5a36fdd 100644 --- a/fancy_gym/black_box/factory/trajectory_generator_factory.py +++ b/fancy_gym/black_box/factory/trajectory_generator_factory.py @@ -1,7 +1,5 @@ -from mp_pytorch.basis_gn.basis_generator import BasisGenerator -from mp_pytorch.mp.dmp import DMP -from mp_pytorch.mp.idmp import IDMP -from mp_pytorch.mp.promp import ProMP +from mp_pytorch.basis_gn import BasisGenerator +from mp_pytorch.mp import ProDMP, DMP, ProMP ALL_TYPES = ["promp", "dmp", "idmp"] @@ -14,8 +12,10 @@ def get_trajectory_generator( return ProMP(basis_generator, action_dim, **kwargs) elif trajectory_generator_type == "dmp": return DMP(basis_generator, action_dim, **kwargs) - elif trajectory_generator_type == 'idmp': - return IDMP(basis_generator, action_dim, **kwargs) + elif trajectory_generator_type == 'prodmp': + from mp_pytorch.basis_gn import ProDMPBasisGenerator + assert isinstance(basis_generator, ProDMPBasisGenerator) + return ProDMP(basis_generator, action_dim, **kwargs) else: raise ValueError(f"Specified movement primitive type {trajectory_generator_type} not supported, " f"please choose one of {ALL_TYPES}.") diff --git a/fancy_gym/envs/__init__.py b/fancy_gym/envs/__init__.py index 9f0299e..a00570c 100644 --- a/fancy_gym/envs/__init__.py +++ b/fancy_gym/envs/__init__.py @@ -126,7 +126,7 @@ for _dims in [5, 7]: register( id=f'Reacher{_dims}dSparse-v0', entry_point='fancy_gym.envs.mujoco:ReacherEnv', - max_episode_steps=MAX_EPISODE_STEPS_REACHER, + max_episode_steps=200, kwargs={ "sparse": True, 'reward_weight': 200, diff --git a/fancy_gym/utils/make_env_helpers.py b/fancy_gym/utils/make_env_helpers.py index 0f832ae..b0bfe8b 100644 --- a/fancy_gym/utils/make_env_helpers.py +++ b/fancy_gym/utils/make_env_helpers.py @@ -10,15 +10,14 @@ import numpy as np from gym.envs.registration import register, registry try: - from dm_control import suite, manipulation, composer - from dm_control.rl import control + from dm_control import suite, manipulation except ImportError: pass try: import metaworld except Exception: - # catch Exception due to Mujoco-py + # catch Exception as Import error does not catch missing mujoco-py pass import fancy_gym @@ -227,7 +226,7 @@ def make_bb_env_helper(**kwargs): def make_dmc( - env_id: Union[str, composer.Environment, control.Environment], + env_id: str, seed: int = None, visualize_reward: bool = True, time_limit: Union[None, float] = None, @@ -274,7 +273,7 @@ def make_dmc( return env -def make_metaworld(env_id, seed, **kwargs): +def make_metaworld(env_id: str, seed: int, **kwargs): if env_id not in metaworld.ML1.ENV_NAMES: raise ValueError(f'Specified environment "{env_id}" not present in metaworld ML1.') diff --git a/setup.py b/setup.py index 3f67e1a..3d428e2 100644 --- a/setup.py +++ b/setup.py @@ -27,8 +27,7 @@ setup( ], extras_require=extras, install_requires=[ - 'gym>=0.24.0', - 'mujoco==2.2.0', + 'gym[mujoco]>=0.24.0', 'mp_pytorch @ git+https://github.com/ALRhub/MP_PyTorch.git@main' ], packages=[package for package in find_packages() if package.startswith("fancy_gym")],