Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatible with python3.11 #95

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
54 changes: 53 additions & 1 deletion openbox/surrogate/base/rf_with_instances_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions requirements/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading