Repository: ray-project/ray

Issue:
[tune] run crashes if reporter isn't used
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: OSX 10.11.6
- **Ray installed from (source or binary)**: I ran `pip install -U ray` not sure which that is
- **Ray version**: 0.6.5
- **Python version**: 3.5.2
- **Exact command to reproduce**:
```
import ray
from ray.tune import Experiment

def run_task(config, reporter):
	print('hello')

experiment = Experiment(run=run_task,
				config={},
				resources_per_trial={"cpu": 1, "gpu": 0},
				name="ray_crash_repro")
ray.init()
ray.tune.run(experiment)
print("end") # never reached
```

### Describe the problem
Not using the `reporter` in the function run by an `Experiment` causes `ray` to crash when it tries to get timing statistics.

If this is desired behavior, it should be documented a little better. The [quick start guide here](https://ray.readthedocs.io/en/latest/tune.html?highlight=reporter) doesn't mention that using the reporter is required.

If this isn't desired behavior I think you can just fill in default values in `fetch_result` for any missing keys that are used later.

### Source code / logs

Traceback (most recent call last):
```
2019-06-25 15:02:03,270	ERROR trial_runner.py:460 -- Error processing event.
Traceback (most recent call last):
  File "/Users/Neil/anaconda/envs/rllab3ray/lib/python3.5/site-packages/ray/tune/trial_runner.py", line 420, in _process_trial
    self._total_time += result[TIME_THIS_ITER_S]
KeyError: 'time_this_iter_s'
2019-06-25 15:02:03,271	INFO ray_trial_executor.py:178 -- Destroying actor for trial run_task_0. If your trainable is slow to initialize, consider setting reuse_actors=True to reduce actor creation overheads.
Traceback (most recent call last):
  File "ray_crash_repro.py", line 12, in <module>
    ray.tune.run(experiment)
  File "/Users/Neil/anaconda/envs/rllab3ray/lib/python3.5/site-packages/ray/tune/tune.py", line 242, in run
    print(runner.debug_string(max_debug=99999))
  File "/Users/Neil/anaconda/envs/rllab3ray/lib/python3.5/site-packages/ray/tune/trial_runner.py", line 354, in debug_string
    t, t.progress_string()))
  File "/Users/Neil/anaconda/envs/rllab3ray/lib/python3.5/site-packages/ray/tune/trial.py", line 441, in progress_string
    int(self.last_result.get(TIME_TOTAL_S)))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
(pid=65702) hello
(pid=65702) WARNING: Not monitoring node memory since `psutil` is not installed. Install this with `pip install psutil` (or ray[debug]) to enable debugging of memory-related crashes.
```


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
@@ -321,7 +321,7 @@ def location_string(hostname, pid):
                     location_string(
                         self.last_result.get(HOSTNAME),
                         self.last_result.get(PID))), "{} s".format(
-                            int(self.last_result.get(TIME_TOTAL_S)))
+                            int(self.last_result.get(TIME_TOTAL_S, 0)))
         ]
 
         if self.last_result.get(TRAINING_ITERATION) is not None:
diff --git a/python/ray/tune/trial_runner.py b/python/ray/tune/trial_runner.py
--- a/python/ray/tune/trial_runner.py
+++ b/python/ray/tune/trial_runner.py
@@ -506,7 +506,7 @@ def _process_trial(self, trial):
                 result = trial.last_result
                 result.update(done=True)
 
-            self._total_time += result[TIME_THIS_ITER_S]
+            self._total_time += result.get(TIME_THIS_ITER_S, 0)
 
             flat_result = flatten_dict(result)
             if trial.should_stop(flat_result):
diff --git a/rllib/evaluation/postprocessing.py b/rllib/evaluation/postprocessing.py
--- a/rllib/evaluation/postprocessing.py
+++ b/rllib/evaluation/postprocessing.py
@@ -28,7 +28,7 @@ def compute_advantages(rollout, last_r, gamma=0.9, lambda_=1.0, use_gae=True):
         last_r (float): Value estimation for last observation
         gamma (float): Discount factor.
         lambda_ (float): Parameter for GAE
-        use_gae (bool): Using Generalized Advantage Estamation
+        use_gae (bool): Using Generalized Advantage Estimation
 
     Returns:
         SampleBatch (SampleBatch): Object with experience from rollout and


Test patch:
diff --git a/python/ray/tune/tests/test_trial_runner.py b/python/ray/tune/tests/test_trial_runner.py
--- a/python/ray/tune/tests/test_trial_runner.py
+++ b/python/ray/tune/tests/test_trial_runner.py
@@ -459,6 +459,15 @@ def train(config, reporter):
         self.assertEqual(trial.status, Trial.TERMINATED)
         self.assertEqual(trial.last_result[TIMESTEPS_TOTAL], 100)
 
+    def testReporterNoUsage(self):
+        def run_task(config, reporter):
+            print("hello")
+
+        experiment = Experiment(run=run_task, name="ray_crash_repro")
+        [trial] = ray.tune.run(experiment).trials
+        print(trial.last_result)
+        self.assertEqual(trial.last_result[DONE], True)
+
     def testErrorReturn(self):
         def train(config, reporter):
             raise Exception("uh oh")