From 65f22d823c6cda3d43462430e5551a97c23ddb20 Mon Sep 17 00:00:00 2001 From: Peter Rowlands Date: Wed, 6 Sep 2023 15:20:39 +0900 Subject: [PATCH 1/2] live: warn when DVC_ROOT is set but DVC_EXP_BASELINE_REV is not --- src/dvclive/live.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/dvclive/live.py b/src/dvclive/live.py index 783d65b0..1254c5b0 100644 --- a/src/dvclive/live.py +++ b/src/dvclive/live.py @@ -135,15 +135,7 @@ def _init_cleanup(self): def _init_dvc(self): from dvc.scm import NoSCM - if os.getenv(env.DVC_EXP_BASELINE_REV, None): - # `dvc exp` execution - self._baseline_rev = os.getenv(env.DVC_EXP_BASELINE_REV, "") - self._exp_name = os.getenv(env.DVC_EXP_NAME, "") - self._inside_dvc_exp = True - if self._save_dvc_exp: - logger.info("Ignoring `save_dvc_exp` because `dvc exp run` is running") - self._save_dvc_exp = False - + self._init_dvc_pipeline() self._dvc_repo = get_dvc_repo() dvc_logger = logging.getLogger("dvc") @@ -183,6 +175,22 @@ def _init_dvc(self): mark_dvclive_only_started(self._exp_name) self._include_untracked.append(self.dir) + def _init_dvc_pipeline(self): + if os.getenv(env.DVC_EXP_BASELINE_REV, None): + # `dvc exp` execution + self._baseline_rev = os.getenv(env.DVC_EXP_BASELINE_REV, "") + self._exp_name = os.getenv(env.DVC_EXP_NAME, "") + self._inside_dvc_exp = True + if self._save_dvc_exp: + logger.info("Ignoring `save_dvc_exp` because `dvc exp run` is running") + self._save_dvc_exp = False + elif os.getenv(env.DVC_ROOT, None): + # `dvc repro` execution + logger.warning( + "Some DVCLive features are unsupported in `dvc repro`." + "\nTo use DVCLive with a DVC Pipeline, run it with `dvc exp run`." + ) + def _init_studio(self): self._dvc_studio_config = get_dvc_studio_config(self) if not self._dvc_studio_config: From 5a5d511625ef69d701cd78e437f51e50fd7fa7ae Mon Sep 17 00:00:00 2001 From: daavoo Date: Wed, 20 Sep 2023 11:52:10 +0200 Subject: [PATCH 2/2] Disable `save_dvc_exp` inside `dvc repro` --- src/dvclive/live.py | 3 +++ tests/test_dvc.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dvclive/live.py b/src/dvclive/live.py index 1254c5b0..4a96636f 100644 --- a/src/dvclive/live.py +++ b/src/dvclive/live.py @@ -186,6 +186,9 @@ def _init_dvc_pipeline(self): self._save_dvc_exp = False elif os.getenv(env.DVC_ROOT, None): # `dvc repro` execution + if self._save_dvc_exp: + logger.info("Ignoring `save_dvc_exp` because `dvc repro` is running") + self._save_dvc_exp = False logger.warning( "Some DVCLive features are unsupported in `dvc repro`." "\nTo use DVCLive with a DVC Pipeline, run it with `dvc exp run`." diff --git a/tests/test_dvc.py b/tests/test_dvc.py index 3cd6c5c8..3c96de95 100644 --- a/tests/test_dvc.py +++ b/tests/test_dvc.py @@ -10,7 +10,7 @@ from dvclive import Live from dvclive.dvc import get_dvc_repo, make_dvcyaml -from dvclive.env import DVC_EXP_BASELINE_REV, DVC_EXP_NAME +from dvclive.env import DVC_EXP_BASELINE_REV, DVC_EXP_NAME, DVC_ROOT from dvclive.serialize import load_yaml YAML_LOADER = YAML(typ="safe") @@ -322,3 +322,10 @@ def test_no_scm_repo(tmp_dir, mocker): live = Live(save_dvc_exp=True) assert live._save_dvc_exp is False + + +def test_dvc_repro(tmp_dir, monkeypatch, mocker): + monkeypatch.setenv(DVC_ROOT, "root") + mocker.patch("dvclive.live.get_dvc_repo", return_value=None) + live = Live(save_dvc_exp=True) + assert not live._save_dvc_exp