Exemple #1
0
def _collect_experiment_commit(
    repo,
    exp_rev,
    stash=False,
    sha_only=True,
    param_deps=False,
    running=None,
    onerror: Optional[Callable] = None,
):
    res: Dict[str, Optional[Any]] = defaultdict(dict)
    for rev in repo.brancher(revs=[exp_rev]):
        if rev == "workspace":
            if exp_rev != "workspace":
                continue
            res["timestamp"] = None
        else:
            commit = repo.scm.resolve_commit(rev)
            res["timestamp"] = datetime.fromtimestamp(commit.commit_time)

        params = _gather_params(repo,
                                rev=rev,
                                targets=None,
                                deps=param_deps,
                                onerror=onerror)
        if params:
            res["params"] = params

        res["queued"] = stash
        if running is not None and exp_rev in running:
            res["running"] = True
            res["executor"] = running[exp_rev].get(ExecutorInfo.PARAM_LOCATION)
        else:
            res["running"] = False
            res["executor"] = None
        if not stash:
            vals = _gather_metrics(repo,
                                   targets=None,
                                   rev=rev,
                                   recursive=False,
                                   onerror=onerror)
            res["metrics"] = vals

        if not sha_only and rev != "workspace":
            for refspec in ["refs/tags", "refs/heads"]:
                name = repo.scm.describe(rev, base=refspec)
                if name:
                    break
            if not name:
                if stash:
                    pass
                else:
                    name = repo.experiments.get_exact_name(rev)
            if name:
                name = name.rsplit("/")[-1]
                res["name"] = name

    return res
Exemple #2
0
def _collect_experiment_commit(
    repo,
    exp_rev,
    stash=False,
    sha_only=True,
    param_deps=False,
    running=None,
    onerror: Optional[Callable] = None,
    is_baseline: bool = False,
):
    from dvc.dependency import ParamsDependency, RepoDependency

    res: Dict[str, Optional[Any]] = defaultdict(dict)
    for rev in repo.brancher(revs=[exp_rev]):
        if rev == "workspace":
            if exp_rev != "workspace":
                continue
            res["timestamp"] = None
        else:
            commit = repo.scm.resolve_commit(rev)
            res["timestamp"] = datetime.fromtimestamp(commit.commit_time)

        params = _gather_params(repo,
                                rev=rev,
                                targets=None,
                                deps=param_deps,
                                onerror=onerror)
        if params:
            res["params"] = params

        res["deps"] = {
            relpath(dep.fs_path, repo.root_dir): {
                "hash": dep.hash_info.value,
                "size": dep.meta.size,
                "nfiles": dep.meta.nfiles,
            }
            for dep in repo.index.deps
            if not isinstance(dep, (ParamsDependency, RepoDependency))
        }
        res["outs"] = {
            relpath(out.fs_path, repo.root_dir): {
                "hash": out.hash_info.value,
                "size": out.meta.size,
                "nfiles": out.meta.nfiles,
                "use_cache": out.use_cache,
                "is_data_source": out.stage.is_data_source,
            }
            for out in repo.index.outs if not (out.is_metric or out.is_plot)
        }

        res["queued"] = stash
        if running is not None and exp_rev in running:
            res["running"] = True
            res["executor"] = running[exp_rev].get("location")
        else:
            res["running"] = False
            res["executor"] = None
        if not stash:
            vals = _gather_metrics(repo,
                                   targets=None,
                                   rev=rev,
                                   recursive=False,
                                   onerror=onerror)
            res["metrics"] = vals

        if not sha_only and rev != "workspace":
            name: Optional[str] = None
            if is_baseline:
                for refspec in ["refs/tags", "refs/heads"]:
                    name = repo.scm.describe(rev, base=refspec)
                    if name:
                        break
            if not name:
                name = repo.experiments.get_exact_name(rev)
            if name:
                name = name.rsplit("/")[-1]
                res["name"] = name

    return res