automl / ConfigSpace

Domain specific language for configuration spaces in Python. Useful for hyperparameter optimization and algorithm configuration.
https://automl.github.io/ConfigSpace/
Other
202 stars 93 forks source link

Backwards compatibility for certain previous ConfigSpace objects #384

Closed sarah-segel closed 1 month ago

sarah-segel commented 1 month ago

Some configspaces created with v0.6.1 can't be loaded with v1.1.3, which seems to be due to the backwards compatibility beeing missing for categorical / ordinal / constant hyperparameters in the dictionary.py.

For example, when executing the following example script for the run in DEHB-pendigits-015-0-0.zip:

from pathlib import Path
from ConfigSpace.read_and_write import json as cs_json

if __name__ == "__main__":
    path = Path("runs/DEHB-pendigits-015-0-0")

    with (path / "configspace.json").open("r") as f:
        configspace = cs_json.read(f.read())

I get the following traceback:

Traceback (most recent call last):
  File "/home/skrebs/Projects/Software/DeepCAVE/examples/api/logs/example_script_default_error.py", line 8, in <module>
    configspace = cs_json.read(f.read())
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/typing_extensions.py", line 2853, in wrapper
    return arg(*args, **kwargs)
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/read_and_write/json.py", line 90, in read
    return ConfigurationSpace.from_json(StringIO(jason_string), decoders=decoders)
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/configuration_space.py", line 1128, in from_json
    return cls.from_serialized_dict(d, decoders=decoders)
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/configuration_space.py", line 1058, in from_serialized_dict
    hyperparameters = [hp_decoder(hp, space, hp_decoder) for hp in _hyperparameters]
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/configuration_space.py", line 1058, in <listcomp>
    hyperparameters = [hp_decoder(hp, space, hp_decoder) for hp in _hyperparameters]
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/configuration_space.py", line 1037, in dec
    return decoder(item, cs, _dec)
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/read_and_write/dictionary.py", line 126, in _decode_categorical
    return CategoricalHyperparameter(**item)
TypeError: __init__() got an unexpected keyword argument 'default'

Futhermore, the same run has an entry "probabilities": null in the configspace.json, which leads to (after fixing the error above by changing "default" to "default_value" in configspace.json):

Traceback (most recent call last):
  File "/home/skrebs/Projects/Software/DeepCAVE/examples/api/logs/example_script_default_error.py", line 8, in <module>
    configspace = cs_json.read(f.read())
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/typing_extensions.py", line 2853, in wrapper
    return arg(*args, **kwargs)
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/read_and_write/json.py", line 90, in read
    return ConfigurationSpace.from_json(StringIO(jason_string), decoders=decoders)
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/configuration_space.py", line 1128, in from_json
    return cls.from_serialized_dict(d, decoders=decoders)
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/configuration_space.py", line 1058, in from_serialized_dict
    hyperparameters = [hp_decoder(hp, space, hp_decoder) for hp in _hyperparameters]
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/configuration_space.py", line 1058, in <listcomp>
    hyperparameters = [hp_decoder(hp, space, hp_decoder) for hp in _hyperparameters]
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/configuration_space.py", line 1037, in dec
    return decoder(item, cs, _dec)
  File "/home/skrebs/miniconda3/envs/DeepCAVE/lib/python3.9/site-packages/ConfigSpace/read_and_write/dictionary.py", line 126, in _decode_categorical
    return CategoricalHyperparameter(**item)
TypeError: __init__() got an unexpected keyword argument 'probabilities'

This seem to be the case for runs created with a rather old ConfigSpace version though (~v0.4.21), so probably it is not necessary to make this backwards compatible (I suppose hardly anyone will still use this version).

eddiebergman commented 1 month ago

Okies, I can fix the first one easily then (thought I caught this). Second one I can do the same patchwork to essentially map probabilities to weights which should have the same effect.

eddiebergman commented 1 month ago

Released in 1.1.4 :)