def compute_reward(self, actions, obs):
    if isinstance(obs, dict):
        obs = obs['state_observation']
    objPos = obs[3:6]
    (rightFinger, leftFinger) = (self.get_site_pos('rightEndEffector'), self.get_site_pos('leftEndEffector'))
    fingerCOM = ((rightFinger + leftFinger) / 2)
    placingGoal = self._state_goal
    graspDist = np.linalg.norm((objPos - fingerCOM))
    placingDist = np.linalg.norm((objPos - placingGoal))

    def reachReward():
        graspRew = (- graspDist)
        if ((np.linalg.norm((objPos[:2] - fingerCOM[:2])) < 0.02) and (fingerCOM[2] < 0.05)):
            self.grasp = True
        return graspRew

    def pickRew():
        if self.pickCompleted:
            return 10
        elif self.grasp:
            if (abs((0.07 - objPos[2])) < 0.1):
                self.pickCompleted = True
            return (1 / (abs((0.07 - objPos[2])) + 0.1))
        else:
            return 0

    def placeRew():
        if self.pickCompleted:
            return np.exp((- placingDist))
        else:
            return 0
    reachReward = reachReward()
    pickReward = pickRew()
    placeReward = placeRew()
    reward = ((reachReward + pickReward) + placeReward)
    return [reward, reachReward, pickReward, placeReward, placingDist]
def compute_reward(self, actions, obs):
    if isinstance(obs, dict):
        obs = obs['state_observation']
    objPos = obs[3:6]
    (rightFinger, leftFinger) = (self.get_site_pos('rightEndEffector'), self.get_site_pos('leftEndEffector'))
    fingerCOM = ((rightFinger + leftFinger) / 2)
    placingGoal = self._state_goal
    graspDist = np.linalg.norm((objPos - fingerCOM))
    placingDist = np.linalg.norm((objPos - placingGoal))

    def reachReward():
        graspRew = (- graspDist)
        if ((np.linalg.norm((objPos[:2] - fingerCOM[:2])) < 0.02) and (fingerCOM[2] < 0.05)):
            self.grasp = True
        return graspRew

    def pickRew():
        if self.pickCompleted:
            return 10
        elif self.grasp:
            if (abs((0.07 - objPos[2])) < 0.1):
                self.pickCompleted = True
            return (1 / (abs((0.07 - objPos[2])) + 0.1))
        else:
            return 0

    def placeRew():
        if self.pickCompleted:
            return np.exp((- placingDist))
        else:
            return 0
    reachReward = reachReward()
    pickReward = pickRew()
    placeReward = placeRew()
    reward = ((reachReward + pickReward) + placeReward)
    return [reward, reachReward, pickReward, placeReward, placingDist]