Repository: ray-project/ray

Issue:
[tune] genetic_example.py --smoke-test output should be reduced
```
2019-03-03 10:58:40,611	INFO genetic_searcher.py:68 -- [GENETIC SEARCH] Generate the 1th generation, population=10
2019-03-03 10:58:40,678	INFO search_policy.py:115 -- =========== BEGIN Experiment-Round: 1 [10 NEW | 10 TOTAL] ===========
2019-03-03 10:58:41,430	ERROR trial_runner.py:252 -- Trial Runner checkpointing failed.
Traceback (most recent call last):
  File "/ray/python/ray/tune/trial_runner.py", line 250, in step
    self.checkpoint()
  File "/ray/python/ray/tune/trial_runner.py", line 144, in checkpoint
    json.dump(runner_state, f, indent=2)
  File "/opt/conda/lib/python2.7/json/__init__.py", line 189, in dump
    for chunk in iterable:
  File "/opt/conda/lib/python2.7/json/encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/opt/conda/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/opt/conda/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "/opt/conda/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/opt/conda/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "/opt/conda/lib/python2.7/json/encoder.py", line 442, in _iterencode
    o = _default(o)
  File "/opt/conda/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) is not JSON serializable
2019-03-03 10:58:41,449	ERROR trial_runner.py:252 -- Trial Runner checkpointing failed.
```


Discussion:

Resolving patch:
diff --git a/python/ray/tune/trial.py b/python/ray/tune/trial.py
--- a/python/ray/tune/trial.py
+++ b/python/ray/tune/trial.py
@@ -299,6 +299,24 @@ def __init__(self,
         self.error_file = None
         self.num_failures = 0
 
+        # AutoML fields
+        self.results = None
+        self.best_result = None
+        self.param_config = None
+        self.extra_arg = None
+
+        self._nonjson_fields = [
+            "_checkpoint",
+            "config",
+            "loggers",
+            "sync_function",
+            "last_result",
+            "results",
+            "best_result",
+            "param_config",
+            "extra_arg",
+        ]
+
         self.trial_name = None
         if trial_name_creator:
             self.trial_name = trial_name_creator(self)
@@ -509,17 +527,8 @@ def __getstate__(self):
         state = self.__dict__.copy()
         state["resources"] = resources_to_json(self.resources)
 
-        # These are non-pickleable entries.
-        pickle_data = {
-            "_checkpoint": self._checkpoint,
-            "config": self.config,
-            "loggers": self.loggers,
-            "sync_function": self.sync_function,
-            "last_result": self.last_result
-        }
-
-        for key, value in pickle_data.items():
-            state[key] = binary_to_hex(cloudpickle.dumps(value))
+        for key in self._nonjson_fields:
+            state[key] = binary_to_hex(cloudpickle.dumps(state.get(key)))
 
         state["runner"] = None
         state["result_logger"] = None
@@ -535,10 +544,7 @@ def __getstate__(self):
     def __setstate__(self, state):
         logger_started = state.pop("__logger_started__")
         state["resources"] = json_to_resources(state["resources"])
-        for key in [
-                "_checkpoint", "config", "loggers", "sync_function",
-                "last_result"
-        ]:
+        for key in self._nonjson_fields:
             state[key] = cloudpickle.loads(hex_to_binary(state[key]))
 
         self.__dict__.update(state)


Test patch: