Repository: pytorch/ignite

Issue:
Reset should_terminate between runs
Following the [comment](https://github.com/pytorch/ignite/issues/227#issuecomment-410770504), currently, Engine's `should_terminate`/`should_terminate_single_epoch` are not reset between runs. IMO, starting a run we need to set them arguments to `False`


Discussion:

Patch:
diff --git a/ignite/engine/engine.py b/ignite/engine/engine.py
index 29e5359d..79f79fb0 100644
--- a/ignite/engine/engine.py
+++ b/ignite/engine/engine.py
@@ -130,7 +130,7 @@ class Engine(object):
                 TIME_ITERATION_COMPLETED = "time_iteration_completed"
 
             TBPTT_event_to_attr = {TBPTT_Events.TIME_ITERATION_STARTED: 'time_iteration',
-                                   TBPTT_Events.TIME_ITERATION_STARTED: 'time_iteration'}
+                                   TBPTT_Events.TIME_ITERATION_COMPLETED: 'time_iteration'}
 
             engine = Engine(process_function)
             engine.register_events(*TBPTT_Events, event_to_attr=TBPTT_event_to_attr)
@@ -363,6 +363,7 @@ class Engine(object):
         """
 
         self.state = State(dataloader=data, max_epochs=max_epochs, metrics={})
+        self.should_terminate = self.should_terminate_single_epoch = False
 
         try:
             self._logger.info("Engine run starting with max_epochs={}.".format(max_epochs))


Test patch:
diff --git a/tests/ignite/engine/test_engine.py b/tests/ignite/engine/test_engine.py
index 6b5a269f..624f1d5a 100644
--- a/tests/ignite/engine/test_engine.py
+++ b/tests/ignite/engine/test_engine.py
@@ -713,3 +713,22 @@ def test_create_supervised_with_metrics():
 
     state = evaluator.run(data)
     assert state.metrics['mse'] == 12.5
+
+
+def test_reset_should_terminate():
+
+    def update_fn(engine, batch):
+        pass
+
+    engine = Engine(update_fn)
+
+    @engine.on(Events.ITERATION_COMPLETED)
+    def terminate_on_iteration_10(engine):
+        if engine.state.iteration == 10:
+            engine.terminate()
+
+    engine.run([0] * 20)
+    assert engine.state.iteration == 10
+
+    engine.run([0] * 20)
+    assert engine.state.iteration == 10