forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
196 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import argparse | ||
import logging | ||
|
||
from dvc.cli.command import CmdBase | ||
from dvc.cli.utils import append_doc_link | ||
from dvc.exceptions import DvcException | ||
from dvc.ui import ui | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CmdExperimentsSave(CmdBase): | ||
def run(self): | ||
|
||
try: | ||
ref = self.repo.experiments.save( | ||
name=self.args.name, force=self.args.force | ||
) | ||
except DvcException: | ||
logger.exception("failed to save experiment") | ||
return 1 | ||
|
||
if self.args.json: | ||
ui.write_json({"ref": ref}) | ||
# fixme: add metrics | ||
else: | ||
name = self.repo.experiments.get_exact_name(ref) | ||
ui.write(f"Experiment has been saved as: {name}") | ||
ui.write( | ||
"\nTo promote an experiment to a Git branch run:\n\n" | ||
"\tdvc exp branch <exp> <branch>\n" | ||
) | ||
if self.args.metrics: | ||
from dvc.compare import show_metrics | ||
|
||
metrics = self.repo.metrics.show(revs=(ref,)) | ||
metrics.pop("workspace", None) | ||
show_metrics(metrics) | ||
|
||
return 0 | ||
|
||
|
||
def add_parser(experiments_subparsers, parent_parser): | ||
EXPERIMENTS_SAVE_HELP = "Save current workspace as a dvc experiment." | ||
save_parser = experiments_subparsers.add_parser( | ||
"save", | ||
parents=[parent_parser], | ||
description=append_doc_link(EXPERIMENTS_SAVE_HELP, "exp/save"), | ||
help=EXPERIMENTS_SAVE_HELP, | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
) | ||
save_parser.add_argument( | ||
"-f", | ||
"--force", | ||
action="store_true", | ||
default=False, | ||
help="Save even if hash value for dependencies/outputs changed.", | ||
) | ||
save_parser.add_argument( | ||
"--json", | ||
"--show-json", | ||
action="store_true", | ||
default=False, | ||
help="Show output in JSON format.", | ||
) | ||
save_parser.add_argument( | ||
"-m", | ||
"--metrics", | ||
action="store_true", | ||
default=False, | ||
help="Show metrics for the saved experiment.", | ||
) | ||
save_parser.add_argument( | ||
"-n", | ||
"--name", | ||
default=None, | ||
help=( | ||
"Human-readable experiment name. If not specified, a name will " | ||
"be auto-generated." | ||
), | ||
metavar="<name>", | ||
) | ||
save_parser.set_defaults(func=CmdExperimentsSave) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
import os | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from funcy import first | ||
|
||
if TYPE_CHECKING: | ||
from dvc.repo import Repo | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def save( | ||
repo: "Repo", | ||
name: Optional[str] = None, | ||
force: bool = False, | ||
) -> Optional[str]: | ||
"""Save the current workspace status as an experiment. | ||
Returns the saved experiment's SHAs. | ||
""" | ||
queue = repo.experiments.workspace_queue | ||
logger.debug("Saving workspace in %s", os.getcwd()) | ||
|
||
entry = repo.experiments.new(queue=queue, name=name, force=force) | ||
executor = queue.init_executor(repo.experiments, entry) | ||
save_result = executor.save(executor.info, force=force) | ||
result = queue.collect_executor(repo.experiments, executor, save_result) | ||
|
||
exp_rev = first(result) | ||
return exp_rev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters