Skip to content

Commit 04670dd

Browse files
authored
add module exception (#506)
* feat: exceptions * fix: rename exceptions -> exception * fix tests * docs: add reference/exception.rst
1 parent 9a315ed commit 04670dd

File tree

8 files changed

+47
-19
lines changed

8 files changed

+47
-19
lines changed

bayes_opt/acquisition.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
from scipy.stats import norm
3434
from sklearn.gaussian_process import GaussianProcessRegressor
3535

36+
from bayes_opt.exception import (
37+
ConstraintNotSupportedError,
38+
NoValidPointRegisteredError,
39+
TargetSpaceEmptyError,
40+
)
3641
from bayes_opt.target_space import TargetSpace
37-
from bayes_opt.util import ConstraintNotSupportedError, NoValidPointRegisteredError, TargetSpaceEmptyError
3842

3943
if TYPE_CHECKING:
4044
from bayes_opt.constraint import ConstraintModel

bayes_opt/exception.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""This module contains custom exceptions for Bayesian Optimization."""
2+
3+
from __future__ import annotations
4+
5+
__all__ = [
6+
"BayesianOptimizationError",
7+
"NotUniqueError",
8+
"ConstraintNotSupportedError",
9+
"NoValidPointRegisteredError",
10+
"TargetSpaceEmptyError",
11+
]
12+
13+
14+
class BayesianOptimizationError(Exception):
15+
"""Base class for exceptions in the Bayesian Optimization."""
16+
17+
18+
class NotUniqueError(BayesianOptimizationError):
19+
"""A point is non-unique."""
20+
21+
22+
class ConstraintNotSupportedError(BayesianOptimizationError):
23+
"""Raised when constrained optimization is not supported."""
24+
25+
26+
class NoValidPointRegisteredError(BayesianOptimizationError):
27+
"""Raised when an acquisition function depends on previous points but none are registered."""
28+
29+
30+
class TargetSpaceEmptyError(BayesianOptimizationError):
31+
"""Raised when the target space is empty."""

bayes_opt/target_space.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import numpy as np
88
from colorama import Fore
99

10-
from bayes_opt.util import NotUniqueError, ensure_rng
10+
from bayes_opt.exception import NotUniqueError
11+
from bayes_opt.util import ensure_rng
1112

1213

1314
def _hashable(x):

bayes_opt/util.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,7 @@
77

88
import numpy as np
99

10-
11-
class NotUniqueError(Exception):
12-
"""A point is non-unique."""
13-
14-
15-
class ConstraintNotSupportedError(Exception):
16-
"""Raised when constrained optimization is not supported."""
17-
18-
19-
class NoValidPointRegisteredError(Exception):
20-
"""Raised when an acquisition function depends on previous points but none are registered."""
21-
22-
23-
class TargetSpaceEmptyError(Exception):
24-
"""Raised when the target space is empty."""
10+
from bayes_opt.exception import NotUniqueError
2511

2612

2713
def load_logs(optimizer, logs):

docsrc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
reference/constraint
2727
reference/domain_reduction
2828
reference/target_space
29+
reference/exception
2930
reference/other
3031

3132
.. raw:: html

docsrc/reference/exception.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:py:mod:`bayes_opt.exception`
2+
-------------------------------
3+
4+
.. automodule:: bayes_opt.exception
5+
:members:

tests/test_bayesian_optimization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from bayes_opt import BayesianOptimization, acquisition
1010
from bayes_opt.acquisition import AcquisitionFunction
1111
from bayes_opt.event import DEFAULT_EVENTS, Events
12+
from bayes_opt.exception import NotUniqueError
1213
from bayes_opt.logger import ScreenLogger
1314
from bayes_opt.target_space import TargetSpace
14-
from bayes_opt.util import NotUniqueError
1515

1616

1717
def target_func(**kwargs):

tests/test_target_space.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import pytest
55

66
from bayes_opt.constraint import ConstraintModel
7+
from bayes_opt.exception import NotUniqueError
78
from bayes_opt.target_space import TargetSpace
8-
from bayes_opt.util import NotUniqueError
99

1010

1111
def target_func(**kwargs):

0 commit comments

Comments
 (0)