Coverage for mlos_core/mlos_core/spaces/adapters/adapter.py: 100%
17 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-07 01:52 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-07 01:52 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""Contains the BaseSpaceAdapter abstract class."""
7from abc import ABCMeta, abstractmethod
9import ConfigSpace
10import pandas as pd
13class BaseSpaceAdapter(metaclass=ABCMeta):
14 """
15 SpaceAdapter abstract class defining the basic interface.
17 Parameters
18 ----------
19 orig_parameter_space : ConfigSpace.ConfigurationSpace
20 The original parameter space to explore.
21 """
23 def __init__(self, *, orig_parameter_space: ConfigSpace.ConfigurationSpace):
24 self._orig_parameter_space: ConfigSpace.ConfigurationSpace = orig_parameter_space
25 self._random_state = orig_parameter_space.random
27 def __repr__(self) -> str:
28 # pylint: disable=consider-using-f-string
29 return "{}(original_parameter_space={}, target_parameter_space={})".format(
30 self.__class__.__name__,
31 self.orig_parameter_space,
32 self.target_parameter_space,
33 )
35 @property
36 def orig_parameter_space(self) -> ConfigSpace.ConfigurationSpace:
37 """Original (user-provided) parameter space to explore."""
38 return self._orig_parameter_space
40 @property
41 @abstractmethod
42 def target_parameter_space(self) -> ConfigSpace.ConfigurationSpace:
43 """Target parameter space that is fed to the underlying optimizer."""
44 pass # pylint: disable=unnecessary-pass # pragma: no cover
46 @abstractmethod
47 def transform(self, configuration: pd.DataFrame) -> pd.DataFrame:
48 """
49 Translates a configuration, which belongs to the target parameter space, to the
50 original parameter space. This method is called by the `suggest` method of the
51 `BaseOptimizer` class.
53 Parameters
54 ----------
55 configuration : pd.DataFrame
56 Pandas dataframe with a single row. Column names are the parameter names
57 of the target parameter space.
59 Returns
60 -------
61 configuration : pd.DataFrame
62 Pandas dataframe with a single row, containing the translated configuration.
63 Column names are the parameter names of the original parameter space.
64 """
65 pass # pylint: disable=unnecessary-pass # pragma: no cover
67 @abstractmethod
68 def inverse_transform(self, configurations: pd.DataFrame) -> pd.DataFrame:
69 """
70 Translates a configuration, which belongs to the original parameter space, to
71 the target parameter space. This method is called by the `register` method of
72 the `BaseOptimizer` class, and performs the inverse operation of
73 `BaseSpaceAdapter.transform` method.
75 Parameters
76 ----------
77 configurations : pd.DataFrame
78 Dataframe of configurations / parameters, which belong to the original parameter space.
79 The columns are the parameter names the original parameter space and the
80 rows are the configurations.
82 Returns
83 -------
84 configurations : pd.DataFrame
85 Dataframe of the translated configurations / parameters.
86 The columns are the parameter names of the target parameter space and
87 the rows are the configurations.
88 """
89 pass # pylint: disable=unnecessary-pass # pragma: no cover