Skip to content

Commit

Permalink
track dvcyaml file (#710)
Browse files Browse the repository at this point in the history
* live: Set new defaults `report=None` and `save_dvc_exp=True`.

* frameworks: Drop model_file.

* update examples

* Write to root dvc.yaml (#687)

* add dvcyaml to root

* clean up dvcyaml implementation

* fix existing tests

* add new tests

* add unit tests for updating dvcyaml

* use posix paths

* don't resolve symlinks

* drop entire dvclive dir on cleanup

* fix studio tests

* revert cleanup changes

* unify rel_path util func

* cleanup test

* refactor tests

* add test for multiple dvclive instances

* put dvc_file logic into _init_dvc_file

---------

Co-authored-by: daavoo <daviddelaiglesiacastro@gmail.com>

* report: Drop "auto" logic.

Fallback to `None` when conditions are not met for other types.

* studio: Extract `post_to_studio` and decoulple from `make_report` (#705)

* refactor(tests): Split `test_main` into separate files.

Rename test_frameworks to frameworks.

* fix matplotlib warning

* drop dvc.yaml prefix from studio plots

* refactor

* drop .dvc files

* track dvcyaml file

* Studio dvcyaml (#709)

* drop dvc.yaml prefix from studio plots

* refactor

* drop .dvc files

* dvc version bump

* drop unneeded relpath call

* drop extra make_report call

---------

Co-authored-by: daavoo <daviddelaiglesiacastro@gmail.com>
  • Loading branch information
dberenbaum and daavoo committed Sep 21, 2023
1 parent 1bdca3a commit 3524a65
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/dvclive/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ def end(self):
catch_and_warn(DvcException, logger)(ensure_dir_is_tracked)(
self.dir, self._dvc_repo
)
if self._dvcyaml:
catch_and_warn(DvcException, logger)(self._dvc_repo.scm.add)(
self.dvc_file
)

self.make_report()

Expand Down Expand Up @@ -589,6 +593,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
@catch_and_warn(DvcException, logger, mark_dvclive_only_ended)
def save_dvc_exp(self):
if self._save_dvc_exp:
if self._dvcyaml:
self._include_untracked.append(self.dvc_file)
self._experiment_rev = self._dvc_repo.experiments.save(
name=self._exp_name,
include_untracked=self._include_untracked,
Expand Down
22 changes: 15 additions & 7 deletions tests/test_dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_exp_save_on_end(tmp_dir, save, mocked_dvc_repo):
assert live._exp_name is not None
mocked_dvc_repo.experiments.save.assert_called_with(
name=live._exp_name,
include_untracked=[live.dir],
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
force=True,
message=None,
)
Expand Down Expand Up @@ -67,6 +67,7 @@ def test_exp_save_run_on_dvc_repro(tmp_dir, mocker):
dvc_repo.scm.get_ref.return_value = None
dvc_repo.scm.no_commits = False
dvc_repo.config = {}
dvc_repo.root_dir = tmp_dir
mocker.patch("dvclive.live.get_dvc_repo", return_value=dvc_repo)
live = Live()
assert live._save_dvc_exp
Expand All @@ -75,7 +76,10 @@ def test_exp_save_run_on_dvc_repro(tmp_dir, mocker):
live.end()

dvc_repo.experiments.save.assert_called_with(
name=live._exp_name, include_untracked=[live.dir], force=True, message=None
name=live._exp_name,
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
force=True,
message=None,
)


Expand All @@ -87,14 +91,18 @@ def test_exp_save_with_dvc_files(tmp_dir, mocker):
dvc_repo.scm.get_rev.return_value = "current_rev"
dvc_repo.scm.get_ref.return_value = None
dvc_repo.scm.no_commits = False
dvc_repo.root_dir = tmp_dir
dvc_repo.config = {}

mocker.patch("dvclive.live.get_dvc_repo", return_value=dvc_repo)
live = Live()
live.end()

dvc_repo.experiments.save.assert_called_with(
name=live._exp_name, include_untracked=[live.dir], force=True, message=None
name=live._exp_name,
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
force=True,
message=None,
)


Expand Down Expand Up @@ -126,7 +134,7 @@ def test_untracked_dvclive_files_inside_dvc_exp_run_are_added(
with Live() as live:
live.log_metric("foo", 1)
live.next_step()
live._dvc_repo.scm.add.assert_called_with(["dvclive/metrics.json", plot_file])
live._dvc_repo.scm.add.assert_any_call(["dvclive/metrics.json", plot_file])


def test_dvc_outs_are_not_added(tmp_dir, mocked_dvc_repo, monkeypatch):
Expand All @@ -144,7 +152,7 @@ def test_dvc_outs_are_not_added(tmp_dir, mocked_dvc_repo, monkeypatch):
live.log_metric("foo", 1)
live.next_step()

live._dvc_repo.scm.add.assert_called_with(["dvclive/metrics.json"])
live._dvc_repo.scm.add.assert_any_call(["dvclive/metrics.json"])


def test_errors_on_git_add_are_catched(tmp_dir, mocked_dvc_repo, monkeypatch):
Expand All @@ -153,7 +161,7 @@ def test_errors_on_git_add_are_catched(tmp_dir, mocked_dvc_repo, monkeypatch):
mocked_dvc_repo.scm.untracked_files.return_value = ["dvclive/metrics.json"]
mocked_dvc_repo.scm.add.side_effect = DvcException("foo")

with Live() as live:
with Live(dvcyaml=False) as live:
live.summary["foo"] = 1


Expand All @@ -162,7 +170,7 @@ def test_exp_save_message(tmp_dir, mocked_dvc_repo):
live.end()
mocked_dvc_repo.experiments.save.assert_called_with(
name=live._exp_name,
include_untracked=[live.dir],
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
force=True,
message="Custom message",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_log_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_log_artifact_with_save_dvc_exp(tmp_dir, mocker, mocked_dvc_repo):
live.log_artifact("data")
mocked_dvc_repo.experiments.save.assert_called_with(
name=live._exp_name,
include_untracked=[live.dir, "data", ".gitignore"],
include_untracked=[live.dir, "data", ".gitignore", str(tmp_dir / "dvc.yaml")],
force=True,
message=None,
)
Expand Down

0 comments on commit 3524a65

Please sign in to comment.