Walk over action space to collect completed paths of at most ``self._max_path_length`` steps.
422227
def _walk(self) -> None:
        
        # Buffer of NTs to expand, previous actions
        incomplete_paths = [([str(type_)], [f"{START_SYMBOL} -> {type_}"]) for type_ in
                            self._world.get_valid_starting_types()]

        self._completed_paths = []
        actions = self._world.get_valid_actions()
        # Keeps track of `MultiMatchNamedBasicTypes` to substitute them with appropriate types.
        multi_match_substitutions = self._world.get_multi_match_mapping()
        # Overview: We keep track of the buffer of non-terminals to expand, and the action history
        # for each incomplete path. At every iteration in the while loop below, we iterate over all
        # incomplete paths, expand one non-terminal from the buffer in a depth-first fashion, get
        # all possible next actions triggered by that non-terminal and add to the paths. Then, we
        # check the expanded paths, to see if they are 1) complete, in which case they are
        # added to completed_paths, 2) longer than max_path_length, in which case they are
        # discarded, or 3) neither, in which case they are used to form the incomplete_paths for the
        # next iteration of this while loop.
        # While the non-terminal expansion is done in a depth-first fashion, note that the search over
        # the action space itself is breadth-first.
        while incomplete_paths:
            next_paths = []
            for nonterminal_buffer, history in incomplete_paths:
                # Taking the last non-terminal added to the buffer. We're going depth-first.
                nonterminal = nonterminal_buffer.pop()
                next_actions = []
                if nonterminal in multi_match_substitutions:
                    for current_nonterminal in [nonterminal] + multi_match_substitutions[nonterminal]:
                        if current_nonterminal in actions:
                            next_actions.extend(actions[current_nonterminal])
                elif nonterminal not in actions:
                    # This happens when the nonterminal corresponds to a type that does not exist in
                    # the context. For example, in the variable free variant of the WikiTables
                    # world, there are nonterminals for specific column types (like date). Say we
                    # produced a path containing "filter_date_greater" already, and we do not have
                    # an columns of type "date", then this condition would be triggered. We should
                    # just discard those paths.
                    continue
                else:
                    next_actions.extend(actions[nonterminal])
                # Iterating over all possible next actions.
                for action in next_actions:
                    new_history = history + [action]
                    new_nonterminal_buffer = nonterminal_buffer[:]
                    # Since we expand the last action added to the buffer, the left child should be
                    # added after the right child.
                    for right_side_part in reversed(self._get_right_side_parts(action)):
                        if types.is_nonterminal(right_side_part):
                            new_nonterminal_buffer.append(right_side_part)
                    next_paths.append((new_nonterminal_buffer, new_history))
            incomplete_paths = []
            for nonterminal_buffer, path in next_paths:
                # An empty buffer means that we've completed this path.
                if not nonterminal_buffer:
                    # Indexing completed paths by the nonterminals they contain.
                    next_path_index = len(self._completed_paths)
                    for action in path:
                        for value in self._get_right_side_parts(action):
                            if not types.is_nonterminal(value):
                                self._terminal_path_index[action].add(next_path_index)
                    self._completed_paths.append(path)
                # We're adding to incomplete_paths for the next iteration, only those paths that are
                # shorter than the max_path_length. The remaining paths will be discarded.
                elif len(path) <= self._max_path_length:
                    incomplete_paths.append((nonterminal_buffer, path))
1289701
def safe_walk(top, topdown=True, onerror=None, followlinks=True, _seen=None):
    '''
    
    '''
    if _seen is None:
        _seen = set()

    # We may not have read permission for top, in which case we can't
    # get a list of the files the directory contains.  os.path.walk
    # always suppressed the exception then, rather than blow up for a
    # minor reason when (say) a thousand readable directories are still
    # left to visit.  That logic is copied here.
    try:
        # Note that listdir and error are globals in this module due
        # to earlier import-*.
        names = os.listdir(top)
    except os.error as err:
        if onerror is not None:
            onerror(err)
        return

    if followlinks:
        status = os.stat(top)
        # st_ino is always 0 on some filesystems (FAT, NTFS); ignore them
        if status.st_ino != 0:
            node = (status.st_dev, status.st_ino)
            if node in _seen:
                return
            _seen.add(node)

    dirs, nondirs = [], []
    for name in names:
        full_path = os.path.join(top, name)
        if os.path.isdir(full_path):
            dirs.append(name)
        else:
            nondirs.append(name)

    if topdown:
        yield top, dirs, nondirs
    for name in dirs:
        new_path = os.path.join(top, name)
        if followlinks or not os.path.islink(new_path):
            for x in safe_walk(new_path, topdown, onerror, followlinks, _seen):
                yield x
    if not topdown:
        yield top, dirs, nondirs
1337437
def step(self, actions):
    
    for index, (env, action) in enumerate(zip(self._envs, actions)):
      if not env.action_space.contains(action):
        message = 'Invalid action at index {}: {}'
        raise ValueError(message.format(index, action))
    if self._blocking:
      transitions = [
          env.step(action)
          for env, action in zip(self._envs, actions)]
    else:
      transitions = [
          env.step(action, blocking=False)
          for env, action in zip(self._envs, actions)]
      transitions = [transition() for transition in transitions]
    observs, rewards, dones, infos = zip(*transitions)
    observ = np.stack(observs)
    reward = np.stack(rewards)
    done = np.stack(dones)
    info = tuple(infos)
    return observ, reward, done, info
738597
def _iter_walk(
        self,
        fs,  # type: FS
        path,  # type: Text
        namespaces=None,  # type: Optional[Collection[Text]]
    ):
        # type: (...) -> Iterator[Tuple[Text, Optional[Info]]]
        """"""
        if self.search == "breadth":
            return self._walk_breadth(fs, path, namespaces=namespaces)
        else:
            return self._walk_depth(fs, path, namespaces=namespaces)
1120776
def get_max_length(self):
        
        max_length = 0
        for track in self.tracks:
            if max_length < track.pianoroll.shape[0]:
                max_length = track.pianoroll.shape[0]
        return max_length
231090
def directory_walk(source_d, destination_d):
    '''
    
    '''
    for dirpath, dirnames, filenames in os.walk(source_d):
        relpath = os.path.relpath(dirpath, source_d)
        if relpath == '.':
            relpath = ''  # remove implied '.'
        for filename in filenames:
            suffix = filename
            if relpath:
                suffix = os.path.join(relpath, filename)
            full_source_path = os.path.join(source_d, suffix)
            full_destination_path = os.path.join(destination_d, suffix)
            yield full_source_path, full_destination_path
37598
def fully_expanded_path(self):
        
        return os.path.abspath(
            os.path.normpath(
                os.path.normcase(
                    os.path.expandvars(
                        os.path.expanduser(self.path)))))
435447
def steps(self, goal):
        

        path = self.path(goal)
        for i in range(len(path) - 1):
            yield path[i], path[i + 1]
1335002
def get_unused_paths(self):
        
        return [path for path in self.filter.paths if path not in self.seen_paths]
46647
def tree(path, depth=2, topdown=True, followlinks=False, showhidden=False):
    """"""
    rt = []
    for root, dirs, files in os.walk(path, topdown=topdown, followlinks=followlinks):
        if not showhidden and File.is_hidden(root):
            continue

        current_depth = len(os.path.relpath(root, path).split(os.sep))
        if current_depth > depth:
            continue

        if showhidden:
            _tuple = (
                root,
                [File(os.path.join(root, _dir)) for _dir in dirs],
                [File(os.path.join(root, _file)) for _file in files]
            )
        else:
            _tuple = (
                root,
                [File(os.path.join(root, _dir)) for _dir in dirs if _dir[0] != '.'],
                [File(os.path.join(root, _file)) for _file in files if _file[0] != '.']
            )

        rt.append(_tuple)
    return rt
790199
def walk(self, top, topdown=True, ignore_file_handler=None):
        

        def onerror(e):
            raise e

        for root, dirs, files in dvc_walk(
            os.path.abspath(top),
            topdown=topdown,
            onerror=onerror,
            ignore_file_handler=ignore_file_handler,
        ):
            yield os.path.normpath(root), dirs, files
280685
def _complete_trajectory(self, trajectory, index):
    """"""

    assert isinstance(trajectory, Trajectory)

    # This *should* be the case.
    assert trajectory.last_time_step.action is None

    # Add to completed trajectories.
    self._completed_trajectories.append(trajectory)

    # Make a new one to replace it.
    self._trajectories[index] = Trajectory()
494301
def walk_paths(self,
                   base: Optional[pathlib.PurePath] = pathlib.PurePath()) \
            -> Iterator[pathlib.PurePath]:
        
        raise NotImplementedError()
18319
def get_top_n_action_types(self, top_n):
        """"""
        # Count action types
        action_type_to_counts = dict()
        for action in self.actions:
            actiontype = action.actiontype
            if actiontype not in action_type_to_counts:
                action_type_to_counts[actiontype] = 1
            else:
                action_type_to_counts[actiontype] = \
                        action_type_to_counts[actiontype] + 1

        # Convert the dictionary representation into a pair of lists
        action_types = list()
        counts = list()
        for actiontype in action_type_to_counts.keys():
            action_types.append(actiontype)
            counts.append(action_type_to_counts[actiontype])

        # How many actions in total?
        num_actions = len(self.actions)
        num_actions2 = 0
        for count in counts:
            num_actions2 = num_actions2 + count
        if num_actions != num_actions2:
            raise(Exception('Problem counting everything up!'))

        # Sort action types by count (lowest to highest)
        sorted_inds = np.argsort(counts)
        last_ind = len(sorted_inds)-1

        # Return the top N actions
        top_actions = list()
        if top_n > len(sorted_inds):
            raise Exception('Asked for top %d action types, ' +
                            'but there are only %d action types'
                            % (top_n, len(sorted_inds)))
        for i in range(top_n):
            top_actions.append(action_types[sorted_inds[last_ind-i]])
        return top_actions
1264335
def sorted_walk(dir):
    
    for base, dirs, files in os.walk(dir):
        dirs.sort()
        files.sort()
        yield base, dirs, files
731338
def _walk(self, root_path='', root_id=''):
        
        '''  '''
        
        title = '%s._walk' % self.__class__.__name__
        
        if root_id:
            pass
        elif root_path:
            root_id, root_parent = self._get_id(root_path)
        for file_id, name, mimetype in self._list_directory(root_id):
            file_path = os.path.join(root_path, name)
            if mimetype == 'application/vnd.google-apps.folder':
                for path, id in self._walk(root_path=file_path, root_id=file_id):
                    yield path, id
            else:
                yield file_path, file_id
1329402
def find(self, path):
        '''
        
        '''
        if self.mindepth < 1:
            dirpath, name = os.path.split(path)
            match, fstat = self._check_criteria(dirpath, name, path)
            if match:
                for result in self._perform_actions(path, fstat=fstat):
                    yield result

        for dirpath, dirs, files in salt.utils.path.os_walk(path):
            relpath = os.path.relpath(dirpath, path)
            depth = path_depth(relpath) + 1
            if depth >= self.mindepth and (self.maxdepth is None or self.maxdepth >= depth):
                for name in dirs + files:
                    fullpath = os.path.join(dirpath, name)
                    match, fstat = self._check_criteria(dirpath, name, fullpath)
                    if match:
                        for result in self._perform_actions(fullpath, fstat=fstat):
                            yield result

            if self.maxdepth is not None and depth > self.maxdepth:
                dirs[:] = []