From ecf435b6d0972f3e29d0f3eca5e36bbeb192c168 Mon Sep 17 00:00:00 2001 From: avelichk Date: Wed, 26 Aug 2020 21:05:22 +0100 Subject: [PATCH] Fix problem with Hyperopt out of range --- pkg/suggestion/v1beta1/hyperopt/base_service.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/suggestion/v1beta1/hyperopt/base_service.py b/pkg/suggestion/v1beta1/hyperopt/base_service.py index acece984915..fdd541c5cdc 100644 --- a/pkg/suggestion/v1beta1/hyperopt/base_service.py +++ b/pkg/suggestion/v1beta1/hyperopt/base_service.py @@ -181,6 +181,9 @@ def getSuggestions(self, trials, request_number): # Produce new request_number ids to make new Suggestion hyperopt_trial_new_ids = self.fmin.trials.new_trial_ids(request_number) random_state = self.fmin.rstate.randint(2**31 - 1) + + # Trial list that must be deployed + new_trials = [] if self.algorithm_name == RANDOM_ALGORITHM_NAME: new_trials = self.hyperopt_algorithm( new_ids=hyperopt_trial_new_ids, @@ -203,7 +206,6 @@ def getSuggestions(self, trials, request_number): **self.algorithm_conf) self.is_first_run = False else: - new_trials = [] for i in range(request_number): # hyperopt_algorithm always returns one new Trial new_trials.append(self.hyperopt_algorithm( @@ -216,9 +218,13 @@ def getSuggestions(self, trials, request_number): # Construct return advisor Trials from new hyperopt Trials list_of_assignments = [] - for i in range(request_number): - vals = new_trials[i]['misc']['vals'] + for trial in new_trials: + vals = trial['misc']['vals'] list_of_assignments.append(BaseHyperoptService.convert(self.search_space, vals)) + + if len(list_of_assignments) > 0: + logger.info("GetSuggestions returns {} new Trial\n".format(len(new_trials))) + return list_of_assignments @staticmethod