diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d1882e2..3d819b19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,7 @@ jobs: fail-fast: false matrix: os: [ "ubuntu-latest", "windows-latest" ] # todo support macos test - python-version: [ "3.8", "3.9", "3.10" ] + python-version: [ "3.8", "3.9", "3.10", "3.11" ] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/openbox/surrogate/base/rf_with_instances_sklearn.py b/openbox/surrogate/base/rf_with_instances_sklearn.py index f8ff35a4..de69f0b2 100644 --- a/openbox/surrogate/base/rf_with_instances_sklearn.py +++ b/openbox/surrogate/base/rf_with_instances_sklearn.py @@ -6,7 +6,7 @@ from sklearn.ensemble import RandomForestRegressor import threading from joblib import Parallel, delayed -from sklearn.utils.fixes import _joblib_parallel_args +# from sklearn.utils.fixes import _joblib_parallel_args from sklearn.utils.validation import check_is_fitted try: from sklearn.ensemble.base import _partition_estimators @@ -20,6 +20,58 @@ from openbox.utils.constants import N_TREES +def _joblib_parallel_args(**kwargs): + """Set joblib.Parallel arguments in a compatible way for 0.11 and 0.12+ + + For joblib 0.11 this maps both ``prefer`` and ``require`` parameters to + a specific ``backend``. + + Parameters + ---------- + + prefer : str in {'processes', 'threads'} or None + Soft hint to choose the default backend if no specific backend + was selected with the parallel_backend context manager. + + require : 'sharedmem' or None + Hard condstraint to select the backend. If set to 'sharedmem', + the selected backend will be single-host and thread-based even + if the user asked for a non-thread based backend with + parallel_backend. + + See joblib.Parallel documentation for more details + """ + import joblib + + if joblib.__version__ >= "0.12": + return kwargs + + extra_args = set(kwargs.keys()).difference({"prefer", "require"}) + if extra_args: + raise NotImplementedError( + "unhandled arguments %s with joblib %s" + % (list(extra_args), joblib.__version__) + ) + args = {} + if "prefer" in kwargs: + prefer = kwargs["prefer"] + if prefer not in ["threads", "processes", None]: + raise ValueError("prefer=%s is not supported" % prefer) + args["backend"] = { + "threads": "threading", + "processes": "multiprocessing", + None: None, + }[prefer] + + if "require" in kwargs: + require = kwargs["require"] + if require not in [None, "sharedmem"]: + raise ValueError("require=%s is not supported" % require) + if require == "sharedmem": + args["backend"] = "threading" + return args + + def _collect_prediction(predict, X, out, lock): """ This is a utility function for joblib's Parallel. diff --git a/requirements/main.txt b/requirements/main.txt index 22c09a1d..dfc8a1f0 100644 --- a/requirements/main.txt +++ b/requirements/main.txt @@ -9,9 +9,9 @@ matplotlib pandas numpy>=1.7.1 scipy>=0.18.1,<=1.10.1 -scikit-learn>=0.21.3,<=1.0.2 +scikit-learn>=0.21.3,<=1.1.3 scikit-optimize>=0.9 -ConfigSpace>=0.4.20,<=0.6 +ConfigSpace>=0.4.20,<=0.6.1 emcee statsmodels platypus-opt==1.0.4 \ No newline at end of file