Skip to content

Commit

Permalink
experiments: store experiments in refs/exps instead of heads (#4910)
Browse files Browse the repository at this point in the history
* experiments: commit to refs/exps/... instead of branch heads

* update exp show

* restore checkpoint_resume kwarg

* refactor new() to use experiments stash

* experiments: use refspecs to populate and collect executors

* experiments: use new stash and merge on exp checkout

* experiments: fix executor chdir

* experiments: update run and show

* skip checkout after reproduce

* checkpoints: use experiments refspecs

* check if workspace was stashed before applying

* exp show: unify checkpoint/standalone experiment collection

* git: move iter_refs to backend

* update for scm changes

* experiments: replace exp checkout in favor of exp apply

* git: handle rev_parse errors in resolve_commit

* update refs containing and baseline check

* fix sigint handling for checkpoints

* update checkpoint exists behavior

* fix checkpoint baseline behavior

* update tests

* experiments: update gc

* update show tests

* fix type checking errors

* update diff

* scm: add diff, describe

* experiments: generate human readable names

* exp run/resume: allow user specified exp name with -n/--name

* update tests

* experiments: add `exp branch` for promoting experiment to full branch

* fix test

* fix missing file

* experiments: explicitly close scm instances before cleaning up tmp dir
  • Loading branch information
pmrowla authored Dec 2, 2020
1 parent c884c94 commit 176a23e
Show file tree
Hide file tree
Showing 22 changed files with 1,265 additions and 959 deletions.
63 changes: 52 additions & 11 deletions dvc/command/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def _collect_rows(
else:
tree = "└──"
new_checkpoint = True
row.append(f"{tree} {queued}{rev[:7]}{parent}")
name = exp.get("name", rev[:7])
row.append(f"{tree} {queued}{name}{parent}")

if not no_timestamp:
row.append(_format_time(exp.get("timestamp")))
Expand Down Expand Up @@ -352,12 +353,12 @@ def run(self):
return 0


class CmdExperimentsCheckout(CmdBase):
class CmdExperimentsApply(CmdBase):
def run(self):
if not self.repo.experiments:
return 0

self.repo.experiments.checkout(self.args.experiment)
self.repo.experiments.apply(self.args.experiment)

return 0

Expand Down Expand Up @@ -461,6 +462,7 @@ def run(self):
try:
self.repo.experiments.run(
target,
name=self.args.name,
queue=self.args.queue,
run_all=self.args.run_all,
jobs=self.args.jobs,
Expand Down Expand Up @@ -532,6 +534,16 @@ def run(self):
return 0


class CmdExperimentsBranch(CmdBase):
def run(self):
if not self.repo.experiments:
return 0

self.repo.experiments.branch(self.args.experiment, self.args.branch)

return 0


def add_parser(subparsers, parent_parser):
EXPERIMENTS_HELP = "Commands to display and compare experiments."

Expand Down Expand Up @@ -653,20 +665,22 @@ def add_parser(subparsers, parent_parser):
)
experiments_show_parser.set_defaults(func=CmdExperimentsShow)

EXPERIMENTS_CHECKOUT_HELP = "Checkout experiments."
experiments_checkout_parser = experiments_subparsers.add_parser(
"checkout",
EXPERIMENTS_APPLY_HELP = (
"Apply the changes from an experiment to your workspace."
)
experiments_apply_parser = experiments_subparsers.add_parser(
"apply",
parents=[parent_parser],
description=append_doc_link(
EXPERIMENTS_CHECKOUT_HELP, "experiments/checkout"
EXPERIMENTS_APPLY_HELP, "experiments/apply"
),
help=EXPERIMENTS_CHECKOUT_HELP,
help=EXPERIMENTS_APPLY_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
experiments_checkout_parser.add_argument(
"experiment", help="Checkout this experiment.",
experiments_apply_parser.add_argument(
"experiment", help="Experiment to be applied.",
)
experiments_checkout_parser.set_defaults(func=CmdExperimentsCheckout)
experiments_apply_parser.set_defaults(func=CmdExperimentsApply)

EXPERIMENTS_DIFF_HELP = (
"Show changes between experiments in the DVC repository."
Expand Down Expand Up @@ -829,11 +843,38 @@ def add_parser(subparsers, parent_parser):
)
experiments_gc_parser.set_defaults(func=CmdExperimentsGC)

EXPERIMENTS_BRANCH_HELP = "Promote an experiment to a Git branch."
experiments_branch_parser = experiments_subparsers.add_parser(
"branch",
parents=[parent_parser],
description=append_doc_link(
EXPERIMENTS_BRANCH_HELP, "experiments/branch"
),
help=EXPERIMENTS_BRANCH_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
experiments_branch_parser.add_argument(
"experiment", help="Experiment to be promoted.",
)
experiments_branch_parser.add_argument(
"branch", help="Git branch name to use.",
)
experiments_branch_parser.set_defaults(func=CmdExperimentsBranch)


def _add_run_common(parser):
"""Add common args for 'exp run' and 'exp resume'."""
# inherit arguments from `dvc repro`
add_repro_arguments(parser)
parser.add_argument(
"-n",
"--name",
default=None,
help=(
"Human-readable experiment name. If not specified, a name will "
"be auto-generated."
),
)
parser.add_argument(
"--params",
action="append",
Expand Down
Loading

0 comments on commit 176a23e

Please sign in to comment.