Repository: microsoft/MLOS

Issue:
numpy 1.24 int attribute errors with skopt
```
[gw1] FAILED mlos_core/mlos_core/tests/optimizers/bayesian_optimizers_test.py::test_context_not_implemented_error[SkoptOptimizer-kwargs1] 

=================================== FAILURES ===================================
__________ test_context_not_implemented_error[SkoptOptimizer-kwargs1] __________
[gw1] linux -- Python 3.10.10 /opt/conda/envs/mlos_core/bin/python

configuration_space = Configuration space object:
  Hyperparameters:
    x, Type: UniformFloat, Range: [0.0, 1.0], Default: 0.5
    y, Type: Categorical, Choices: {a, b, c}, Default: a
    z, Type: UniformInteger, Range: [0, 10], Default: 5

optimizer_class = <class 'mlos_core.optimizers.bayesian_optimizers.SkoptOptimizer'>
kwargs = {'base_estimator': 'gp'}

    @pytest.mark.parametrize(('optimizer_class', 'kwargs'), [
        (EmukitOptimizer, {}),
        (SkoptOptimizer, {'base_estimator': 'gp'}),
    ])
    def test_context_not_implemented_error(configuration_space: CS.ConfigurationSpace,
                                           optimizer_class: Type[BaseOptimizer], kwargs):
        """
        Make sure we raise exceptions for the functionality that has not been implemented yet.
        """
        optimizer = optimizer_class(configuration_space, **kwargs)
>       suggestion = optimizer.suggest()

configuration_space = Configuration space object:
  Hyperparameters:
    x, Type: UniformFloat, Range: [0.0, 1.0], Default: 0.5
    y, Type: Categorical, Choices: {a, b, c}, Default: a
    z, Type: UniformInteger, Range: [0, 10], Default: 5

kwargs     = {'base_estimator': 'gp'}
optimizer  = SkoptOptimizer(parameter_space=Configuration space object:
  Hyperparameters:
    x, Type: UniformFloat, Range: [0.0, ... 0.5
    y, Type: Categorical, Choices: {a, b, c}, Default: a
    z, Type: UniformInteger, Range: [0, 10], Default: 5
)
optimizer_class = <class 'mlos_core.optimizers.bayesian_optimizers.SkoptOptimizer'>

mlos_core/mlos_core/tests/optimizers/bayesian_optimizers_test.py:29: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
mlos_core/mlos_core/optimizers/optimizer.py:103: in suggest
    configuration = self._suggest(context)
        context    = None
        X          = [0.7713214[54](https://github.com/microsoft/MLOS/actions/runs/4612712020/jobs/8153933182?pr=291#step:11:55)76418[61](https://github.com/microsoft/MLOS/actions/runs/4612712020/jobs/8153933182?pr=291#step:11:62)]
        self       = <skopt.space.transformers.Pipeline object at 0x7f2214d0c070>
        transformer = <skopt.space.transformers.Normalize object at 0x7f2214d0e290>
/opt/conda/envs/mlos_core/lib/python3.10/site-packages/skopt/space/transformers.py:275: in inverse_transform
    return np.round(X_orig).astype(np.int)
        X          = array([0.77132145])
        X_orig     = array([1.542[64](https://github.com/microsoft/MLOS/actions/runs/4612712020/jobs/8153933182?pr=291#step:11:65)291])
        self       = <skopt.space.transformers.Normalize object at 0x7f2214d0e2[90](https://github.com/microsoft/MLOS/actions/runs/4612712020/jobs/8153933182?pr=291#step:11:91)>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

attr = 'int'

    def __getattr__(attr):
        # Warn for expired attributes, and return a dummy function
        # that always raises an exception.
        import warnings
        try:
            msg = __expired_functions__[attr]
        except KeyError:
            pass
        else:
            warnings.warn(msg, DeprecationWarning, stacklevel=2)
    
            def _expired(*args, **kwds):
                raise RuntimeError(msg)
    
            return _expired
    
        # Emit warnings for deprecated attributes
        try:
            val, msg = __deprecated_attrs__[attr]
        except KeyError:
            pass
        else:
            warnings.warn(msg, DeprecationWarning, stacklevel=2)
            return val
    
        if attr in __future_scalars__:
            # And future warnings for those that will change, but also give
            # the AttributeError
            warnings.warn(
                f"In the future `np.{attr}` will be defined as the "
                "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    
        if attr in __former_attrs__:
>           raise AttributeError(__former_attrs__[attr])
E           AttributeError: module 'numpy' has no attribute 'int'.
E           `np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
E           The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
E               https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

attr       = 'int'
warnings   = <module 'warnings' from '/opt/conda/envs/mlos_core/lib/python3.10/warnings.py'>

/opt/conda/envs/mlos_core/lib/python3.10/site-packages/numpy/__init__.py:305: AttributeError
```

See Also:
- #291
- #292 
- https://github.com/microsoft/MLOS/blob/1cd609263f5e84008cb75e09b4c8d8355bf84185/mlos_core/setup.py#L29
- https://github.com/microsoft/MLOS/blob/1cd609263f5e84008cb75e09b4c8d8355bf84185/mlos_core/setup.py#L45
- https://github.com/microsoft/MLOS/blob/1cd609263f5e84008cb75e09b4c8d8355bf84185/mlos_core/setup.py#L42


Discussion:
Not sure yet why this is failing in just the devcontainer.
Currently failing off and on, mostly for Windows, but also [Linux](https://github.com/microsoft/MLOS/actions/runs/5259344077/jobs/9504781815#step:10:294) on occasion.  Still not sure what the problem is.  But given there are several PRs in skopt open to fix the issues without any progress, I think the path forward is probably just to deprecate skopt:

https://github.com/scikit-optimize/scikit-optimize/pulls?q=is%3Apr+is%3Aopen+numpy



Resolving patch:
diff --git a/mlos_core/mlos_core/optimizers/random_optimizer.py b/mlos_core/mlos_core/optimizers/random_optimizer.py
--- a/mlos_core/mlos_core/optimizers/random_optimizer.py
+++ b/mlos_core/mlos_core/optimizers/random_optimizer.py
@@ -62,7 +62,7 @@ def _suggest(self, context: Optional[pd.DataFrame] = None) -> pd.DataFrame:
         if context is not None:
             # not sure how that works here?
             raise NotImplementedError()
-        return pd.DataFrame(self.optimizer_parameter_space.sample_configuration().get_dictionary(), index=[0])
+        return pd.DataFrame(dict(self.optimizer_parameter_space.sample_configuration()), index=[0])
 
     def register_pending(self, configurations: pd.DataFrame,
                          context: Optional[pd.DataFrame] = None) -> None:
diff --git a/mlos_core/mlos_core/spaces/adapters/llamatune.py b/mlos_core/mlos_core/spaces/adapters/llamatune.py
--- a/mlos_core/mlos_core/spaces/adapters/llamatune.py
+++ b/mlos_core/mlos_core/spaces/adapters/llamatune.py
@@ -286,7 +286,7 @@ def _validate_special_param_values(self, special_param_values_dict: dict) -> Non
             if param not in all_parameters:
                 raise ValueError(error_prefix + f"Parameter '{param}' does not exist.")
 
-            hyperparameter = self.orig_parameter_space.get_hyperparameter(param)
+            hyperparameter = self.orig_parameter_space[param]
             if not isinstance(hyperparameter, ConfigSpace.UniformIntegerHyperparameter):
                 raise NotImplementedError(error_prefix + f"Parameter '{param}' is not supported. "
                                           "Only Integer Hyperparameters are currently supported.")
diff --git a/mlos_core/setup.py b/mlos_core/setup.py
--- a/mlos_core/setup.py
+++ b/mlos_core/setup.py
@@ -52,10 +52,10 @@
         '': ['py.typed', '**/*.pyi'],
     },
     install_requires=[
-        'scikit-learn<1.2',     # FIXME: temporarily work around some version mismatch issues (PR 850)
+        'scikit-learn>=1.2',
         'joblib>=1.1.1',        # CVE-2022-21797: scikit-learn dependency, addressed in 1.2.0dev0, which isn't currently released
         'scipy>=1.3.2',
-        'numpy<1.24',           # FIXME: temporarily work around some version mismatch issues (PR 850)
+        'numpy>=1.24',
         'pandas>=1.0.3',
         'ConfigSpace>=0.7.1',
     ],


Test patch: