[tune] logger refactor part 1: move classes and utilities to own files (#11746)

* [tune] logger refactor part 1: move classes and utilities to own files

* Fix circular dependency

* Remove uneeded pretty print copy

* Apply suggestions from code review
This commit is contained in:
Kai Fricke
2020-11-03 07:48:09 -08:00
committed by GitHub
parent 5af745c90d
commit f7b19c41e3
20 changed files with 481 additions and 375 deletions
+27
View File
@@ -1,5 +1,7 @@
import copy
import json
import logging
import numbers
import os
import inspect
import threading
@@ -538,6 +540,31 @@ def detect_config_single(func):
return use_config_single
class SafeFallbackEncoder(json.JSONEncoder):
def __init__(self, nan_str="null", **kwargs):
super(SafeFallbackEncoder, self).__init__(**kwargs)
self.nan_str = nan_str
def default(self, value):
try:
if np.isnan(value):
return self.nan_str
if (type(value).__module__ == np.__name__
and isinstance(value, np.ndarray)):
return value.tolist()
if issubclass(type(value), numbers.Integral):
return int(value)
if issubclass(type(value), numbers.Number):
return float(value)
return super(SafeFallbackEncoder, self).default(value)
except Exception:
return str(value) # give up, just stringify it (ok for logs)
if __name__ == "__main__":
ray.init()
X = pin_in_object_store("hello")