def encode_optimization_problem(optimization_problem: OptimizationProblem) -> OptimizerService_pb2.OptimizationProblem: return OptimizerService_pb2.OptimizationProblem( ParameterSpace=OptimizerService_pb2.Hypergrid(HypergridJsonString=json.dumps(optimization_problem.parameter_space, cls=HypergridJsonEncoder)), ObjectiveSpace=OptimizerService_pb2.Hypergrid(HypergridJsonString=json.dumps(optimization_problem.objective_space, cls=HypergridJsonEncoder)), Objectives=[OptimizerService_pb2.Objective(Name=objective.name, Minimize=objective.minimize) for objective in optimization_problem.objectives], ContextSpace=None if optimization_problem.context_space is None else OptimizerService_pb2.Hypergrid(HypergridJsonString=json.dumps(optimization_problem.context_space, cls=HypergridJsonEncoder)) )
def encode_optimization_problem( optimization_problem: OptimizationProblem ) -> OptimizerService_pb2.OptimizationProblem: return OptimizerService_pb2.OptimizationProblem( ParameterSpace=OptimizerServiceEncoder.encode_hypergrid( optimization_problem.parameter_space), ObjectiveSpace=OptimizerServiceEncoder.encode_hypergrid( optimization_problem.objective_space), Objectives=[ OptimizerService_pb2.Objective(Name=objective.name, Minimize=objective.minimize) for objective in optimization_problem.objectives ], ContextSpace=None if optimization_problem.context_space is None else OptimizerServiceEncoder.encode_hypergrid( optimization_problem.context_space))
def to_protobuf(self): """ Serializes self to a protobuf. :return: """ return OptimizerService_pb2.OptimizationProblem( ParameterSpace=OptimizerService_pb2.Hypergrid( HypergridJsonString=json.dumps(self.parameter_space, cls=HypergridJsonEncoder)), ObjectiveSpace=OptimizerService_pb2.Hypergrid( HypergridJsonString=json.dumps(self.objective_space, cls=HypergridJsonEncoder)), Objectives=[ OptimizerService_pb2.Objective(Name=objective.name, Minimize=objective.minimize) for objective in self.objectives ], ContextSpace=None if self.context_space is None else OptimizerService_pb2.Hypergrid(HypergridJsonString=json.dumps( self.context_space, cls=HypergridJsonEncoder)))