def load_configs()

in scripts/plotting/plot_sweep.py [0:0]


def load_configs(paths: Iterable, config_filter: Optional[Callable] = None) -> Dict:
    """Finds all configs recursively and reads their content."""
    configs = {}
    for path in paths:
        try:
            file_paths = list(path.rglob("meta.json"))
        except FileNotFoundError as exc:
            missing = Path(exc.filename).name
            if missing.startswith("train_tid"):
                pass  # expected: these are deleted during experiments
            else:
                # If this code is reached, see if other files need handling.
                assert False, (exc.args, exc.filename, exc.filename2)
        except OSError as exc:
            if exc.errno == errno.ESTALE:
                # This may happen when an experiment is still running.
                print(f"Ignoring due to stale file handle: {path}")
                continue
            # If this code is reached, see if there are other error codes that may be ignored.
            assert False, (str(exc), exc.errno)
        for file_path in file_paths:
            config = load_config(file_path.parent)
            if config is not None and (config_filter is None or config_filter(config)):
                configs[file_path.parent] = config
    cr = "\n  "
    # Show max 10 configs
    configs_to_show = list(map(str, sorted(configs)))
    if len(configs_to_show) > 10:
        configs_to_show = configs_to_show[0:5] + ["..."] + configs_to_show[-5:]
    print(f"Loaded {len(configs)} configs:{cr}{cr.join(configs_to_show)}")
    return configs