Skip to content
Snippets Groups Projects

Resolve "Make BaseRunner an abstract base class"

Merged Jorn Hoofwijk requested to merge 107-make-baserunner-an-abstract-base-class into master
Compare and
1 file
+ 16
5
Compare changes
  • Side-by-side
  • Inline
+ 16
5
@@ -8,6 +8,7 @@ import os
import time
import traceback
import warnings
import abc
from .notebook_integration import live_plot, live_info, in_ipynb
from .utils import timed
@@ -53,7 +54,7 @@ else:
_default_executor_kwargs = {}
class BaseRunner:
class BaseRunner(metaclass=abc.ABCMeta):
"""Base class for runners that use concurrent.futures.Executors.
Parameters
@@ -246,6 +247,14 @@ class BaseRunner:
"""Set of points that failed 'self.retries' times."""
return set(self.tracebacks) - set(self.to_retry)
@abc.abstractmethod
def elapsed_time(self):
pass # since overhead calls this method
@abc.abstractmethod
def _submit(self, x):
pass # since _get_futures calls this method
class BlockingRunner(BaseRunner):
"""Run a learner synchronously in an executor.
@@ -435,8 +444,7 @@ class AsyncRunner(BaseRunner):
retries=0, raise_if_retries_exceeded=True):
if goal is None:
def goal(_):
return False
+2
goal = lambda _: False
super().__init__(learner, goal, executor=executor, ntasks=ntasks,
log=log, shutdown_executor=shutdown_executor,
@@ -454,9 +462,9 @@ class AsyncRunner(BaseRunner):
raise RuntimeError('Cannot use an executor when learning an '
'async function.')
self.executor.shutdown() # Make sure we don't shoot ourselves later
self._submit = lambda x: self.ioloop.create_task(self.function(x))
self.__submit = lambda x: self.ioloop.create_task(self.function(x))
else:
self._submit = functools.partial(self.ioloop.run_in_executor,
self.__submit = functools.partial(self.ioloop.run_in_executor,
self.executor,
self.function)
@@ -467,6 +475,9 @@ class AsyncRunner(BaseRunner):
"in a Jupyter notebook, remember to run "
"'adaptive.notebook_extension()'")
def _submit(self, x):
return self.__submit(x)
def status(self):
"""Return the runner status as a string.
Loading