11
11
import abc
12
12
13
13
from .notebook_integration import live_plot , live_info , in_ipynb
14
- from .utils import timed
15
14
16
15
try :
17
16
import ipyparallel
@@ -105,8 +104,7 @@ class BaseRunner(metaclass=abc.ABCMeta):
105
104
Methods
106
105
-------
107
106
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
110
108
``100 * (1 - total_elapsed_function_time / self.elapsed_time())``.
111
109
112
110
"""
@@ -130,8 +128,7 @@ def __init__(self, learner, goal, *,
130
128
self .learner = learner
131
129
self .log = [] if log else None
132
130
133
- # Function timing
134
- self .function = functools .partial (timed , self .learner .function )
131
+ # Timing
135
132
self .start_time = time .time ()
136
133
self .end_time = None
137
134
self ._elapsed_function_time = 0
@@ -190,7 +187,8 @@ def _process_futures(self, done_futs):
190
187
for fut in done_futs :
191
188
x = self .pending_points .pop (fut )
192
189
try :
193
- y , t = fut .result ()
190
+ y = fut .result ()
191
+ t = time .time () - fut .start_time # total execution time
194
192
except Exception as e :
195
193
self .tracebacks [x ] = traceback .format_exc ()
196
194
self .to_retry [x ] = self .to_retry .get (x , 0 ) + 1
@@ -218,7 +216,9 @@ def _get_futures(self):
218
216
points , _ = self ._ask (n_new_tasks )
219
217
220
218
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
222
222
223
223
# Collect and results and add them to the learner
224
224
futures = list (self .pending_points .keys ())
@@ -332,7 +332,7 @@ def __init__(self, learner, goal, *,
332
332
self ._run ()
333
333
334
334
def _submit (self , x ):
335
- return self .executor .submit (self .function , x )
335
+ return self .executor .submit (self .learner . function , x )
336
336
337
337
def _run (self ):
338
338
first_completed = concurrent .FIRST_COMPLETED
@@ -471,9 +471,9 @@ def goal(_):
471
471
def _submit (self , x ):
472
472
ioloop = self .ioloop
473
473
if inspect .iscoroutinefunction (self .learner .function ):
474
- return ioloop .create_task (self .function (x ))
474
+ return ioloop .create_task (self .learner . function (x ))
475
475
else :
476
- return ioloop .run_in_executor (self .executor , self .function , x )
476
+ return ioloop .run_in_executor (self .executor , self .learner . function , x )
477
477
478
478
def status (self ):
479
479
"""Return the runner status as a string.
0 commit comments