ConfigSpace icon indicating copy to clipboard operation
ConfigSpace copied to clipboard

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

Open hury07 opened this issue 2 years ago • 4 comments

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

hury07 avatar Jul 28 '23 08:07 hury07

Downgrade configspace to version 0.7.1. It has helped me

eismont21 avatar Aug 02 '23 15:08 eismont21

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.

eddiebergman avatar Aug 07 '23 09:08 eddiebergman

Matching Cython issue: cython/cython#5750

sarahec avatar Apr 15 '24 00:04 sarahec

Hi,

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

eddiebergman avatar Apr 16 '24 17:04 eddiebergman