def update_datarun_method_config(datarun_id, method, hyperparameter_configs): """ Update the config of a method of a datarun by only providing the hyperparameters. This method would also do some simple legality check on the provided hyperparameters. The argument hyperparameter_configs is a dict like: {hp: {'type': ..., 'range': ...}}) """ assert isinstance(hyperparameter_configs, dict) config = load_datarun_method_config(datarun_id, method) hyperparmeters = config['hyperparameters'] for hp, val in hyperparameter_configs.items(): if hp not in hyperparmeters: warnings.warn( 'Trying to update unknown parameter %s for method %s' % (hp, method)) if val['type'] != hyperparmeters[hp]['type']: raise ValueError( 'Hyperparameter type mismatch! Trying to update %s with type %s as type %s!' % (hp, hyperparmeters[hp]['type'], val['type'])) hyperparmeters[hp] = val save_datarun_method_config(datarun_id, method, config) _method = NewMethod(method, get_datarun_config_path(datarun_id)) parts = _method.get_hyperpartitions() db = get_db() for part in parts: # if necessary, create a new datarun for each hyperpartition. # This setting is useful for debugging. # create a new hyperpartition in the database query = db.session.query(db.Hyperpartition).filter( db.Hyperpartition.datarun_id == datarun_id) query = query.filter(db.Hyperpartition.method == method) # We assume that the categorical and constants are fixed query = query.filter(db.Hyperpartition.categorical_hyperparameters_64 == object_to_base_64(part.categoricals)) query = query.filter(db.Hyperpartition.constant_hyperparameters_64 == object_to_base_64(part.constants)) # query = query.filter(db.Hyperpartition.tunable_hyperparameters_64 != object_to_base_64(part.tunables)) hps = list(query.all()) if len(hps) == 1: hp = hps[0] hp.tunables = part.tunables elif len(hps) > 1: raise ValueError('Multiple hyperpartitions found!') db.session.commit()
def hyperparameter_values(self, value): self.hyperparameter_values_64 = object_to_base_64(value)
def tunables(self, value): self.tunable_hyperparameters_64 = object_to_base_64(value)
def constants(self, value): self.constant_hyperparameters_64 = object_to_base_64(value)
def trainable_params(self, value): self.trainable_params64 = object_to_base_64(value)
def categoricals(self, value): self.categorical_hyperparameters_64 = object_to_base_64(value)
def params(self, value): self.params64 = object_to_base_64(value)
def constants(self, value): self.constants64 = object_to_base_64(value)
def tunables(self, value): self.tunables64 = object_to_base_64(value)
def categoricals(self, value): self.categoricals64 = object_to_base_64(value)
def wrapper(self, value): self.wrapper64 = object_to_base_64(value)