Skip to content

Commit

Permalink
exp show: Include deps columns.
Browse files Browse the repository at this point in the history
Use `repo.index.deps` to collect dependencies associated with each experiment.

Closes #6434
  • Loading branch information
daavoo committed Dec 3, 2021
1 parent 024f06d commit 9452c99
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
30 changes: 25 additions & 5 deletions dvc/command/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ def _update_names(names, items):
def _collect_names(all_experiments, **kwargs):
metric_names = defaultdict(dict)
param_names = defaultdict(dict)
deps_names = set()

for _, experiments in all_experiments.items():
for exp_data in experiments.values():
exp = exp_data.get("data", {})
_update_names(metric_names, exp.get("metrics", {}).items())
_update_names(param_names, exp.get("params", {}).items())
deps_names.update(exp.get("deps", {}).keys())

metric_names = _filter_names(
metric_names,
"metrics",
Expand All @@ -118,7 +121,7 @@ def _collect_names(all_experiments, **kwargs):
kwargs.get("exclude_params"),
)

return metric_names, param_names
return metric_names, param_names, deps_names


experiment_types = {
Expand All @@ -136,6 +139,7 @@ def _collect_rows(
experiments,
metric_names,
param_names,
deps_names,
precision=DEFAULT_PRECISION,
sort_by=None,
sort_order=None,
Expand Down Expand Up @@ -208,6 +212,11 @@ def _collect_rows(
executor,
]
fill_value = FILL_VALUE_ERRORED if results.get("error") else fill_value
for dep in deps_names:
hash_info = exp.get("deps", {}).get(dep)
if hash_info is not None:
hash_info = hash_info[:7]
row.append(hash_info or fill_value)
_extend_row(
row,
metric_names,
Expand All @@ -222,7 +231,6 @@ def _collect_rows(
precision,
fill_value=fill_value,
)

yield row


Expand Down Expand Up @@ -328,6 +336,7 @@ def experiments_table(
metric_names,
param_headers,
param_names,
deps_names,
sort_by=None,
sort_order=None,
precision=DEFAULT_PRECISION,
Expand All @@ -347,6 +356,7 @@ def experiments_table(
experiments,
metric_names,
param_names,
deps_names,
sort_by=sort_by,
sort_order=sort_order,
precision=precision,
Expand Down Expand Up @@ -396,7 +406,7 @@ def show_experiments(
include_params = _parse_filter_list(kwargs.pop("include_params", []))
exclude_params = _parse_filter_list(kwargs.pop("exclude_params", []))

metric_names, param_names = _collect_names(
metric_names, param_names, deps_names = _collect_names(
all_experiments,
include_metrics=include_metrics,
exclude_metrics=exclude_metrics,
Expand All @@ -412,6 +422,7 @@ def show_experiments(
"parent",
"State",
"Executor",
*deps_names,
]

names = {**metric_names, **param_names}
Expand All @@ -427,6 +438,7 @@ def show_experiments(
metric_names,
param_headers,
param_names,
deps_names,
kwargs.get("sort_by"),
kwargs.get("sort_order"),
kwargs.get("precision"),
Expand All @@ -450,14 +462,22 @@ def show_experiments(
)
td.drop(*merge_headers[1:])

headers = {"metrics": metric_headers, "params": param_headers}
headers = {
"metrics": metric_headers,
"params": param_headers,
"deps": deps_names,
}
styles = {
"Experiment": {"no_wrap": True, "header_style": "black on grey93"},
"Created": {"header_style": "black on grey93"},
"State": {"header_style": "black on grey93"},
"Executor": {"header_style": "black on grey93"},
}
header_bg_colors = {"metrics": "cornsilk1", "params": "light_cyan1"}
header_bg_colors = {
"metrics": "cornsilk1",
"params": "light_cyan1",
"deps": "plum2",
}
styles.update(
{
header: {
Expand Down
6 changes: 6 additions & 0 deletions dvc/repo/experiments/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def _collect_experiment_commit(
if params:
res["params"] = params

res["deps"] = {
dep.def_path: dep.hash_info.value
for dep in repo.index.deps
if type(dep).__name__ != "ParamsDependency"
}

res["queued"] = stash
if running is not None and exp_rev in running:
res["running"] = True
Expand Down
18 changes: 9 additions & 9 deletions tests/func/experiments/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_show_simple(tmp_dir, scm, dvc, exp_stage):
assert dvc.experiments.show()["workspace"] == {
"baseline": {
"data": {
"deps": {"copy.py": "561f068574ab2a132d304dca3dd6510d"},
"metrics": {"metrics.yaml": {"data": {"foo": 1}}},
"params": {"params.yaml": {"data": {"foo": 1}}},
"queued": False,
Expand All @@ -45,6 +46,7 @@ def test_show_experiment(tmp_dir, scm, dvc, exp_stage, workspace):

expected_baseline = {
"data": {
"deps": {"copy.py": "561f068574ab2a132d304dca3dd6510d"},
"metrics": {"metrics.yaml": {"data": {"foo": 1}}},
"params": {"params.yaml": {"data": {"foo": 1}}},
"queued": False,
Expand Down Expand Up @@ -376,6 +378,7 @@ def test_show_running_workspace(tmp_dir, scm, dvc, exp_stage, capsys):
assert dvc.experiments.show()["workspace"] == {
"baseline": {
"data": {
"deps": {"copy.py": "561f068574ab2a132d304dca3dd6510d"},
"metrics": {"metrics.yaml": {"data": {"foo": 1}}},
"params": {"params.yaml": {"data": {"foo": 1}}},
"queued": False,
Expand Down Expand Up @@ -500,25 +503,23 @@ def _get_rev_isotimestamp(rev):
capsys.readouterr()
assert main(["exp", "show", "--csv"]) == 0
cap = capsys.readouterr()
assert "Experiment,rev,typ,Created,parent" in cap.out
assert "copy.py,metrics.yaml:foo,params.yaml:foo" in cap.out
assert ",workspace,baseline,,,561f068,3,3" in cap.out
assert (
"Experiment,rev,typ,Created,parent,metrics.yaml:foo,params.yaml:foo"
in cap.out
)
assert ",workspace,baseline,,,3,3" in cap.out
assert (
"master,{},baseline,{},,1,1".format(
"master,{},baseline,{},,561f068,1,1".format(
baseline_rev[:7], _get_rev_isotimestamp(baseline_rev)
)
in cap.out
)
assert (
"{},{},branch_base,{},,2,2".format(
"{},{},branch_base,{},,561f068,2,2".format(
ref_info1.name, rev1[:7], _get_rev_isotimestamp(rev1)
)
in cap.out
)
assert (
"{},{},branch_commit,{},,3,3".format(
"{},{},branch_commit,{},,561f068,3,3".format(
ref_info2.name, rev2[:7], _get_rev_isotimestamp(rev2)
)
in cap.out
Expand Down Expand Up @@ -559,7 +560,6 @@ def test_show_only_changed(tmp_dir, dvc, scm, capsys):
assert main(["exp", "show"]) == 0
cap = capsys.readouterr()

print(cap)
assert "bar" in cap.out

capsys.readouterr()
Expand Down

0 comments on commit 9452c99

Please sign in to comment.