Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom exp name #725

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dvclive/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__( # noqa: PLR0913
save_dvc_exp: bool = False,
dvcyaml: bool = True,
cache_images: bool = False,
exp_name: Optional[str] = None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add exp_message and update other args for this callback in a separate PR.

):
super().__init__()
self._prefix = prefix
Expand Down
8 changes: 6 additions & 2 deletions src/dvclive/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(
save_dvc_exp: bool = True,
dvcyaml: Union[str, bool] = True,
cache_images: bool = False,
exp_name: Optional[str] = None,
exp_message: Optional[str] = None,
):
self.summary: Dict[str, Any] = {}
Expand All @@ -89,7 +90,7 @@ def __init__(
self._init_report()

self._baseline_rev: Optional[str] = None
self._exp_name: Optional[str] = None
self._exp_name: Optional[str] = exp_name
self._exp_message: Optional[str] = exp_message
self._experiment_rev: Optional[str] = None
self._inside_dvc_exp: bool = False
Expand Down Expand Up @@ -178,7 +179,10 @@ def _init_dvc(self):

self._baseline_rev = self._dvc_repo.scm.get_rev()
if self._save_dvc_exp:
self._exp_name = get_random_exp_name(self._dvc_repo.scm, self._baseline_rev)
if not self._exp_name:
dberenbaum marked this conversation as resolved.
Show resolved Hide resolved
self._exp_name = get_random_exp_name(
self._dvc_repo.scm, self._baseline_rev
)
mark_dvclive_only_started(self._exp_name)
self._include_untracked.append(self.dir)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ def test_exp_save_message(tmp_dir, mocked_dvc_repo):
)


def test_exp_save_name(tmp_dir, mocked_dvc_repo):
live = Live(exp_name="custom-name")
live.end()
mocked_dvc_repo.experiments.save.assert_called_with(
name="custom-name",
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
force=True,
message=None,
)


def test_no_scm_repo(tmp_dir, mocker):
dvc_repo = mocker.MagicMock()
dvc_repo.scm = NoSCM()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_post_to_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,14 @@ def test_post_to_studio_message(tmp_dir, mocked_dvc_repo, mocked_studio_post):
"https://0.0.0.0/api/live",
**get_studio_call("start", exp_name=live._exp_name, message="Custom message"),
)


def test_post_to_studio_name(tmp_dir, mocked_dvc_repo, mocked_studio_post):
Live(exp_name="custom-name")

mocked_post, _ = mocked_studio_post

mocked_post.assert_called_with(
"https://0.0.0.0/api/live",
**get_studio_call("start", exp_name="custom-name"),
)
Loading