Python gym.utils.EzPickle() Examples

The following are 30 code examples of gym.utils.EzPickle(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gym.utils , or try the search function .
Example #1
Source File: hopper_random_dynamics.py    From rl_swiss with MIT License 6 votes vote down vote up
def __init__(self):
        self.multipliers = {
            'body_mass_multiplier': np.ones(5),
            'body_inertia_multiplier': np.ones((5,3)),
            'dof_damping_multiplier': np.ones(6),
            'geom_friction_multiplier': np.ones((5,3))
        }
        MetaMujocoEnv.__init__(self, 'hopper.xml', 4)
        utils.EzPickle.__init__(self)

        self.original_params = {
            'body_mass': self.model.body_mass.copy(),
            'body_inertia': self.model.body_inertia.copy(),
            'dof_damping': self.model.dof_damping.copy(),
            'geom_friction': self.model.geom_friction.copy()
        } 
Example #2
Source File: relocate_v0.py    From mj_envs with Apache License 2.0 6 votes vote down vote up
def __init__(self):
        self.target_obj_sid = 0
        self.S_grasp_sid = 0
        self.obj_bid = 0
        curr_dir = os.path.dirname(os.path.abspath(__file__))
        mujoco_env.MujocoEnv.__init__(self, curr_dir+'/assets/DAPG_relocate.xml', 5)
        
        # change actuator sensitivity
        self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id('A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0')+1,:3] = np.array([10, 0, 0])
        self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id('A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0')+1,:3] = np.array([1, 0, 0])
        self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id('A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0')+1,:3] = np.array([0, -10, 0])
        self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id('A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0')+1,:3] = np.array([0, -1, 0])

        self.target_obj_sid = self.sim.model.site_name2id("target")
        self.S_grasp_sid = self.sim.model.site_name2id('S_grasp')
        self.obj_bid = self.sim.model.body_name2id('Object')
        utils.EzPickle.__init__(self)
        self.act_mid = np.mean(self.model.actuator_ctrlrange, axis=1)
        self.act_rng = 0.5*(self.model.actuator_ctrlrange[:,1]-self.model.actuator_ctrlrange[:,0]) 
Example #3
Source File: few_shot_fetch_env.py    From rl_swiss with MIT License 6 votes vote down vote up
def __init__(self, reward_type='sparse', terminate_on_success=False):
        initial_qpos = {
            'robot0:slide0': 0.405,
            'robot0:slide1': 0.48,
            'robot0:slide2': 0.0,
            'object0:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
            'object1:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
        }

        FewShotFetchEnv.__init__(
            self, FEW_SHOT_ENV_XML_PATH, has_object=True, block_gripper=False, n_substeps=20,
            gripper_extra_height=0.2, target_in_the_air=True, target_offset=0.0,
            obj_range=0.15, target_range=0.05, distance_threshold=0.05,
            initial_qpos=initial_qpos, reward_type=reward_type, goal_high_prob=1.0,
            min_goal_extra_height=0.15, max_goal_extra_height=0.2,
            min_dist_between_objs=0.1, same_color_radius=0.5,
            terminate_on_success=terminate_on_success
        )
        gym_utils.EzPickle.__init__(self)
        self._max_episode_steps = 65 
Example #4
Source File: old_version_of_color_few_shot_fetch_env.py    From rl_swiss with MIT License 6 votes vote down vote up
def __init__(self, reward_type='sparse', terminate_on_success=False):
        initial_qpos = {
            'robot0:slide0': 0.405,
            'robot0:slide1': 0.48,
            'robot0:slide2': 0.0,
            'object0:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
            'object1:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
        }

        FewShotFetchEnv.__init__(
            self, FEW_SHOT_ENV_XML_PATH, has_object=True, block_gripper=False, n_substeps=20,
            gripper_extra_height=0.2, target_in_the_air=True, target_offset=0.0,
            obj_range=0.15, target_range=0.05, distance_threshold=0.05,
            initial_qpos=initial_qpos, reward_type=reward_type, goal_high_prob=1.0,
            min_goal_extra_height=0.15, max_goal_extra_height=0.2,
            min_dist_between_objs=0.1, same_color_radius=0.3,
            terminate_on_success=terminate_on_success
        )
        gym_utils.EzPickle.__init__(self)
        self._max_episode_steps = 65 
Example #5
Source File: hammer_v0.py    From mj_envs with Apache License 2.0 6 votes vote down vote up
def __init__(self):
        self.target_obj_sid = -1
        self.S_grasp_sid = -1
        self.obj_bid = -1
        self.tool_sid = -1
        self.goal_sid = -1
        curr_dir = os.path.dirname(os.path.abspath(__file__))
        mujoco_env.MujocoEnv.__init__(self, curr_dir+'/assets/DAPG_hammer.xml', 5)
        utils.EzPickle.__init__(self)

        # change actuator sensitivity
        self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id('A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0')+1,:3] = np.array([10, 0, 0])
        self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id('A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0')+1,:3] = np.array([1, 0, 0])
        self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id('A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0')+1,:3] = np.array([0, -10, 0])
        self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id('A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0')+1,:3] = np.array([0, -1, 0])
        
        self.target_obj_sid = self.sim.model.site_name2id('S_target')
        self.S_grasp_sid = self.sim.model.site_name2id('S_grasp')
        self.obj_bid = self.sim.model.body_name2id('Object')
        self.tool_sid = self.sim.model.site_name2id('tool')
        self.goal_sid = self.sim.model.site_name2id('nail_goal')
        self.act_mid = np.mean(self.model.actuator_ctrlrange, axis=1)
        self.act_rng = 0.5 * (self.model.actuator_ctrlrange[:, 1] - self.model.actuator_ctrlrange[:, 0]) 
Example #6
Source File: door_v0.py    From mj_envs with Apache License 2.0 6 votes vote down vote up
def __init__(self):
        self.door_hinge_did = 0
        self.door_bid = 0
        self.grasp_sid = 0
        self.handle_sid = 0
        curr_dir = os.path.dirname(os.path.abspath(__file__))
        mujoco_env.MujocoEnv.__init__(self, curr_dir+'/assets/DAPG_door.xml', 5)
        
        # change actuator sensitivity
        self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id('A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0')+1,:3] = np.array([10, 0, 0])
        self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id('A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0')+1,:3] = np.array([1, 0, 0])
        self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id('A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0')+1,:3] = np.array([0, -10, 0])
        self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id('A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0')+1,:3] = np.array([0, -1, 0])

        utils.EzPickle.__init__(self)
        ob = self.reset_model()
        self.act_mid = np.mean(self.model.actuator_ctrlrange, axis=1)
        self.act_rng = 0.5*(self.model.actuator_ctrlrange[:,1]-self.model.actuator_ctrlrange[:,0])
        self.door_hinge_did = self.model.jnt_dofadr[self.model.joint_name2id('door_hinge')]
        self.grasp_sid = self.model.site_name2id('S_grasp')
        self.handle_sid = self.model.site_name2id('S_handle')
        self.door_bid = self.model.body_name2id('frame') 
Example #7
Source File: reacher_env.py    From me-trpo with MIT License 6 votes vote down vote up
def __init__(self):
        utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, 'reacher.xml', 2)

    # def _step(self, a):
    #     # x = self._get_obs()[None]
    #     # assert np.allclose(self.get_body_com("fingertip")[:2], get_fingertips(x)),\
    #     # str(self.get_body_com("fingertip")) + " "+ str(get_fingertips(x))
    #     vec = self.get_body_com("fingertip")-self.get_body_com("target")
    #     reward_dist = - np.linalg.norm(vec[:2])
    #     reward_ctrl = - np.square(a).sum()*0.01
    #     reward = reward_dist + reward_ctrl
    #     self.do_simulation(a, self.frame_skip)
    #     ob = self._get_obs()
    #     done = False
    #     return ob, reward, done, dict(reward_dist=reward_dist, reward_ctrl=reward_ctrl) 
Example #8
Source File: pick_and_place.py    From DRL_DeliveryDuel with MIT License 6 votes vote down vote up
def __init__(self, reward_type='sparse'):
        initial_qpos = {
            'robot0:slide0': 0.405,
            'robot0:slide1': 0.48,
            'robot0:slide2': 0.0,
            'table0:slide0': 1.05,
            'table0:slide1': 0.4,
            'table0:slide2': 0.0,
            'object0:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
        }
        fetch_env.FetchEnv.__init__(
            self, 'fetch/pick_and_place.xml', has_object=True, block_gripper=False, n_substeps=20,
            gripper_extra_height=0.2, target_in_the_air=True, target_offset=0.0,
            obj_range=0.15, target_range=0.15, distance_threshold=0.05,
            initial_qpos=initial_qpos, reward_type=reward_type)
        utils.EzPickle.__init__(self) 
Example #9
Source File: push.py    From DRL_DeliveryDuel with MIT License 6 votes vote down vote up
def __init__(self, reward_type='sparse'):
        initial_qpos = {
            'robot0:slide0': 0.405,
            'robot0:slide1': 0.48,
            'robot0:slide2': 0.0,
            'table0:slide0': 1.05,
            'table0:slide1': 0.4,
            'table0:slide2': 0.0,
            'object0:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
        }
        fetch_env.FetchEnv.__init__(
            self, 'fetch/push.xml', has_object=True, block_gripper=True, n_substeps=20,
            gripper_extra_height=0.0, target_in_the_air=False, target_offset=0.0,
            obj_range=0.15, target_range=0.15, distance_threshold=0.05,
            initial_qpos=initial_qpos, reward_type=reward_type)
        utils.EzPickle.__init__(self) 
Example #10
Source File: few_shot_reach_env.py    From rl_swiss with MIT License 6 votes vote down vote up
def __init__(self, reward_type='sparse'):
        initial_qpos = {
            'robot0:slide0': 0.405,
            'robot0:slide1': 0.48,
            'robot0:slide2': 0.0,
            'object0:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
            'object1:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
        }

        FewShotReachEnv.__init__(
            self, FEW_SHOT_ENV_XML_PATH, has_object=True, block_gripper=False, n_substeps=20,
            gripper_extra_height=0.2, target_in_the_air=True, target_offset=0.0,
            obj_range=0.15, target_range=0.0, distance_threshold=0.05,
            initial_qpos=initial_qpos, reward_type=reward_type, goal_high_prob=1.0,
            min_goal_extra_height=0.05, max_goal_extra_height=0.05,
            min_dist_between_objs=0.1, same_color_radius=0.3
        )
        gym_utils.EzPickle.__init__(self)
        self._max_episode_steps = 30 
Example #11
Source File: state_matching_ant_env.py    From rl_swiss with MIT License 6 votes vote down vote up
def __init__(self, episode_len=499):
        # # 1 x 1 x 8 x 2
        # self.valid_targets = np.array(
        #     [[[
        #         [8.0, 0.0],
        #         [0.0, 8.0],
        #         [-8.0, 0.0],
        #         [0.0, -8.0],
        #     ]]]
        # )

        self.timestep = 0.0
        self.episode_len = episode_len
        # self.init_xy = init_pos.copy()

        xml_path = os.path.join(os.path.dirname(__file__), "assets", 'low_gear_ratio_ant.xml')
        # xml_path = os.path.join(os.path.dirname(__file__), "assets", 's_maze.xml')
        MujocoEnv.__init__(self, xml_path, 5)
        utils.EzPickle.__init__(self) 
Example #12
Source File: point_maze_env.py    From imitation with MIT License 6 votes vote down vote up
def __init__(
        self,
        direction=1,
        maze_length=0.6,
        sparse_reward=False,
        no_reward=False,
        include_vel=False,
        episode_length=100,
    ):
        utils.EzPickle.__init__(self)
        self.sparse_reward = sparse_reward
        self.no_reward = no_reward
        self.include_vel = include_vel
        self.max_episode_length = episode_length
        self.direction = direction
        self.length = maze_length

        self.episode_length = 0

        model = point_mass_maze(direction=self.direction, length=self.length)
        with model.asfile() as f:
            mujoco_env.MujocoEnv.__init__(self, f.name, 5) 
Example #13
Source File: ant_multi_target.py    From rl_swiss with MIT License 5 votes vote down vote up
def __init__(self, use_rel_pos_obs=False, terminate_near_target=False):
        self.terminate_near_target = terminate_near_target
        self.terminate_radius = 0.5
        self.use_rel_pos_obs = use_rel_pos_obs
        # 1 x 1 x 8 x 2
        self.valid_targets = np.array(
            [[[
                # [2.0, 0.0],
                # # [1.41, 1.41],
                # [0.0, 2.0],
                # # [-1.41, 1.41],
                # [-2.0, 0.0],
                # # [-1.41, -1.41],
                # [0.0, -2.0],
                # # [1.41, -1.41]

                [4.0, 0.0],
                [0.0, 4.0],
                [-4.0, 0.0],
                [0.0, -4.0],
            ]]]
        )

        xml_path = os.path.join(os.path.dirname(__file__), "assets", 'low_gear_ratio_ant.xml')
        MujocoEnv.__init__(self, xml_path, 5)
        utils.EzPickle.__init__(self) 
Example #14
Source File: ant_env.py    From inverse_rl with MIT License 5 votes vote down vote up
def __init__(self, max_timesteps=1000, disabled=False, gear=150):
        #mujoco_env.MujocoEnv.__init__(self, 'ant.xml', 5)
        utils.EzPickle.__init__(self)
        self.timesteps = 0
        self.max_timesteps=max_timesteps

        if disabled:
            model = angry_ant_crippled(gear=gear)
        else:
            model = ant_env(gear=gear)
        with model.asfile() as f:
            mujoco_env.MujocoEnv.__init__(self, f.name, 5) 
Example #15
Source File: atari_env.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self, game='pong', obs_type='ram', frameskip=(2, 5), repeat_action_probability=0.):
        """Frameskip should be either a tuple (indicating a random range to
        choose from, with the top value exclude), or an int."""

        utils.EzPickle.__init__(self, game, obs_type, frameskip, repeat_action_probability)
        assert obs_type in ('ram', 'image')

        self.game_path = atari_py.get_game_path(game)
        if not os.path.exists(self.game_path):
            raise IOError('You asked for game %s but path %s does not exist'%(game, self.game_path))
        self._obs_type = obs_type
        self.frameskip = frameskip
        self.ale = atari_py.ALEInterface()
        self.viewer = None

        # Tune (or disable) ALE's action repeat:
        # https://github.com/openai/gym/issues/349
        assert isinstance(repeat_action_probability, (float, int)), "Invalid repeat_action_probability: {!r}".format(repeat_action_probability)
        self.ale.setFloat('repeat_action_probability'.encode('utf-8'), repeat_action_probability)

        self.seed()

        self._action_set = self.ale.getMinimalActionSet()
        self.action_space = spaces.Discrete(len(self._action_set))

        (screen_width,screen_height) = self.ale.getScreenDims()
        if self._obs_type == 'ram':
            self.observation_space = spaces.Box(low=0, high=255, dtype=np.uint8, shape=(128,))
        elif self._obs_type == 'image':
            self.observation_space = spaces.Box(low=0, high=255, shape=(screen_height, screen_width, 3), dtype=np.uint8)
        else:
            raise error.Error('Unrecognized observation type: {}'.format(self._obs_type)) 
Example #16
Source File: reacher.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, 'reacher.xml', 2) 
Example #17
Source File: ant_linear_classification.py    From rl_swiss with MIT License 5 votes vote down vote up
def __init__(self, use_relative_pos=False):
        self.ACCEPT_RADIUS = 0.5
        self.true_label = 0
        self.task_hyperplane = np.ones(4) / 2.0
        self.first_sample = np.random.uniform(size=4)
        self.second_sample = np.random.uniform(size=4)
        self.targets = np.array(
            [
                [1.41, 1.41],
                [-1.41, 1.41]
            ]
        )
        self.use_relative_pos = use_relative_pos
        MetaMujocoEnv.__init__(self, 'low_gear_ratio_ant.xml', 5)
        utils.EzPickle.__init__(self) 
Example #18
Source File: ant_rand_direc_2d.py    From rl_swiss with MIT License 5 votes vote down vote up
def __init__(self):
        self.goal_direction = np.array([1.0, 0.0])
        # MetaMujocoEnv.__init__(self, 'ant.xml', 5)
        MetaMujocoEnv.__init__(self, 'low_gear_ratio_ant.xml', 5)
        # MetaMujocoEnv.__init__(self, 'low_gear_ratio_ant.xml', 5)
        utils.EzPickle.__init__(self) 
Example #19
Source File: humanoid.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, 'humanoid.xml', 5)
        utils.EzPickle.__init__(self) 
Example #20
Source File: ant_rand_goal_in_8_star_env.py    From rl_swiss with MIT License 5 votes vote down vote up
def __init__(self):
        self.goal_pos = np.array([14.1, 14.1])
        self.target_distance = 25.0

        MetaMujocoEnv.__init__(self, 'low_gear_ratio_ant_8_star.xml', 5)
        utils.EzPickle.__init__(self) 
Example #21
Source File: walker_env.py    From me-trpo with MIT License 5 votes vote down vote up
def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, "walker2d.xml", 4)
        utils.EzPickle.__init__(self) 
Example #22
Source File: thrower.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        utils.EzPickle.__init__(self)
        self._ball_hit_ground = False
        self._ball_hit_location = None
        mujoco_env.MujocoEnv.__init__(self, 'thrower.xml', 5) 
Example #23
Source File: striker.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        utils.EzPickle.__init__(self)
        self._striked = False
        self._min_strike_dist = np.inf
        self.strike_threshold = 0.1
        mujoco_env.MujocoEnv.__init__(self, 'striker.xml', 5) 
Example #24
Source File: swimmer.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, 'swimmer.xml', 4)
        utils.EzPickle.__init__(self) 
Example #25
Source File: walker2d.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, "walker2d.xml", 4)
        utils.EzPickle.__init__(self) 
Example #26
Source File: pusher.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, 'pusher.xml', 5) 
Example #27
Source File: ant.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, 'ant.xml', 5)
        utils.EzPickle.__init__(self) 
Example #28
Source File: humanoidstandup.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, 'humanoidstandup.xml', 5)
        utils.EzPickle.__init__(self) 
Example #29
Source File: half_cheetah.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, 'half_cheetah.xml', 5)
        utils.EzPickle.__init__(self) 
Example #30
Source File: inverted_double_pendulum.py    From ia-course with MIT License 5 votes vote down vote up
def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, 'inverted_double_pendulum.xml', 5)
        utils.EzPickle.__init__(self)