def compute(self, config, budget, **kwargs): """ Simple example for a compute function The loss is just a the config + some noise (that decreases with the budget) For dramatization, the function can sleep for a given interval to emphasizes the speed ups achievable with parallel workers. Args: config: dictionary containing the sampled configurations by the optimizer budget: (float) amount of time/epochs/etc. the model can use to train Returns: dictionary with mandatory fields: 'loss' (scalar) 'info' (dict) """ params = [] for k, v in config.items(): param = PCSBasedComponentParameter_pb2.PCSBasedParameterProto( key=k, value=str(v)) params.append(param) channel = grpc.insecure_channel("localhost:" + str(self.gRPC_port)) stub = PCSBasedComponentParameter_pb2_grpc.PCSBasedOptimizerServiceStub( channel) cmp = PCSBasedComponentParameter_pb2.PCSBasedComponentProto( name=self.component_name, parameters=params) response = stub.Evaluate(cmp) channel.close() # res = numpy.clip(config['x'] + numpy.random.randn() / budget, config['x'] / 2, 1.5 * config['x']) # config['weka.classifiers.bayes.BayesNet.Q'] # time.sleep(self.sleep_interval) print(response.result) return ({ 'loss': float(response.result ), # this is the a mandatory field to run hyperband 'info': response. result # can be used for any user-defined information - also mandatory })
def compute(self, config, budget, **kwargs): """ Simple example for a compute function The loss is just a the config + some noise (that decreases with the budget) For dramatization, the function can sleep for a given interval to emphasizes the speed ups achievable with parallel workers. Args: config: dictionary containing the sampled configurations by the optimizer budget: (float) amount of time/epochs/etc. the model can use to train Returns: dictionary with mandatory fields: 'loss' (scalar) 'info' (dict) """ with open("worker.log", "a") as file: file.write("Budget " + str(budget) + "\n") params = [] for k, v in config.items(): params.append( PCSBasedComponentParameter_pb2.PCSBasedParameterProto( key=k, value=str(v))) cmp = PCSBasedComponentParameter_pb2.PCSBasedComponentProto( name=str(math.ceil(budget / 1000)), parameters=params) channel = grpc.insecure_channel("localhost:" + str(self.gRPC_port)) stub = PCSBasedComponentParameter_pb2_grpc.PCSBasedOptimizerServiceStub( channel) response = stub.Evaluate(cmp) channel.close() if (response.result < 0): return ({'loss': float(10000), 'info': 'crashed'}) else: return ({'loss': float(response.result), 'info': 'succeeded'})
import PCSBasedComponentParameter_pb2_grpc if __name__ == '__main__': # find parameterfile pcs in scenario f = open("scenario.txt", "r") lines = f.readlines() for line in lines: if line.startswith("paramfile"): componentName = line.replace("paramfile = ", "")[:-5] if line.startswith("gRPC_port"): gRPC_port = line.replace("gRPC_port = ", "").strip() params = [] for i in range(6, len(sys.argv) - 1, 2): param = PCSBasedComponentParameter_pb2.PCSBasedParameterProto( key=sys.argv[i][1:].replace("-", ""), value=sys.argv[i + 1]) params.append(param) channel = grpc.insecure_channel("localhost:" + gRPC_port) stub = PCSBasedComponentParameter_pb2_grpc.PCSBasedOptimizerServiceStub( channel) cmp = PCSBasedComponentParameter_pb2.PCSBasedComponentProto( name=componentName, parameters=params) response = stub.Evaluate(cmp) channel.close() f = open("testout.txt", "a") f.write("### start run ###\n") for arg in sys.argv: