Skip to content

Trial io

Utility functions for loading trials from a file.

load_trials_from_pickle #

load_trials_from_pickle(
    root_dir: Path | str,
) -> Sequence[tuple[Mapping[str, Any], UserResultDict]]

Load trials from a pickle-based TrialRepo.

PARAMETER DESCRIPTION
root_dir

The root directory containing the 'configs' folder.

TYPE: Path | str

RETURNS DESCRIPTION
Sequence[tuple[Mapping[str, Any], UserResultDict]]

Sequence[tuple[Mapping[str, Any], UserResultDict]]: A sequence of tuples, each containing the trial configuration and its corresponding report as a dictionary.

Source code in scalefm/utils/trial_io.py
def load_trials_from_pickle(
    root_dir: Path | str,
) -> Sequence[tuple[Mapping[str, Any], UserResultDict]]:
    """Load trials from a pickle-based TrialRepo.

    Args:
        root_dir (Path | str): The root directory containing the 'configs' folder.

    Returns:
        Sequence[tuple[Mapping[str, Any], UserResultDict]]: A sequence of tuples,
        each containing the trial configuration and its corresponding report
        as a dictionary.
    """
    if isinstance(root_dir, str):
        root_dir = Path(root_dir)
    trials: ValuesView[Trial] = (
        TrialRepo(
            root_dir / "configs",
        )
        .latest(create_cache_if_missing=False)
        .values()
    )

    return [
        (trial.config, cast("UserResultDict", asdict(trial.report)))
        for trial in trials
        if trial.report is not None
    ]