Beispiel #1
0
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()
Beispiel #2
0
 def hyperparameter_values(self, value):
     self.hyperparameter_values_64 = object_to_base_64(value)
Beispiel #3
0
 def tunables(self, value):
     self.tunable_hyperparameters_64 = object_to_base_64(value)
Beispiel #4
0
 def constants(self, value):
     self.constant_hyperparameters_64 = object_to_base_64(value)
Beispiel #5
0
 def trainable_params(self, value):
     self.trainable_params64 = object_to_base_64(value)
Beispiel #6
0
 def categoricals(self, value):
     self.categorical_hyperparameters_64 = object_to_base_64(value)
Beispiel #7
0
 def params(self, value):
     self.params64 = object_to_base_64(value)
Beispiel #8
0
 def constants(self, value):
     self.constants64 = object_to_base_64(value)
Beispiel #9
0
 def tunables(self, value):
     self.tunables64 = object_to_base_64(value)
Beispiel #10
0
 def categoricals(self, value):
     self.categoricals64 = object_to_base_64(value)
Beispiel #11
0
 def wrapper(self, value):
     self.wrapper64 = object_to_base_64(value)