Check if CometLogger experiment is alive (#19915)

Co-authored-by: Etay Livne <etay.livne@mobileye.com>
This commit is contained in:
Etay Livne 2024-06-18 20:15:12 +03:00 committed by GitHub
parent 394c42aaf6
commit 1e83a1bd32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -268,7 +268,7 @@ class CometLogger(Logger):
self.logger.experiment.some_comet_function()
"""
if self._experiment is not None:
if self._experiment is not None and self._experiment.alive:
return self._experiment
if self._future_experiment_key is not None:

View File

@ -66,6 +66,20 @@ def test_comet_logger_online(comet_mock):
api.assert_called_once_with("rest")
@mock.patch.dict(os.environ, {})
def test_comet_experiment_resets_if_not_alive(comet_mock):
"""Test that the CometLogger creates a new experiment if the old one is not alive anymore."""
logger = CometLogger()
assert logger._experiment is None
alive_experiment = Mock(alive=True)
logger._experiment = alive_experiment
assert logger.experiment is alive_experiment
unalive_experiment = Mock(alive=False)
logger._experiment = unalive_experiment
assert logger.experiment is not unalive_experiment
@mock.patch.dict(os.environ, {})
def test_comet_logger_no_api_key_given(comet_mock):
"""Test that CometLogger fails to initialize if both api key and save_dir are missing."""