Repository: facebookresearch/hydra

Issue:
consolidate all example callbacks into experimental/callbacks.py
a follow up to discussion in https://github.com/facebookresearch/hydra/pull/2111


Discussion:

Resolving patch:
diff --git a/hydra/experimental/pickle_job_info_callback.py b/hydra/experimental/callbacks.py
similarity index 55%
rename from hydra/experimental/pickle_job_info_callback.py
rename to hydra/experimental/callbacks.py
--- a/hydra/experimental/pickle_job_info_callback.py
+++ b/hydra/experimental/callbacks.py
@@ -7,29 +7,45 @@
 
 from omegaconf import DictConfig
 
-from hydra.core.utils import JobReturn
+from hydra.core.utils import JobReturn, JobStatus
 from hydra.experimental.callback import Callback
 
-log = logging.getLogger(__name__)
+
+class LogJobReturnCallback(Callback):
+    def __init__(self) -> None:
+        self.log = logging.getLogger(f"{__name__}.{self.__class__.__name__}")
+
+    def on_job_end(
+        self, config: DictConfig, job_return: JobReturn, **kwargs: Any
+    ) -> None:
+        if job_return.status == JobStatus.COMPLETED:
+            self.log.info(f"Succeeded with return value: {job_return.return_value}")
+        elif job_return.status == JobStatus.FAILED:
+            self.log.error("", exc_info=job_return._return_value)
+        else:
+            self.log.error("Status unknown. This should never happen.")
 
 
 class PickleJobInfoCallback(Callback):
     output_dir: Path
 
+    def __init__(self) -> None:
+        self.log = logging.getLogger(f"{__name__}.{self.__class__.__name__}")
+
     def on_job_start(self, config: DictConfig, **kwargs: Any) -> None:
         self.output_dir = Path(config.hydra.runtime.output_dir) / Path(
             config.hydra.output_subdir
         )
         filename = "config.pickle"
         self._save_pickle(obj=config, filename=filename, output_dir=self.output_dir)
-        log.info(f"Saving job configs in {self.output_dir / filename}")
+        self.log.info(f"Saving job configs in {self.output_dir / filename}")
 
     def on_job_end(
         self, config: DictConfig, job_return: JobReturn, **kwargs: Any
     ) -> None:
         filename = "job_return.pickle"
         self._save_pickle(obj=job_return, filename=filename, output_dir=self.output_dir)
-        log.info(f"Saving job_return in {self.output_dir / filename}")
+        self.log.info(f"Saving job_return in {self.output_dir / filename}")
 
     def _save_pickle(self, obj: Any, filename: str, output_dir: Path) -> None:
         output_dir.mkdir(parents=True, exist_ok=True)
diff --git a/hydra/experimental/log_job_return_callback.py b/hydra/experimental/log_job_return_callback.py
deleted file mode 100644
--- a/hydra/experimental/log_job_return_callback.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
-
-import logging
-from typing import Any
-
-from omegaconf import DictConfig
-
-from hydra.core.utils import JobReturn, JobStatus
-from hydra.experimental.callback import Callback
-
-log = logging.getLogger(__name__)
-
-
-class LogJobReturnCallback(Callback):
-    def on_job_end(
-        self, config: DictConfig, job_return: JobReturn, **kwargs: Any
-    ) -> None:
-        if job_return.status == JobStatus.COMPLETED:
-            log.info(f"Succeeded with return value: {job_return.return_value}")
-        elif job_return.status == JobStatus.FAILED:
-            log.error("", exc_info=job_return._return_value)
-        else:
-            log.error("Status unknown. This should never happen.")


Test patch:
diff --git a/tests/test_apps/app_with_log_jobreturn_callback/config.yaml b/tests/test_apps/app_with_log_jobreturn_callback/config.yaml
--- a/tests/test_apps/app_with_log_jobreturn_callback/config.yaml
+++ b/tests/test_apps/app_with_log_jobreturn_callback/config.yaml
@@ -3,4 +3,4 @@ foo: bar
 hydra:
   callbacks:
     log_job_return:
-      _target_: hydra.experimental.log_job_return_callback.LogJobReturnCallback
+      _target_: hydra.experimental.callbacks.LogJobReturnCallback
diff --git a/tests/test_apps/app_with_pickle_job_info_callback/config.yaml b/tests/test_apps/app_with_pickle_job_info_callback/config.yaml
--- a/tests/test_apps/app_with_pickle_job_info_callback/config.yaml
+++ b/tests/test_apps/app_with_pickle_job_info_callback/config.yaml
@@ -3,4 +3,4 @@ foo: bar
 hydra:
   callbacks:
     save_job_info:
-      _target_: hydra.experimental.pickle_job_info_callback.PickleJobInfoCallback
+      _target_: hydra.experimental.callbacks.PickleJobInfoCallback