1111import abc
1212
1313from .notebook_integration import live_plot , live_info , in_ipynb
14- from .utils import timed
1514
1615try :
1716 import ipyparallel
@@ -105,8 +104,7 @@ class BaseRunner(metaclass=abc.ABCMeta):
105104 Methods
106105 -------
107106 overhead : callable
108- The overhead in percent of using Adaptive. This includes the
109- overhead of the executor. Essentially, this is
107+ The overhead in percent of using Adaptive. Essentially, this is
110108 ``100 * (1 - total_elapsed_function_time / self.elapsed_time())``.
111109
112110 """
@@ -130,8 +128,7 @@ def __init__(self, learner, goal, *,
130128 self .learner = learner
131129 self .log = [] if log else None
132130
133- # Function timing
134- self .function = functools .partial (timed , self .learner .function )
131+ # Timing
135132 self .start_time = time .time ()
136133 self .end_time = None
137134 self ._elapsed_function_time = 0
@@ -190,7 +187,8 @@ def _process_futures(self, done_futs):
190187 for fut in done_futs :
191188 x = self .pending_points .pop (fut )
192189 try :
193- y , t = fut .result ()
190+ y = fut .result ()
191+ t = time .time () - fut .start_time # total execution time
194192 except Exception as e :
195193 self .tracebacks [x ] = traceback .format_exc ()
196194 self .to_retry [x ] = self .to_retry .get (x , 0 ) + 1
@@ -218,7 +216,9 @@ def _get_futures(self):
218216 points , _ = self ._ask (n_new_tasks )
219217
220218 for x in points :
221- self .pending_points [self ._submit (x )] = x
219+ fut = self ._submit (x )
220+ fut .start_time = time .time () # so we can measure execution time
221+ self .pending_points [fut ] = x
222222
223223 # Collect and results and add them to the learner
224224 futures = list (self .pending_points .keys ())
@@ -332,7 +332,7 @@ def __init__(self, learner, goal, *,
332332 self ._run ()
333333
334334 def _submit (self , x ):
335- return self .executor .submit (self .function , x )
335+ return self .executor .submit (self .learner . function , x )
336336
337337 def _run (self ):
338338 first_completed = concurrent .FIRST_COMPLETED
@@ -471,9 +471,9 @@ def goal(_):
471471 def _submit (self , x ):
472472 ioloop = self .ioloop
473473 if inspect .iscoroutinefunction (self .learner .function ):
474- return ioloop .create_task (self .function (x ))
474+ return ioloop .create_task (self .learner . function (x ))
475475 else :
476- return ioloop .run_in_executor (self .executor , self .function , x )
476+ return ioloop .run_in_executor (self .executor , self .learner . function , x )
477477
478478 def status (self ):
479479 """Return the runner status as a string.
0 commit comments