def CreateOptimizer(self, request: OptimizerService_pb2.CreateOptimizerRequest, context): # pylint: disable=unused-argument self.logger.info("Creating Optimizer") print("CREATING OPTIMIZER") optimization_problem = OptimizationProblem.from_protobuf( optimization_problem_pb2=request.OptimizationProblem) optimizer_config_json = request.OptimizerConfig if optimizer_config_json is not None and len( optimizer_config_json) > 0: optimizer_config = Point.from_json(optimizer_config_json) else: optimizer_config = bayesian_optimizer_config_store.default optimizer = BayesianOptimizer( optimization_problem=optimization_problem, optimizer_config=optimizer_config) optimizer_id = self.get_next_optimizer_id() # To avoid a race condition we acquire the lock before inserting the lock and the optimizer into their respective # dictionaries. Otherwise we could end up with a situation where a lock is in the dictionary, but the optimizer # is not. optimizer_lock = self._lock_manager.RLock() with optimizer_lock: self._optimizer_locks_by_optimizer_id[ optimizer_id] = optimizer_lock self._optimizers_by_id[optimizer_id] = optimizer self._ordered_ids.append(optimizer_id) self.logger.info(f"Created optimizer {optimizer_id}.") return OptimizerService_pb2.OptimizerHandle(Id=optimizer_id)
def CreateOptimizer(self, request: OptimizerService_pb2.CreateOptimizerRequest, context): # pylint: disable=unused-argument optimization_problem = OptimizationProblem.from_protobuf( optimization_problem_pb2=request.OptimizationProblem) optimizer = BayesianOptimizer( optimization_problem=optimization_problem, optimizer_config=BayesianOptimizerConfig.DEFAULT) optimizer_id = self.get_next_optimizer_id() # To avoid a race condition we acquire the lock before inserting the lock and the optimizer into their respective # dictionaries. Otherwise we could end up with a situation where a lock is in the dictionary, but the optimizer # is not. optimizer_lock = self._lock_manager.RLock() with optimizer_lock: self._optimizer_locks_by_optimizer_id[ optimizer_id] = optimizer_lock self._optimizers_by_id[optimizer_id] = optimizer logging.info(f"Created optimizer {optimizer_id}.") return OptimizerService_pb2.OptimizerHandle(Id=optimizer_id)
def optimizer_handle(self): return OptimizerService_pb2.OptimizerHandle(Id=self.id)