ravens/environment.py
def step(self, act=None):
        """Execute action with specified primitive.

        For each episode (training, loading, etc.), this is normally called the first
        time from `env.reset()` above, with NO action, and returns an EMPTY observation.
        Then, it's called a SECOND time with an action that lacks a primitive (set to
        None, even though the key exists). But, this method will return an actual image
        observation that we pass to the policy. Finally, subsequent calls will have
        proper actions.

        (Sept 08) Added graceful exit functionality. This will let the code terminate
        early but with task.done=False as we didn't actually 'finish' -- just failed.
        Should use task.done=True to indicate any form of 'successful' dones (hitting
        time limit doesn't count).

        (Oct 09) Clarify documentation for the confusing first time step. I now see
        with ground truth agents, there is no 'second action lacking a primitive',
        because ground truth agents don't need images (see their `act` method).
        """
        if act and act['primitive']:
            success = self.primitives[act['primitive']](**act['params'])

            # Exit early if action failed. Daniel: adding exit_gracefully.
            if (not success) or self.task.exit_gracefully:
                _, reward_extras = self.task.reward()
                info = self.info
                reward_extras['task.done'] = False

                # Means we hit irrecoverable action, exit now (reset to False!!).
                if self.task.exit_gracefully:
                    reward_extras['exit_gracefully'] = True
                    self.task.exit_gracefully = False  # important !!!

                # For consistency?
                if isinstance(self.task, tasks.names['cloth-flat-notarget']):
                    info['sampled_zone_pose'] = self.task.zone_pose
                elif isinstance(self.task, tasks.names['bag-color-goal']):
                    info['bag_base_pos'] = self.task.bag_base_pos[0]
                    info['bag_base_orn'] = self.task.bag_base_orn[0]
                    info['bag_target_color'] = self.task.bag_colors[0]

                info['extras'] = reward_extras
                return {}, 0, True, info

        # Wait for objects to settle, with a hard exit for bag tasks.
        start_t = time.time()
        while not self.is_static():
            if self.is_bag_env() and (time.time() - start_t > 2.0):
                break
            time.sleep(0.001)

        # Compute task rewards.
        reward, reward_extras = self.task.reward()
        done = self.task.done()

        # Pass ground truth robot state as info.
        info = self.info

        # Daniel: fine-grained info about rewards (since it's nuanced for some tasks).
        # If we hit time limit, `task.done` will check if we succeeded on last action.
        reward_extras['task.done'] = done
        info['extras'] = reward_extras
        if isinstance(self.task, tasks.names['cloth-flat-notarget']):
            info['sampled_zone_pose'] = self.task.zone_pose
        elif isinstance(self.task, tasks.names['bag-color-goal']):
            info['bag_base_pos'] = self.task.bag_base_pos[0]
            info['bag_base_orn'] = self.task.bag_base_orn[0]
            info['bag_target_color'] = self.task.bag_colors[0]

        # Get camera observations per specified config.
        obs = {}
        if act and 'camera_config' in act:
            obs['color'], obs['depth'] = [], []
            for config in act['camera_config']:
                color, depth, _ = self.render(config)
                obs['color'].append(color)
                obs['depth'].append(depth)

        return obs, reward, done, info
Execute action with specified primitive.

        For each episode (training, loading, etc.), this is normally called the first
        time from `env.reset()` above, with NO action, and returns an EMPTY observation.
        Then, it's called a SECOND time with an action that lacks a primitive (set to
        None, even though the key exists). But, this method will return an actual image
        observation that we pass to the policy. Finally, subsequent calls will have
        proper actions.

        (Sept 08) Added graceful exit functionality. This will let the code terminate
        early but with task.done=False as we didn't actually 'finish' -- just failed.
        Should use task.done=True to indicate any form of 'successful' dones (hitting
        time limit doesn't count).

        (Oct 09) Clarify documentation for the confusing first time step. I now see
        with ground truth agents, there is no 'second action lacking a primitive',
        because ground truth agents don't need images (see their `act` method).
        
Execute action with specified primitive.
For each episode (training, loading, etc.), this is normally called the first
time from `env.reset()` above, with NO action, and returns an EMPTY observation.
Then, it's called a SECOND time with an action that lacks a primitive (set to
None, even though the key exists). But, this method will return an actual image
observation that we pass to the policy. Finally, subsequent calls will have
proper actions.

(Sept 08) Added graceful exit functionality. This will let the code terminate
early but with task.done=False as we didn't actually 'finish' -- just failed.
Should use task.done=True to indicate any form of 'successful' dones (hitting
time limit doesn't count).

(Oct 09) Clarify documentation for the confusing first time step. I now see
with ground truth agents, there is no 'second action lacking a primitive',
because ground truth agents don't need images .
Execute action with specified primitive . For each episode ( training loading etc . ) this is normally called the first time from ` env . reset () ` above with NO action and returns an EMPTY observation . Then it ' s called a SECOND time with an action that lacks a primitive ( set to None even though the key exists ) . But this method will return an actual image observation that we pass to the policy . Finally subsequent calls will have proper actions . ( Sept 08 ) Added graceful exit functionality . This will let the code terminate early but with task . done = False as we didn ' t actually ' finish ' -- just failed . Should use task . done = True to indicate any form of ' successful ' dones ( hitting time limit doesn ' t count ) . ( Oct 09 ) Clarify documentation for the confusing first time step . I now see with ground truth agents there is no ' second action lacking a primitive ' because ground truth agents don ' t need images .
def step(self, act=None):
        if act and act['primitive']:
            success = self.primitives[act['primitive']](**act['params'])
            if (not success) or self.task.exit_gracefully:
                _, reward_extras = self.task.reward()
                info = self.info
                reward_extras['task.done'] = False
                if self.task.exit_gracefully:
                    reward_extras['exit_gracefully'] = True
                    self.task.exit_gracefully = False  
                if isinstance(self.task, tasks.names['cloth-flat-notarget']):
                    info['sampled_zone_pose'] = self.task.zone_pose
                elif isinstance(self.task, tasks.names['bag-color-goal']):
                    info['bag_base_pos'] = self.task.bag_base_pos[0]
                    info['bag_base_orn'] = self.task.bag_base_orn[0]
                    info['bag_target_color'] = self.task.bag_colors[0]
                info['extras'] = reward_extras
                return {}, 0, True, info
        start_t = time.time()
        while not self.is_static():
            if self.is_bag_env() and (time.time() - start_t > 2.0):
                break
            time.sleep(0.001)
        reward, reward_extras = self.task.reward()
        done = self.task.done()
        info = self.info
        reward_extras['task.done'] = done
        info['extras'] = reward_extras
        if isinstance(self.task, tasks.names['cloth-flat-notarget']):
            info['sampled_zone_pose'] = self.task.zone_pose
        elif isinstance(self.task, tasks.names['bag-color-goal']):
            info['bag_base_pos'] = self.task.bag_base_pos[0]
            info['bag_base_orn'] = self.task.bag_base_orn[0]
            info['bag_target_color'] = self.task.bag_colors[0]
        obs = {}
        if act and 'camera_config' in act:
            obs['color'], obs['depth'] = [], []
            for config in act['camera_config']:
                color, depth, _ = self.render(config)
                obs['color'].append(color)
                obs['depth'].append(depth)
        return obs, reward, done, info
def step ( self , act = None ) : if act and act [ 'primitive' ] : success = self . primitives [ act [ 'primitive' ] ] ( ** act [ 'params' ] ) if ( not success ) or self . task . exit_gracefully : _ , reward_extras = self . task . reward ( ) info = self . info reward_extras [ 'task.done' ] = False if self . task . exit_gracefully : reward_extras [ 'exit_gracefully' ] = True self . task . exit_gracefully = False if isinstance ( self . task , tasks . names [ 'cloth-flat-notarget' ] ) : info [ 'sampled_zone_pose' ] = self . task . zone_pose elif isinstance ( self . task , tasks . names [ 'bag-color-goal' ] ) : info [ 'bag_base_pos' ] = self . task . bag_base_pos [ 0 ] info [ 'bag_base_orn' ] = self . task . bag_base_orn [ 0 ] info [ 'bag_target_color' ] = self . task . bag_colors [ 0 ] info [ 'extras' ] = reward_extras return { } , 0 , True , info start_t = time . time ( ) while not self . is_static ( ) : if self . is_bag_env ( ) and ( time . time ( ) - start_t > 2.0 ) : break time . sleep ( 0.001 ) reward , reward_extras = self . task . reward ( ) done = self . task . done ( ) info = self . info reward_extras [ 'task.done' ] = done info [ 'extras' ] = reward_extras if isinstance ( self . task , tasks . names [ 'cloth-flat-notarget' ] ) : info [ 'sampled_zone_pose' ] = self . task . zone_pose elif isinstance ( self . task , tasks . names [ 'bag-color-goal' ] ) : info [ 'bag_base_pos' ] = self . task . bag_base_pos [ 0 ] info [ 'bag_base_orn' ] = self . task . bag_base_orn [ 0 ] info [ 'bag_target_color' ] = self . task . bag_colors [ 0 ] obs = { } if act and 'camera_config' in act : obs [ 'color' ] , obs [ 'depth' ] = [ ] , [ ] for config in act [ 'camera_config' ] : color , depth , _ = self . render ( config ) obs [ 'color' ] . append ( color ) obs [ 'depth' ] . append ( depth ) return obs , reward , done , info
Execute action with specified primitive.
Execute action with specified primitive .
"""Execute action with specified primitive.

        For each episode (training, loading, etc.), this is normally called the first
        time from `env.reset()` above, with NO action, and returns an EMPTY observation.
        Then, it's called a SECOND time with an action that lacks a primitive (set to
        None, even though the key exists). But, this method will return an actual image
        observation that we pass to the policy. Finally, subsequent calls will have
        proper actions.

        (Sept 08) Added graceful exit functionality. This will let the code terminate
        early but with task.done=False as we didn't actually 'finish' -- just failed.
        Should use task.done=True to indicate any form of 'successful' dones (hitting
        time limit doesn't count).

        (Oct 09) Clarify documentation for the confusing first time step. I now see
        with ground truth agents, there is no 'second action lacking a primitive',
        because ground truth agents don't need images (see their `act` method).
        """ # Exit early if action failed. Daniel: adding exit_gracefully. # Means we hit irrecoverable action, exit now (reset to False!!). # important !!! # For consistency? # Wait for objects to settle, with a hard exit for bag tasks. # Compute task rewards. # Pass ground truth robot state as info. # Daniel: fine-grained info about rewards (since it's nuanced for some tasks). # If we hit time limit, `task.done` will check if we succeeded on last action. # Get camera observations per specified config.
self
act