Skip to content

Commit

Permalink
Merge pull request #1296 from automl/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
mfeurer authored Nov 9, 2021
2 parents bd049a5 + 7364c68 commit e21047a
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 54 deletions.
2 changes: 1 addition & 1 deletion autosklearn/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Version information."""

# The following line *must* be the last in the module, exactly as formatted:
__version__ = "0.14.1"
__version__ = "0.14.2"
2 changes: 2 additions & 0 deletions autosklearn/evaluation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import autosklearn.evaluation.train_evaluator
import autosklearn.evaluation.test_evaluator
import autosklearn.evaluation.util
import autosklearn.pipeline.components
from autosklearn.evaluation.train_evaluator import TYPE_ADDITIONAL_INFO
from autosklearn.util.backend import Backend
from autosklearn.util.logging_ import PickableLoggerAdapter, get_named_client_logger
Expand Down Expand Up @@ -336,6 +337,7 @@ def run(
init_params=init_params,
budget=budget,
budget_type=self.budget_type,
additional_components=autosklearn.pipeline.components.base._addons,
)

if self.resampling_strategy != 'test':
Expand Down
11 changes: 11 additions & 0 deletions autosklearn/evaluation/abstract_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import autosklearn.pipeline.classification
import autosklearn.pipeline.regression
from autosklearn.pipeline.components.base import ThirdPartyComponents, _addons
from autosklearn.constants import (
CLASSIFICATION_TASKS,
REGRESSION_TASKS,
Expand Down Expand Up @@ -181,6 +182,7 @@ def __init__(
backend: Backend,
queue: multiprocessing.Queue,
metric: Scorer,
additional_components: Dict[str, ThirdPartyComponents],
port: Optional[int],
configuration: Optional[Union[int, Configuration]] = None,
scoring_functions: Optional[List[Scorer]] = None,
Expand Down Expand Up @@ -268,6 +270,15 @@ def __init__(
self.budget = budget
self.budget_type = budget_type

# Add 3rd-party components to the list of 3rd-party components in case this wasn't done
# before (this happens if we run in parallel and the components are only passed to the
# AbstractEvaluator via the TAE and are not there yet because the worker is in its own
# process).
for key in additional_components:
for component_name, component in additional_components[key].components.items():
if component_name not in _addons[key].components:
_addons[key].add_component(component)

# Please mypy to prevent not defined attr
self.model = self._get_model()

Expand Down
7 changes: 6 additions & 1 deletion autosklearn/evaluation/test_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
AbstractEvaluator,
_fit_and_suppress_warnings,
)
from autosklearn.pipeline.components.base import ThirdPartyComponents
from autosklearn.metrics import calculate_loss, Scorer
from autosklearn.util.backend import Backend

Expand All @@ -29,6 +30,7 @@ def __init__(
backend: Backend,
queue: multiprocessing.Queue,
metric: Scorer,
additional_components: Dict[str, ThirdPartyComponents],
port: Optional[int],
configuration: Optional[Union[int, Configuration]] = None,
scoring_functions: Optional[List[Scorer]] = None,
Expand All @@ -44,6 +46,7 @@ def __init__(
port=port,
configuration=configuration,
metric=metric,
additional_components=additional_components,
scoring_functions=scoring_functions,
seed=seed,
output_y_hat_optimization=False,
Expand Down Expand Up @@ -120,6 +123,7 @@ def eval_t(
exclude: Optional[List[str]],
disable_file_output: bool,
port: Optional[int],
additional_components: Dict[str, ThirdPartyComponents],
init_params: Optional[Dict[str, Any]] = None,
budget: Optional[float] = None,
budget_type: Optional[str] = None,
Expand All @@ -131,6 +135,7 @@ def eval_t(
scoring_functions=scoring_functions,
include=include, exclude=exclude,
disable_file_output=disable_file_output,
init_params=init_params)
additional_components=additional_components,
init_params=init_params,)

evaluator.fit_predict_and_loss()
16 changes: 15 additions & 1 deletion autosklearn/evaluation/train_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
SUPPORTED_TARGET_TYPES,
)
from autosklearn.pipeline.base import PIPELINE_DATA_DTYPE
from autosklearn.pipeline.components.base import IterativeComponent
from autosklearn.pipeline.components.base import IterativeComponent, ThirdPartyComponents
from autosklearn.metrics import Scorer
from autosklearn.util.backend import Backend
from autosklearn.util.logging_ import PicklableClientLogger
Expand Down Expand Up @@ -160,6 +160,7 @@ def __init__(
backend: Backend,
queue: multiprocessing.Queue,
metric: Scorer,
additional_components: Dict[str, ThirdPartyComponents],
port: Optional[int],
configuration: Optional[Union[int, Configuration]] = None,
scoring_functions: Optional[List[Scorer]] = None,
Expand All @@ -184,6 +185,7 @@ def __init__(
port=port,
configuration=configuration,
metric=metric,
additional_components=additional_components,
scoring_functions=scoring_functions,
seed=seed,
output_y_hat_optimization=output_y_hat_optimization,
Expand Down Expand Up @@ -1163,6 +1165,7 @@ def eval_holdout(
exclude: Optional[List[str]],
disable_file_output: bool,
port: Optional[int],
additional_components: Dict[str, ThirdPartyComponents],
init_params: Optional[Dict[str, Any]] = None,
budget: Optional[float] = 100.0,
budget_type: Optional[str] = None,
Expand All @@ -1183,6 +1186,7 @@ def eval_holdout(
include=include,
exclude=exclude,
disable_file_output=disable_file_output,
additional_components=additional_components,
init_params=init_params,
budget=budget,
budget_type=budget_type,
Expand All @@ -1206,6 +1210,7 @@ def eval_iterative_holdout(
exclude: Optional[List[str]],
disable_file_output: bool,
port: Optional[int],
additional_components: Dict[str, ThirdPartyComponents],
init_params: Optional[Dict[str, Any]] = None,
budget: Optional[float] = 100.0,
budget_type: Optional[str] = None,
Expand All @@ -1227,6 +1232,7 @@ def eval_iterative_holdout(
instance=instance,
disable_file_output=disable_file_output,
iterative=True,
additional_components=additional_components,
init_params=init_params,
budget=budget,
budget_type=budget_type
Expand All @@ -1249,6 +1255,7 @@ def eval_partial_cv(
exclude: Optional[List[str]],
disable_file_output: bool,
port: Optional[int],
additional_components: Dict[str, ThirdPartyComponents],
init_params: Optional[Dict[str, Any]] = None,
budget: Optional[float] = None,
budget_type: Optional[str] = None,
Expand All @@ -1274,6 +1281,7 @@ def eval_partial_cv(
include=include,
exclude=exclude,
disable_file_output=disable_file_output,
additional_components=additional_components,
init_params=init_params,
budget=budget,
budget_type=budget_type,
Expand All @@ -1298,6 +1306,7 @@ def eval_partial_cv_iterative(
exclude: Optional[List[str]],
disable_file_output: bool,
port: Optional[int],
additional_components: Dict[str, ThirdPartyComponents],
init_params: Optional[Dict[str, Any]] = None,
budget: Optional[float] = None,
budget_type: Optional[str] = None,
Expand All @@ -1321,6 +1330,7 @@ def eval_partial_cv_iterative(
exclude=exclude,
disable_file_output=disable_file_output,
iterative=True,
additional_components=additional_components,
init_params=init_params,
)

Expand All @@ -1342,6 +1352,7 @@ def eval_cv(
exclude: Optional[List[str]],
disable_file_output: bool,
port: Optional[int],
additional_components: Dict[str, ThirdPartyComponents],
init_params: Optional[Dict[str, Any]] = None,
budget: Optional[float] = None,
budget_type: Optional[str] = None,
Expand All @@ -1362,6 +1373,7 @@ def eval_cv(
include=include,
exclude=exclude,
disable_file_output=disable_file_output,
additional_components=additional_components,
init_params=init_params,
budget=budget,
budget_type=budget_type,
Expand All @@ -1386,6 +1398,7 @@ def eval_iterative_cv(
exclude: Optional[List[str]],
disable_file_output: bool,
port: Optional[int],
additional_components: Dict[str, ThirdPartyComponents],
init_params: Optional[Dict[str, Any]] = None,
budget: Optional[float] = None,
budget_type: Optional[str] = None,
Expand All @@ -1406,6 +1419,7 @@ def eval_iterative_cv(
exclude=exclude,
disable_file_output=disable_file_output,
port=port,
additional_components=additional_components,
init_params=init_params,
budget=budget,
budget_type=budget_type,
Expand Down
3 changes: 3 additions & 0 deletions autosklearn/pipeline/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import inspect
import pkgutil
import sys
from typing import Dict

from sklearn.base import BaseEstimator, TransformerMixin

from autosklearn.pipeline.constants import SPARSE

_addons = dict() # type: Dict[str, 'ThirdPartyComponents']


def find_components(package, directory, base_class):
components = OrderedDict()
Expand Down
9 changes: 5 additions & 4 deletions autosklearn/pipeline/components/classification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
import os

from ..base import AutoSklearnClassificationAlgorithm, find_components, \
ThirdPartyComponents, AutoSklearnChoice
ThirdPartyComponents, AutoSklearnChoice, _addons
from ConfigSpace.configuration_space import ConfigurationSpace
from ConfigSpace.hyperparameters import CategoricalHyperparameter

classifier_directory = os.path.split(__file__)[0]
_classifiers = find_components(__package__,
classifier_directory,
AutoSklearnClassificationAlgorithm)
_addons = ThirdPartyComponents(AutoSklearnClassificationAlgorithm)
additional_components = ThirdPartyComponents(AutoSklearnClassificationAlgorithm)
_addons['classification'] = additional_components


def add_classifier(classifier: Type[AutoSklearnClassificationAlgorithm]) -> None:
_addons.add_component(classifier)
additional_components.add_component(classifier)


class ClassifierChoice(AutoSklearnChoice):
Expand All @@ -26,7 +27,7 @@ class ClassifierChoice(AutoSklearnChoice):
def get_components(cls):
components = OrderedDict()
components.update(_classifiers)
components.update(_addons.components)
components.update(additional_components.components)
return components

def get_available_components(cls, dataset_properties=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
from sklearn.base import BaseEstimator

from ...base import AutoSklearnPreprocessingAlgorithm, find_components, \
ThirdPartyComponents, AutoSklearnChoice
ThirdPartyComponents, AutoSklearnChoice, _addons

from autosklearn.pipeline.base import DATASET_PROPERTIES_TYPE, PIPELINE_DATA_DTYPE

ohe_directory = os.path.split(__file__)[0]
_ohes = find_components(__package__,
ohe_directory,
AutoSklearnPreprocessingAlgorithm)
_addons = ThirdPartyComponents(AutoSklearnPreprocessingAlgorithm)
additional_components = ThirdPartyComponents(AutoSklearnPreprocessingAlgorithm)
_addons['data_preprocessing.categorical_encoding'] = additional_components


def add_ohe(ohe: 'OHEChoice') -> None:
_addons.add_component(ohe)
additional_components.add_component(ohe)


class OHEChoice(AutoSklearnChoice):
Expand All @@ -31,7 +32,7 @@ class OHEChoice(AutoSklearnChoice):
def get_components(cls: BaseEstimator) -> Dict[str, BaseEstimator]:
components: Dict[str, BaseEstimator] = OrderedDict()
components.update(_ohes)
components.update(_addons.components)
components.update(additional_components.components)
return components

def get_hyperparameter_search_space(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ConfigSpace.hyperparameters import CategoricalHyperparameter

from ...base import AutoSklearnPreprocessingAlgorithm, find_components, \
ThirdPartyComponents, AutoSklearnChoice
ThirdPartyComponents, AutoSklearnChoice, _addons

from sklearn.base import BaseEstimator

Expand All @@ -17,11 +17,12 @@
mc_directory = os.path.split(__file__)[0]
_mcs = find_components(
__package__, mc_directory, AutoSklearnPreprocessingAlgorithm)
_addons = ThirdPartyComponents(AutoSklearnPreprocessingAlgorithm)
additional_components = ThirdPartyComponents(AutoSklearnPreprocessingAlgorithm)
_addons['data_preprocessing.minority_coalescense'] = additional_components


def add_mc(mc: BaseEstimator) -> None:
_addons.add_component(mc)
additional_components.add_component(mc)


class CoalescenseChoice(AutoSklearnChoice):
Expand All @@ -30,7 +31,7 @@ class CoalescenseChoice(AutoSklearnChoice):
def get_components(cls: BaseEstimator) -> Dict[str, BaseEstimator]:
components: Dict[str, BaseEstimator] = OrderedDict()
components.update(_mcs)
components.update(_addons.components)
components.update(additional_components.components)
return components

def get_hyperparameter_search_space(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sklearn.base import BaseEstimator

from ...base import AutoSklearnPreprocessingAlgorithm, find_components, \
ThirdPartyComponents, AutoSklearnChoice
ThirdPartyComponents, AutoSklearnChoice, _addons
from autosklearn.pipeline.base import DATASET_PROPERTIES_TYPE, PIPELINE_DATA_DTYPE
from autosklearn.pipeline.components.data_preprocessing.rescaling.abstract_rescaling import (
Rescaling
Expand All @@ -19,11 +19,12 @@
_rescalers = find_components(__package__,
rescaling_directory,
AutoSklearnPreprocessingAlgorithm)
_addons = ThirdPartyComponents(AutoSklearnPreprocessingAlgorithm)
additional_components = ThirdPartyComponents(AutoSklearnPreprocessingAlgorithm)
_addons['data_preprocessing.rescaling'] = additional_components


def add_rescaler(rescaler: Rescaling) -> None:
_addons.add_component(rescaler)
additional_components.add_component(rescaler)


class RescalingChoice(AutoSklearnChoice):
Expand All @@ -32,7 +33,7 @@ class RescalingChoice(AutoSklearnChoice):
def get_components(cls: BaseEstimator) -> Dict[str, BaseEstimator]:
components: Dict[str, BaseEstimator] = OrderedDict()
components.update(_rescalers)
components.update(_addons.components)
components.update(additional_components.components)
return components

def get_hyperparameter_search_space(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
from typing import Type

from ..base import AutoSklearnPreprocessingAlgorithm, find_components, \
ThirdPartyComponents, AutoSklearnChoice
ThirdPartyComponents, AutoSklearnChoice, _addons
from ConfigSpace.configuration_space import ConfigurationSpace
from ConfigSpace.hyperparameters import CategoricalHyperparameter

classifier_directory = os.path.split(__file__)[0]
_preprocessors = find_components(__package__,
classifier_directory,
AutoSklearnPreprocessingAlgorithm)
_addons = ThirdPartyComponents(AutoSklearnPreprocessingAlgorithm)
additional_components = ThirdPartyComponents(AutoSklearnPreprocessingAlgorithm)
_addons['feature_preprocessing'] = additional_components


def add_preprocessor(preprocessor: Type[AutoSklearnPreprocessingAlgorithm]) -> None:
_addons.add_component(preprocessor)
additional_components.add_component(preprocessor)


class FeaturePreprocessorChoice(AutoSklearnChoice):
Expand All @@ -24,7 +25,7 @@ class FeaturePreprocessorChoice(AutoSklearnChoice):
def get_components(cls):
components = OrderedDict()
components.update(_preprocessors)
components.update(_addons.components)
components.update(additional_components.components)
return components

def get_available_components(self, dataset_properties=None,
Expand Down
Loading

0 comments on commit e21047a

Please sign in to comment.