Skip to content

Commit

Permalink
clean codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Weixuan Fu committed Mar 30, 2017
1 parent 544fdf3 commit 26c0da9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
48 changes: 21 additions & 27 deletions tpot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,36 +727,30 @@ def _wrapped_cross_val_score(sklearn_pipeline, features=features, classes=classe
resulting_score = -float('inf')
return resulting_score

if self.n_jobs != 1:
pool = Pool(processes=self.n_jobs)
resulting_score_list = []
# chunk size for pbar update
for chunk_idx in range(0, len(sklearn_pipeline_list),self.n_jobs*2):
# evalurate pipeline

resulting_score_list = []
# chunk size for pbar update
for chunk_idx in range(0, len(sklearn_pipeline_list),self.n_jobs*2):
if self.n_jobs != 1:
pool = Pool(processes=self.n_jobs)
tmp_result_score = pool.map(_wrapped_cross_val_score, sklearn_pipeline_list[chunk_idx:chunk_idx+self.n_jobs*2])
for val in tmp_result_score:
if not self._pbar.disable:
self._pbar.update(1)
if val == 'Timeout':
if self.verbosity > 2:
self._pbar.write('Skipped pipeline #{0} due to time out. '
'Continuing to the next pipeline.'.format(self._pbar.n))
resulting_score_list.append(-float('inf'))
else:
resulting_score_list.append(val)
pool.terminate()
else:
resulting_score_list = []
for sklearn_pipeline in sklearn_pipeline_list:
try:
resulting_score = _wrapped_cross_val_score(sklearn_pipeline)
except TimedOutExc:
resulting_score = -float('inf')
if self.verbosity > 2 and not self._pbar.disable:
self._pbar.write('Skipped pipeline #{0} due to time out. '
'Continuing to the next pipeline.'.format(self._pbar.n + 1))
resulting_score_list.append(resulting_score)
pool.terminate() # garbage collection
else:
tmp_result_score = map(_wrapped_cross_val_score, sklearn_pipeline_list[chunk_idx:chunk_idx+self.n_jobs*2])
# update pbar
for val in tmp_result_score:
if not self._pbar.disable:
self._pbar.update(1)
if val == 'Timeout':
if self.verbosity > 2:
self._pbar.write('Skipped pipeline #{0} due to time out. '
'Continuing to the next pipeline.'.format(self._pbar.n))
resulting_score_list.append(-float('inf'))
else:
resulting_score_list.append(val)



for resulting_score, operator_count, individual_str, test_idx in zip(resulting_score_list, operator_count_list, eval_individuals_str, test_idx_list):
if type(resulting_score) in [float, np.float64, np.float32]:
Expand Down
5 changes: 4 additions & 1 deletion tpot/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,21 @@ def wrap_func(func):
import signal
@wraps(func)
def limitedTime(*args, **kw):
# don't show traceback
sys.tracebacklimit=0
old_signal_hander = signal.signal(signal.SIGALRM, timeout_signal_handler)
max_time_seconds = convert_mins_to_secs(max_eval_time_mins)
signal.alarm(max_time_seconds)
try:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
ret = func(*args, **kw)
except:
except TimedOutExc:
raise TimedOutExc('Time Out!')
finally:
signal.signal(signal.SIGALRM, old_signal_hander) # Old signal handler is restored
signal.alarm(0) # Alarm removed
sys.tracebacklimit=1000
return ret
else:
class InterruptableThread(threading.Thread):
Expand Down

0 comments on commit 26c0da9

Please sign in to comment.