util.py 918 B

123456789101112131415161718192021222324252627
  1. import logging
  2. from typing import Optional
  3. logger = logging.getLogger(__name__)
  4. def _set_search_properties_backwards_compatible(
  5. set_search_properties_func, metric: Optional[str], mode: Optional[str], **spec
  6. ) -> bool:
  7. """Wraps around set_search_properties() so that it is backward compatible.
  8. Also outputs a warning to encourage custom schedulers to be updated.
  9. """
  10. try:
  11. return set_search_properties_func(metric, mode, **spec)
  12. except TypeError as e:
  13. if str(e).startswith(
  14. "set_search_properties() got an unexpected keyword argument"
  15. ):
  16. logger.warning(
  17. "Please update custom Scheduler to take in function signature "
  18. "as ``def set_search_properties(metric, mode, "
  19. "**spec) -> bool``."
  20. )
  21. return set_search_properties_func(metric, mode)
  22. else:
  23. raise e