From feaa5cfcb2adb6100365a3b992a5c53f5edd9814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Rowlands=20=28=EB=B3=80=EA=B8=B0=ED=98=B8=29?= Date: Tue, 20 Oct 2020 14:54:43 +0900 Subject: [PATCH] experiments: fix checkpoints sorting issues in `dvc exp show` (#4740) * experiments: order experiment (branches) by timestamp * checkpoints: sort checkpoint branches by tip commit values * remove sort logic from dvc.scm --- dvc/command/experiments.py | 6 +++++- dvc/repo/experiments/show.py | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py index b908e505e..ebe84c15d 100644 --- a/dvc/command/experiments.py +++ b/dvc/command/experiments.py @@ -155,7 +155,11 @@ def _sort_exp(experiments, sort_by, typ, reverse): ret = OrderedDict() def _sort(item): - _, exp = item + rev, exp = item + tip = exp.get("checkpoint_tip") + if tip and tip != rev: + # Sort checkpoint experiments by tip commit + return _sort((tip, experiments[tip])) for fname, item in exp.get(typ, {}).items(): if isinstance(item, dict): item = flatten(item) diff --git a/dvc/repo/experiments/show.py b/dvc/repo/experiments/show.py index 7d66b2aeb..c5d8f3332 100644 --- a/dvc/repo/experiments/show.py +++ b/dvc/repo/experiments/show.py @@ -110,7 +110,12 @@ def show( ) # collect reproduced experiments - for exp_branch in repo.experiments.scm.list_branches(): + for head in sorted( + repo.experiments.scm.repo.heads, + key=lambda h: h.commit.committed_date, + reverse=True, + ): + exp_branch = head.name m = repo.experiments.BRANCH_RE.match(exp_branch) if m: rev = repo.scm.resolve_rev(m.group("baseline_rev"))