Skip to content

Commit 1a03b05

Browse files
committed
Disable SDR when non-float parameters are present
1 parent 68909ad commit 1a03b05

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

bayes_opt/domain_reduction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import numpy as np
1616

17+
from bayes_opt.parameter import FloatParameter
1718
from bayes_opt.target_space import TargetSpace
1819

1920
if TYPE_CHECKING:
@@ -90,6 +91,10 @@ def initialize(self, target_space: TargetSpace) -> None:
9091
target_space : TargetSpace
9192
TargetSpace this DomainTransformer operates on.
9293
"""
94+
any_not_float = any([not isinstance(p, FloatParameter) for p in target_space._params_config.values()])
95+
if any_not_float:
96+
msg = "Domain reduction is only supported for all-FloatParameter optimization."
97+
raise ValueError(msg)
9398
# Set the original bounds
9499
self.original_bounds = np.copy(target_space.bounds)
95100
self.bounds = [self.original_bounds]

tests/test_seq_domain_red.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ def test_minimum_window_dict_ordering():
179179
)
180180

181181

182+
def test_mixed_parameters():
183+
"""Ensure that the transformer errors when providing non-float parameters"""
184+
pbounds = {"x": (-10, 10), "y": (-10, 10), "z": (1, 10, int)}
185+
target_space = TargetSpace(target_func=black_box_function, pbounds=pbounds)
186+
with pytest.raises(ValueError):
187+
_ = SequentialDomainReductionTransformer().initialize(target_space)
188+
189+
182190
if __name__ == "__main__":
183191
r"""
184192
CommandLine:

0 commit comments

Comments
 (0)