<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_residual(self, pores=[], overwrite=False):
 r""" Method to start invasion in a network w. residual saturation. Called after inlets are set. Parameters pores : array_like The pores locations that are to be filled with invader at the beginning of the simulation. overwrite : boolean If ``True`` then all existing inlet locations will be removed and then the supplied locations will be added. If ``False``, then supplied locations are added to any already existing locations. Notes ----- Currently works for pores only and treats inner throats, i.e. those that connect two pores in the cluster as invaded and outer ones as uninvaded. Uninvaded throats are added to a new residual cluster queue but do not start invading independently if not connected to an inlet. Step 1. Identify clusters in the phase occupancy. Step 2. Look for clusters that are connected or contain an inlet Step 3. For those that are merge into inlet cluster. May be connected to more than one - run should sort this out Step 4. For those that are isolated set the queue to not invading. Step 5. (in run) When isolated cluster is met my invading cluster it merges in and starts invading """

        Ps = self._parse_indices(pores)
        if overwrite:
            self['pore.residual'] = False
        self['pore.residual'][Ps] = True
        residual = self['pore.residual']
        net = self.project.network
        conns = net['throat.conns']
        rclusters = site_percolation(conns, residual).sites
        rcluster_ids = np.unique(rclusters[rclusters > -1])
        initial_num = len(self.queue)-1
        for rcluster_id in rcluster_ids:
            rPs = rclusters == rcluster_id
            existing = np.unique(self['pore.cluster'][rPs])
            existing = existing[existing > -1]
            if len(existing) > 0:
                # There was at least one inlet cluster connected to this
                # residual cluster, pick the first one.
                cluster_num = existing[0]
            else:
                # Make a new cluster queue
                cluster_num = len(self.queue)
                self.queue.append([])
            queue = self.queue[cluster_num]
            # Set the residual pores and inner throats as part of cluster
            self['pore.cluster'][rPs] = cluster_num
            Ts = net.find_neighbor_throats(pores=rPs,
                                           flatten=True,
                                           mode='xnor')
            self['throat.cluster'][Ts] = cluster_num
            self['pore.invasion_sequence'][rPs] = 0
            self['throat.invasion_sequence'][Ts] = 0
            self['pore.invasion_pressure'][rPs] = -np.inf
            self['throat.invasion_pressure'][Ts] = -np.inf
            # Add all the outer throats to the queue
            Ts = net.find_neighbor_throats(pores=rPs,
                                           flatten=True,
                                           mode='exclusive_or')
            for T in Ts:
                data = []
                # Pc
                data.append(self['throat.entry_pressure'][T])
                # Element Index
                data.append(T)
                # Element Type (Pore of Throat)
                data.append('throat')
                hq.heappush(queue, data)
        self.invasion_running = [True]*len(self.queue)
        # we have added new clusters that are currently isolated and we
        # need to stop them invading until they merge into an invading
        # cluster
        for c_num in range(len(self.queue)):
            if c_num > initial_num:
                self.invasion_running[c_num] = False