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,13 +373,14 @@ class Hyperopt(Backtesting):
opt = Optimizer(self.hyperopt_space(), "ET", acq_optimizer="sampling") opt = Optimizer(self.hyperopt_space(), "ET", acq_optimizer="sampling")
for i in range(self.total_tries//cpus): with Parallel(n_jobs=-1) as parallel:
asked = opt.ask(n_points=cpus) for i in range(self.total_tries//cpus):
#asked = opt.ask() asked = opt.ask(n_points=cpus)
#f_val = self.generate_optimizer(asked) #asked = opt.ask()
f_val = Parallel(n_jobs=-1)(delayed(self.generate_optimizer)(v) for v in asked) #f_val = self.generate_optimizer(asked)
opt.tell(asked, f_val) f_val = parallel(delayed(self.generate_optimizer)(v) for v in asked)
print(f'got value {f_val}') opt.tell(asked, [i['loss'] for i in f_val])
print(f'got value {f_val}')
except ValueError: except ValueError: