reuse pool workers

This commit is contained in:
Janne Sinivirta 2018-06-19 21:57:42 +03:00
parent 0cb1aedf5b
commit a46badd5c0

View File

@ -308,13 +308,12 @@ class Hyperopt(Backtesting):
'result': result_explanation, 'result': result_explanation,
} }
) )
return loss
# return { return {
# 'loss': loss, 'loss': loss,
# 'status': STATUS_OK, 'status': STATUS_OK,
# 'result': result_explanation, 'result': result_explanation,
# } }
def format_results(self, results: DataFrame) -> str: def format_results(self, results: DataFrame) -> str:
""" """
@ -374,12 +373,13 @@ class Hyperopt(Backtesting):
opt = Optimizer(self.hyperopt_space(), "ET", acq_optimizer="sampling") opt = Optimizer(self.hyperopt_space(), "ET", acq_optimizer="sampling")
with Parallel(n_jobs=-1) as parallel:
for i in range(self.total_tries//cpus): for i in range(self.total_tries//cpus):
asked = opt.ask(n_points=cpus) asked = opt.ask(n_points=cpus)
#asked = opt.ask() #asked = opt.ask()
#f_val = self.generate_optimizer(asked) #f_val = self.generate_optimizer(asked)
f_val = Parallel(n_jobs=-1)(delayed(self.generate_optimizer)(v) for v in asked) f_val = parallel(delayed(self.generate_optimizer)(v) for v in asked)
opt.tell(asked, f_val) opt.tell(asked, [i['loss'] for i in f_val])
print(f'got value {f_val}') print(f'got value {f_val}')