diff --git a/.gitignore b/.gitignore index bdc6e576..23e03692 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,6 @@ dmypy.json # Cython debug symbols cython_debug/ +.dvc/ +.dvcignore src/dvclive/_dvclive_version.py diff --git a/pyproject.toml b/pyproject.toml index e8c84d02..bd5a9147 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ classifiers = [ ] dynamic = ["version"] dependencies = [ - "dvc>=3.17.0", + "dvc>=3.20.0", "dvc-render>=0.5.0,<1.0", "dvc-studio-client>=0.15.0,<1", "funcy", diff --git a/src/dvclive/studio.py b/src/dvclive/studio.py index 29bb22fc..f74db7ab 100644 --- a/src/dvclive/studio.py +++ b/src/dvclive/studio.py @@ -33,14 +33,9 @@ def _cast_to_numbers(datapoints): return datapoints -def _adapt_plot_name(live, name): +def _adapt_path(live, name): if live._dvc_repo is not None: name = rel_path(name, live._dvc_repo.root_dir) - if os.path.isfile(live.dvc_file): - dvc_file = live.dvc_file - if live._dvc_repo is not None: - dvc_file = rel_path(live.dvc_file, live._dvc_repo.root_dir) - name = f"{dvc_file}::{name}" return name @@ -56,9 +51,7 @@ def _adapt_image(image_path): def _adapt_images(live): return { - _adapt_plot_name(live, image.output_path): { - "image": _adapt_image(image.output_path) - } + _adapt_path(live, image.output_path): {"image": _adapt_image(image.output_path)} for image in live._images.values() if image.step > live._latest_studio_step } @@ -67,8 +60,7 @@ def _adapt_images(live): def get_studio_updates(live): if os.path.isfile(live.params_file): params_file = live.params_file - if live._dvc_repo is not None: - params_file = rel_path(params_file, live._dvc_repo.root_dir) + params_file = _adapt_path(live, params_file) params = {params_file: load_yaml(live.params_file)} else: params = {} @@ -76,12 +68,11 @@ def get_studio_updates(live): plots, metrics = parse_metrics(live) metrics_file = live.metrics_file - if live._dvc_repo is not None: - metrics_file = rel_path(metrics_file, live._dvc_repo.root_dir) + metrics_file = _adapt_path(live, metrics_file) metrics = {metrics_file: {"data": metrics}} plots = { - _adapt_plot_name(live, name): _adapt_plot_datapoints(live, plot) + _adapt_path(live, name): _adapt_plot_datapoints(live, plot) for name, plot in plots.items() } plots = {k: {"data": v} for k, v in plots.items()} diff --git a/tests/test_post_to_studio.py b/tests/test_post_to_studio.py index 747a9b42..0968739d 100644 --- a/tests/test_post_to_studio.py +++ b/tests/test_post_to_studio.py @@ -36,7 +36,6 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post): live = Live() live.log_param("fooparam", 1) - dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix() foo_path = (Path(live.plots_dir) / Metric.subfolder / "foo.tsv").as_posix() mocked_post, _ = mocked_studio_post @@ -54,7 +53,7 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post): "data", exp_name=live._exp_name, step=0, - plots={f"{dvc_path}::{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}}, + plots={f"{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}}, ), ) @@ -67,7 +66,7 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post): "data", exp_name=live._exp_name, step=1, - plots={f"{dvc_path}::{foo_path}": {"data": [{"step": 1, "foo": 2.0}]}}, + plots={f"{foo_path}": {"data": [{"step": 1, "foo": 2.0}]}}, ), ) @@ -89,7 +88,6 @@ def test_post_to_studio_failed_data_request( live = Live() - dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix() foo_path = (Path(live.plots_dir) / Metric.subfolder / "foo.tsv").as_posix() error_response = mocker.MagicMock() @@ -108,7 +106,7 @@ def test_post_to_studio_failed_data_request( exp_name=live._exp_name, step=1, plots={ - f"{dvc_path}::{foo_path}": { + f"{foo_path}": { "data": [{"step": 0, "foo": 1.0}, {"step": 1, "foo": 2.0}] } }, @@ -207,7 +205,6 @@ def test_post_to_studio_shorten_names(tmp_dir, mocked_dvc_repo, mocked_studio_po live.log_metric("eval/loss", 1) live.next_step() - dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix() plots_path = Path(live.plots_dir) loss_path = (plots_path / Metric.subfolder / "eval/loss.tsv").as_posix() @@ -217,7 +214,7 @@ def test_post_to_studio_shorten_names(tmp_dir, mocked_dvc_repo, mocked_studio_po "data", exp_name=live._exp_name, step=0, - plots={f"{dvc_path}::{loss_path}": {"data": [{"step": 0, "loss": 1.0}]}}, + plots={f"{loss_path}": {"data": [{"step": 0, "loss": 1.0}]}}, ), ) @@ -252,7 +249,6 @@ def test_post_to_studio_inside_subdir( live.log_metric("foo", 1) live.next_step() - dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix() foo_path = (Path(live.plots_dir) / Metric.subfolder / "foo.tsv").as_posix() mocked_post.assert_called_with( @@ -262,9 +258,7 @@ def test_post_to_studio_inside_subdir( baseline_sha=live._baseline_rev, exp_name=live._exp_name, step=0, - plots={ - f"{dvc_path}::subdir/{foo_path}": {"data": [{"step": 0, "foo": 1.0}]} - }, + plots={f"subdir/{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}}, ), ) @@ -285,7 +279,6 @@ def test_post_to_studio_inside_subdir_dvc_exp( live.log_metric("foo", 1) live.next_step() - dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix() foo_path = (Path(live.plots_dir) / Metric.subfolder / "foo.tsv").as_posix() mocked_post.assert_called_with( @@ -295,9 +288,7 @@ def test_post_to_studio_inside_subdir_dvc_exp( baseline_sha=live._baseline_rev, exp_name=live._exp_name, step=0, - plots={ - f"{dvc_path}::subdir/{foo_path}": {"data": [{"step": 0, "foo": 1.0}]} - }, + plots={f"subdir/{foo_path}": {"data": [{"step": 0, "foo": 1.0}]}}, ), ) @@ -342,7 +333,6 @@ def test_post_to_studio_images(tmp_dir, mocked_dvc_repo, mocked_studio_post): live.log_image("foo.png", ImagePIL.new("RGB", (10, 10), (0, 0, 0))) live.next_step() - dvc_path = Path(live.dvc_file).relative_to(mocked_dvc_repo.root_dir).as_posix() foo_path = (Path(live.plots_dir) / Image.subfolder / "foo.png").as_posix() mocked_post.assert_called_with( @@ -352,7 +342,7 @@ def test_post_to_studio_images(tmp_dir, mocked_dvc_repo, mocked_studio_post): baseline_sha=live._baseline_rev, exp_name=live._exp_name, step=0, - plots={f"{dvc_path}::{foo_path}": {"image": _adapt_image(foo_path)}}, + plots={f"{foo_path}": {"image": _adapt_image(foo_path)}}, ), )