示例#1
0
def test_metrics_show_precision():
    metrics = {
        "branch_1": {
            "metrics.json": {
                "a": 1.098765366365355,
                "b": {"ad": 1.5342673, "bc": 2.987725527},
            }
        }
    }

    assert _show_metrics(metrics, all_branches=True,) == textwrap.dedent(
        """\
        Revision    Path          a        b.ad     b.bc
        branch_1    metrics.json  1.09877  1.53427  2.98773"""
    )

    assert _show_metrics(
        metrics, all_branches=True, precision=4
    ) == textwrap.dedent(
        """\
        Revision    Path          a       b.ad    b.bc
        branch_1    metrics.json  1.0988  1.5343  2.9877"""
    )

    assert _show_metrics(
        metrics, all_branches=True, precision=7
    ) == textwrap.dedent(
        """\
        Revision    Path          a          b.ad       b.bc
        branch_1    metrics.json  1.0987654  1.5342673  2.9877255"""
    )
示例#2
0
文件: repro.py 项目: vladkol/dvc
    def run(self):
        saved_dir = os.path.realpath(os.curdir)
        os.chdir(self.args.cwd)

        # Dirty hack so the for loop below can at least enter once
        if self.args.all_pipelines:
            self.args.targets = [None]
        elif not self.args.targets:
            self.args.targets = self.default_targets

        ret = 0
        for target in self.args.targets:
            try:
                stages = self.repo.reproduce(target, **self._repro_kwargs)

                if len(stages) == 0:
                    logger.info(CmdDataStatus.UP_TO_DATE_MSG)
                else:
                    logger.info(
                        "Use `dvc push` to send your updates to "
                        "remote storage."
                    )

                if self.args.metrics:
                    metrics = self.repo.metrics.show()
                    logger.info(_show_metrics(metrics))

            except DvcException:
                logger.exception("")
                ret = 1
                break

        os.chdir(saved_dir)
        return ret
示例#3
0
    def run(self):
        from dvc.command.metrics import _show_metrics

        if self.args.reset and self.args.checkpoint_resume:
            raise InvalidArgumentError(
                "--reset and --rev are mutually exclusive.")

        if self.args.reset:
            logger.info("Any existing checkpoints will be reset and re-run.")

        results = self.repo.experiments.run(
            name=self.args.name,
            queue=self.args.queue,
            run_all=self.args.run_all,
            jobs=self.args.jobs,
            params=self.args.set_param,
            checkpoint_resume=self.args.checkpoint_resume,
            reset=self.args.reset,
            tmp_dir=self.args.tmp_dir,
            **self._repro_kwargs,
        )

        if self.args.metrics and results:
            metrics = self.repo.metrics.show(revs=list(results))
            metrics.pop("workspace", None)
            logger.info(_show_metrics(metrics))

        return 0
示例#4
0
def test_metrics_show_with_different_metrics_header():
    assert _show_metrics(
        {
            "branch_1": {
                "metrics.json": {
                    "b": {
                        "ad": 1,
                        "bc": 2
                    },
                    "c": 4
                }
            },
            "branch_2": {
                "metrics.json": {
                    "a": 1,
                    "b": {
                        "ad": 3,
                        "bc": 4
                    }
                }
            },
        },
        all_branches=True,
    ) == textwrap.dedent("""\
        Revision    Path          a    b.ad    b.bc    c
        branch_1    metrics.json  —    1       2       4
        branch_2    metrics.json  1    3       4       —""")
示例#5
0
def test_metrics_show_with_one_revision_multiple_paths():
    assert _show_metrics(
        {
            "branch_1": {
                "metrics.json": {
                    "a": 1,
                    "b": {
                        "ad": 0.1,
                        "bc": 1.03
                    }
                },
                "metrics_1.json": {
                    "a": 2.3,
                    "b": {
                        "ad": 6.5,
                        "bc": 7.9
                    }
                },
            }
        },
        all_branches=True,
    ) == textwrap.dedent("""\
        Revision    Path            a    b.ad    b.bc
        branch_1    metrics.json    1    0.1     1.03
        branch_1    metrics_1.json  2.3  6.5     7.9""")
示例#6
0
def test_metrics_show_with_multiple_revision():
    assert _show_metrics(
        {
            "branch_1": {
                "metrics.json": {
                    "a": 1,
                    "b": {
                        "ad": 1,
                        "bc": 2
                    }
                }
            },
            "branch_2": {
                "metrics.json": {
                    "a": 1,
                    "b": {
                        "ad": 3,
                        "bc": 4
                    }
                }
            },
        },
        all_branches=True,
    ) == textwrap.dedent("""\
        Revision    Path          a    b.ad    b.bc
        branch_1    metrics.json  1    1       2
        branch_2    metrics.json  1    3       4""")
示例#7
0
def test_metrics_show_with_non_dict_values():
    assert _show_metrics(
        {"branch_1": {"metrics.json": 1}}, all_branches=True,
    ) == textwrap.dedent(
        """\
        Revision    Path
        branch_1    metrics.json  1"""
    )
示例#8
0
def test_metrics_show_with_no_revision():
    assert _show_metrics(
        {"branch_1": {"metrics.json": {"a": 0, "b": {"ad": 0.0, "bc": 0.0}}}},
        all_branches=False,
    ) == textwrap.dedent(
        """\
        Path          a    b.ad    b.bc
        metrics.json  0    0.0     0.0"""
    )
示例#9
0
def test_metrics_show_with_valid_falsey_values():
    assert _show_metrics(
        {"branch_1": {"metrics.json": {"a": 0, "b": {"ad": 0.0, "bc": 0.0}}}},
        all_branches=True,
    ) == textwrap.dedent(
        """\
        Revision    Path          a    b.ad    b.bc
        branch_1    metrics.json  0    0.0     0.0"""
    )
示例#10
0
    def run(self):
        if not self.repo.experiments:
            return 0

        saved_dir = os.path.realpath(os.curdir)
        os.chdir(self.args.cwd)

        # Dirty hack so the for loop below can at least enter once
        if self.args.all_pipelines:
            self.args.targets = [None]
        elif not self.args.targets:
            self.args.targets = self.default_targets

        ret = 0
        for target in self.args.targets:
            try:
                stages = self.repo.reproduce(
                    target,
                    single_item=self.args.single_item,
                    force=self.args.force,
                    dry=self.args.dry,
                    interactive=self.args.interactive,
                    pipeline=self.args.pipeline,
                    all_pipelines=self.args.all_pipelines,
                    run_cache=not self.args.no_run_cache,
                    no_commit=self.args.no_commit,
                    downstream=self.args.downstream,
                    recursive=self.args.recursive,
                    force_downstream=self.args.force_downstream,
                    experiment=True,
                    queue=self.args.queue,
                    run_all=self.args.run_all,
                    jobs=self.args.jobs,
                    params=self.args.params,
                    checkpoint=(self.args.checkpoint
                                or self.args.checkpoint_continue is not None),
                    checkpoint_continue=self.args.checkpoint_continue,
                )

                if len(stages) == 0:
                    logger.info(CmdDataStatus.UP_TO_DATE_MSG)

                if self.args.metrics:
                    metrics = self.repo.metrics.show()
                    logger.info(_show_metrics(metrics))

            except DvcException:
                logger.exception("")
                ret = 1
                break

        os.chdir(saved_dir)
        return ret
示例#11
0
    def run(self):
        stages = self.repo.reproduce(**self._repro_kwargs)
        if len(stages) == 0:
            logger.info(CmdDataStatus.UP_TO_DATE_MSG)
        else:
            logger.info("Use `dvc push` to send your updates to "
                        "remote storage.")

        if self.args.metrics:
            metrics = self.repo.metrics.show()
            logger.info(_show_metrics(metrics))

        return 0
示例#12
0
def test_metrics_show_default():
    assert _show_metrics(
        {
            "metrics.yaml": {
                "x.b": {"old": 5, "new": 6},
                "a.d.e": {"old": 3, "new": 4, "diff": 1},
                "a.b.c": {"old": 1, "new": 2, "diff": 1},
            }
        },
    ) == textwrap.dedent(
        """\
        Path    diff    new    old
        x.b     —       6      5
        a.d.e   1       4      3
        a.b.c   1       2      1"""
    )
示例#13
0
def test_metrics_show_with_valid_falsey_values():
    assert _show_metrics(
        {"branch_1": {
            "metrics.json": {
                "a": 0,
                "b": {
                    "ad": 0.0,
                    "bc": 0.0
                }
            }
        }},
        all_branches=True,
    ) == textwrap.dedent("""\
        branch_1:
        \tmetrics.json:
        \t\ta: 0
        \t\tb.ad: 0.0
        \t\tb.bc: 0.0""")
示例#14
0
def test_metrics_show_md():
    assert _show_metrics(
        {
            "metrics.yaml": {
                "x.b": {"old": 5, "new": 6},
                "a.d.e": {"old": 3, "new": 4, "diff": 1},
                "a.b.c": {"old": 1, "new": 2, "diff": 1},
            }
        },
        markdown=True,
    ) == textwrap.dedent(
        """\
        | Path   | diff   | new   | old   |
        |--------|--------|-------|-------|
        | x.b    | —      | 6     | 5     |
        | a.d.e  | 1      | 4     | 3     |
        | a.b.c  | 1      | 2     | 1     |
        """
    )