コード例 #1
0
ファイル: init.py プロジェクト: pared/dvc
    def run(self):
        from dvc.command.stage import parse_cmd

        cmd = parse_cmd(self.args.command)
        if not self.args.interactive and not cmd:
            raise InvalidArgumentError("command is not specified")

        from dvc.repo.experiments.init import init

        defaults = {}
        if not self.args.explicit:
            config = self.repo.config["exp"]
            defaults.update({**self.DEFAULTS, **config})

        cli_args = compact({
            "cmd": cmd,
            "code": self.args.code,
            "data": self.args.data,
            "models": self.args.models,
            "metrics": self.args.metrics,
            "params": self.args.params,
            "plots": self.args.plots,
            "live": self.args.live,
        })

        initialized_stage = init(
            self.repo,
            name=self.args.name,
            type=self.args.type,
            defaults=defaults,
            overrides=cli_args,
            interactive=self.args.interactive,
            force=self.args.force,
        )

        text = ui.rich_text.assemble(
            "\n" if self.args.interactive else "",
            "Created ",
            (self.args.name, "bright_blue"),
            " stage in ",
            ("dvc.yaml", "green"),
            ".",
        )
        if not self.args.run:
            text.append_text(
                ui.rich_text.assemble(
                    " To run, use ",
                    ('"dvc exp run"', "green"),
                    ".\nSee ",
                    (self.EXP_LINK, "repr.url"),
                    ".",
                ))

        ui.write(text, styled=True)
        if self.args.run:
            return self.repo.experiments.run(
                targets=[initialized_stage.addressing])

        return 0
コード例 #2
0
ファイル: run.py プロジェクト: rattanjotsingh/dvc
    def run(self):
        if not any(
            [
                self.args.deps,
                self.args.outs,
                self.args.outs_no_cache,
                self.args.metrics,
                self.args.metrics_no_cache,
                self.args.plots,
                self.args.plots_no_cache,
                self.args.outs_persist,
                self.args.outs_persist_no_cache,
                self.args.checkpoints,
                self.args.params,
                self.args.cmd,
            ]
        ):  # pragma: no cover
            logger.error(
                "too few arguments. Specify at least one: `-d`, `-o`, `-O`, "
                "`-m`, `-M`, `-p`, `--plots`, `--plots-no-cache`, "
                "`--outs-persist`, `--outs-persist-no-cache`, `command`."
            )
            return 1

        try:
            self.repo.run(
                cmd=parse_cmd(self.args.cmd),
                outs=self.args.outs,
                outs_no_cache=self.args.outs_no_cache,
                metrics=self.args.metrics,
                metrics_no_cache=self.args.metrics_no_cache,
                plots=self.args.plots,
                plots_no_cache=self.args.plots_no_cache,
                live=self.args.live,
                live_no_cache=self.args.live_no_cache,
                live_no_summary=self.args.live_no_summary,
                live_no_html=self.args.live_no_html,
                deps=self.args.deps,
                params=self.args.params,
                fname=self.args.file,
                wdir=self.args.wdir,
                no_exec=(self.args.no_exec or bool(self.args.checkpoints)),
                force=self.args.force,
                run_cache=not self.args.no_run_cache,
                no_commit=self.args.no_commit,
                outs_persist=self.args.outs_persist,
                outs_persist_no_cache=self.args.outs_persist_no_cache,
                checkpoints=self.args.checkpoints,
                always_changed=self.args.always_changed,
                name=self.args.name,
                single_stage=self.args.single_stage,
                external=self.args.external,
                desc=self.args.desc,
            )
        except DvcException:
            logger.exception("")
            return 1

        return 0
コード例 #3
0
ファイル: experiments.py プロジェクト: rpatil524/dvc
    def run(self):
        from dvc.command.stage import parse_cmd

        cmd = parse_cmd(self.args.cmd)
        if not self.args.interactive and not cmd:
            raise InvalidArgumentError("command is not specified")

        from dvc.repo.experiments.init import init

        global_defaults = {
            "code": self.CODE,
            "data": self.DATA,
            "models": self.MODELS,
            "metrics": self.DEFAULT_METRICS,
            "params": self.DEFAULT_PARAMS,
            "plots": self.PLOTS,
            "live": self.DVCLIVE,
        }
        defaults = {}
        if not self.args.explicit:
            config = {}  # TODO
            defaults.update({**global_defaults, **config})

        cli_args = compact({
            "cmd": cmd,
            "code": self.args.code,
            "data": self.args.data,
            "models": self.args.models,
            "metrics": self.args.metrics,
            "params": self.args.params,
            "plots": self.args.plots,
            "live": self.args.live,
        })

        initialized_stage = init(
            self.repo,
            name=self.args.name,
            type=self.args.type,
            defaults=defaults,
            overrides=cli_args,
            interactive=self.args.interactive,
            force=self.args.force,
        )
        if self.args.run:
            return self.repo.experiments.run(
                targets=[initialized_stage.addressing])
        return 0
コード例 #4
0
ファイル: run.py プロジェクト: vishalbelsare/dvc
    def run(self):
        if not any([
                self.args.deps,
                self.args.outs,
                self.args.outs_no_cache,
                self.args.metrics,
                self.args.metrics_no_cache,
                self.args.plots,
                self.args.plots_no_cache,
                self.args.outs_persist,
                self.args.outs_persist_no_cache,
                self.args.checkpoints,
                self.args.params,
                self.args.command,
        ]):  # pragma: no cover
            logger.error(
                "too few arguments. Specify at least one: `-d`, `-o`, `-O`, "
                "`-m`, `-M`, `-p`, `--plots`, `--plots-no-cache`, "
                "`--outs-persist`, `--outs-persist-no-cache`, `command`.")
            return 1

        kwargs = vars(self.args)
        kwargs.update({
            "cmd":
            parse_cmd(self.args.command),
            "fname":
            kwargs.pop("file"),
            "no_exec": (self.args.no_exec or bool(self.args.checkpoints)),
            "run_cache":
            not kwargs.pop("no_run_cache"),
        })
        try:
            self.repo.run(**kwargs)
        except DvcException:
            logger.exception("")
            return 1

        return 0
コード例 #5
0
ファイル: experiments.py プロジェクト: gcoter/dvc
    def run(self):
        from dvc.command.stage import parse_cmd

        cmd = parse_cmd(self.args.cmd)
        if not self.args.interactive and not cmd:
            raise InvalidArgumentError("command is not specified")

        from dvc.dvcfile import make_dvcfile

        global_defaults = {
            "code": self.CODE,
            "data": self.DATA,
            "models": self.MODELS,
            "metrics": self.DEFAULT_METRICS,
            "params": self.DEFAULT_PARAMS,
            "plots": self.PLOTS,
            "live": self.DVCLIVE,
        }

        dvcfile = make_dvcfile(self.repo, "dvc.yaml")
        name = self.args.name or self.args.type

        dvcfile_exists = dvcfile.exists()
        if not self.args.force and dvcfile_exists and name in dvcfile.stages:
            from dvc.stage.exceptions import DuplicateStageName

            hint = "Use '--force' to overwrite."
            raise DuplicateStageName(
                f"Stage '{name}' already exists in 'dvc.yaml'. {hint}"
            )

        context = ChainMap()
        if not self.args.explicit:
            config = {}  # TODO
            context.maps.extend([config, global_defaults])

        with_live = self.args.type == "live"
        if self.args.interactive:
            try:
                context = self.init_interactive(
                    defaults=context,
                    show_heading=not dvcfile_exists,
                    live=with_live,
                )
            except (KeyboardInterrupt, EOFError):
                ui.error_write()
                raise
        elif with_live:
            # suppress `metrics`/`params` if live is selected, unless
            # also provided via cli, also make output to be a checkpoint.
            context = context.new_child({"metrics": None, "params": None})
        else:
            # suppress live otherwise
            context = context.new_child({"live": None})

        if not self.args.interactive:
            d = compact(
                {
                    "cmd": cmd,
                    "code": self.args.code,
                    "data": self.args.data,
                    "models": self.args.models,
                    "metrics": self.args.metrics,
                    "params": self.args.params,
                    "plots": self.args.plots,
                    "live": self.args.live,
                }
            )
            context = context.new_child(d)

        assert "cmd" in context
        command = context["cmd"]
        code = context.get("code")
        data = context.get("data")
        models = context.get("models")
        metrics = context.get("metrics")
        plots = context.get("plots")
        live = context.get("live")

        params_kv = []
        if context.get("params"):
            from dvc.utils.serialize import LOADERS

            path = context["params"]
            _, ext = os.path.splitext(path)
            params_kv = [{path: list(LOADERS[ext](path))}]

        checkpoint_out = bool(context.get("live"))
        stage = self.repo.stage.add(
            name=name,
            cmd=command,
            deps=compact([code, data]),
            params=params_kv,
            metrics_no_cache=compact([metrics]),
            plots_no_cache=compact([plots]),
            live=live,
            force=self.args.force,
            **{"checkpoints" if checkpoint_out else "outs": compact([models])},
        )

        if self.args.run:
            return self.repo.experiments.run(targets=[stage.addressing])
        return 0