ConfigSpace icon indicating copy to clipboard operation
ConfigSpace copied to clipboard

`Configuration.get()` always return None if key is not in CS regardless of the provided default value

Open jhj0411jhj opened this issue 2 years ago • 1 comments

Configuration.get() always returns None if key is not in CS regardless of the provided default value. I have to use config.get_dictionary.get() to perform the expected behavior.

ConfigSpace version: 0.4.20, 0.4.21, 0.5.0.

Code:

import ConfigSpace
from ConfigSpace import ConfigurationSpace, UniformIntegerHyperparameter

print(ConfigSpace.__version__)
cs = ConfigurationSpace()
a = UniformIntegerHyperparameter("a", lower=0, upper=1000)
cs.add_hyperparameter(a)

conf = cs.sample_configuration()
print(conf)
print(conf.get('x'))  # None
print(conf.get('x', 123))  # None !!!
print(conf['x'])  # None

jhj0411jhj avatar Apr 06 '22 04:04 jhj0411jhj

Thank you very much for reporting this. I can confirm this issue. I just tried to fix it, however, this results in an endless loop when requesting new neighbors from a configuration, which I don't understand yet. As you currently have a workaround, we'll get back to you when we have taken care of the open pull requests.

mfeurer avatar Apr 19 '22 06:04 mfeurer

This has been fixed in #321

eddiebergman avatar Jun 26 '23 10:06 eddiebergman