automl / ConfigSpace

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

TypeError: Expected int, got numpy.ndarray when sampling OrdinalHyperparameter #338

Open hury07 opened 11 months ago

hury07 commented 11 months ago

Hello, It seems that there is an error to sample OrdinalHyperparameter. The code is given as follows to replicate the error.

from ConfigSpace import ConfigurationSpace, CategoricalHyperparameter, OrdinalHyperparameter

cs = ConfigurationSpace(
    name="test",
    seed=1234,
    space={
        "Oil_solvent": CategoricalHyperparameter("Oil_solvent", ["Squalene", "Mineral oil", "Paraffin liquid"]),
        "Phospholipid_concentration": OrdinalHyperparameter("Phospholipid_concentration", [200, 300, 400, 500, 600]),
    }
)

print(cs.sample_configuration())
Traceback (most recent call last):
  File "/home/hury/Projects/AutoDOE/tests/decision_space.py", line 12, in <module>
    print(cs.sample_configuration())
  File "/home/hury/mambaforge/envs/autodoe/lib/python3.10/site-packages/ConfigSpace/configuration_space.py", line 880, in sample_configuration
    vector[:, i] = hyperparameter._sample(self.random, missing)
  File "ConfigSpace/hyperparameters/ordinal.pyx", line 241, in ConfigSpace.hyperparameters.ordinal.OrdinalHyperparameter._sample
TypeError: Expected int, got numpy.ndarray

ConfigSpace version: v0.7.2

eismont21 commented 11 months ago

Downgrade configspace to version 0.7.1. It has helped me

eddiebergman commented 11 months ago

Hiyo, thanks for the note on downgrading. Turns out it seems to be an issue with a newer version of Cython and simply downgrading Cython seems to cause other issues.

We've removed 0.7.2 from PyPI for now.

sarahec commented 2 months ago

Matching Cython issue: cython/cython#5750

eddiebergman commented 2 months ago

Hi,

Just want to report that this issue if fixed in PR #346 which removes Cython. Hopefully we can release sometime next week.