ConfigSpace
ConfigSpace copied to clipboard
[Bug] UniformFloatHyperparameter Typing check bug
I noticed there was a bug in the typing check when I tried to install it in a ppc64le architecture supercomputer. The ConfigSpace version I am using is 0.7.2. When running the following example code,
import ConfigSpace.hyperparameters as CSH
u = CSH.UniformIntegerHyperparameter("u", 1, 10, default_value=1)
An error will be given:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[7], line 2
1 import ConfigSpace.hyperparameters as CSH
----> 2 u = CSH.UniformIntegerHyperparameter("u", 1, 10, default_value=int(1))
File /nobackup/users/junhong/anaconda3/envs/pytorch1.12/lib/python3.9/site-packages/ConfigSpace-0.7.2-py3.9-linux-ppc64le.egg/ConfigSpace/hyperparameters/uniform_integer.pyx:82, in ConfigSpace.hyperparameters.uniform_integer.UniformIntegerHyperparameter.__init__()
File /nobackup/users/junhong/anaconda3/envs/pytorch1.12/lib/python3.9/site-packages/ConfigSpace-0.7.2-py3.9-linux-ppc64le.egg/ConfigSpace/hyperparameters/uniform_float.pyx:62, in ConfigSpace.hyperparameters.uniform_float.UniformFloatHyperparameter.__init__()
TypeError: Argument 'default_value' has incorrect type (expected float, got int)
I tried to reproduce it on my personal laptop with x86/x64 architecture, but it didn't show up. After a deep dive into the code, I found that line 62 in uniform_float.pyx is a default value checking: self.default_value = self.check_default(default_value). At line 14, we can see that the default value could be both integer or float value: default_value: Union[int, float, None] = None. But the type checking function def check_default(self, default_value: Optional[float]) -> float: only allow float value parameter.
I eventually fixed this by changing the definition to def check_default(self, default_value: Optional[Union[int, float]]) -> float:. I think there might be similar issues in the other place in the codebase.