diff --git a/bayes_opt/acquisition.py b/bayes_opt/acquisition.py index 7bc47e0b4..4fa7eaa1b 100644 --- a/bayes_opt/acquisition.py +++ b/bayes_opt/acquisition.py @@ -33,8 +33,12 @@ from scipy.stats import norm from sklearn.gaussian_process import GaussianProcessRegressor +from bayes_opt.exception import ( + ConstraintNotSupportedError, + NoValidPointRegisteredError, + TargetSpaceEmptyError, +) from bayes_opt.target_space import TargetSpace -from bayes_opt.util import ConstraintNotSupportedError, NoValidPointRegisteredError, TargetSpaceEmptyError if TYPE_CHECKING: from bayes_opt.constraint import ConstraintModel diff --git a/bayes_opt/exception.py b/bayes_opt/exception.py new file mode 100644 index 000000000..628e20d77 --- /dev/null +++ b/bayes_opt/exception.py @@ -0,0 +1,31 @@ +"""This module contains custom exceptions for Bayesian Optimization.""" + +from __future__ import annotations + +__all__ = [ + "BayesianOptimizationError", + "NotUniqueError", + "ConstraintNotSupportedError", + "NoValidPointRegisteredError", + "TargetSpaceEmptyError", +] + + +class BayesianOptimizationError(Exception): + """Base class for exceptions in the Bayesian Optimization.""" + + +class NotUniqueError(BayesianOptimizationError): + """A point is non-unique.""" + + +class ConstraintNotSupportedError(BayesianOptimizationError): + """Raised when constrained optimization is not supported.""" + + +class NoValidPointRegisteredError(BayesianOptimizationError): + """Raised when an acquisition function depends on previous points but none are registered.""" + + +class TargetSpaceEmptyError(BayesianOptimizationError): + """Raised when the target space is empty.""" diff --git a/bayes_opt/target_space.py b/bayes_opt/target_space.py index c6f516947..04bc3f13b 100644 --- a/bayes_opt/target_space.py +++ b/bayes_opt/target_space.py @@ -7,7 +7,8 @@ import numpy as np from colorama import Fore -from bayes_opt.util import NotUniqueError, ensure_rng +from bayes_opt.exception import NotUniqueError +from bayes_opt.util import ensure_rng def _hashable(x): diff --git a/bayes_opt/util.py b/bayes_opt/util.py index 80e9c7084..b1e745b13 100644 --- a/bayes_opt/util.py +++ b/bayes_opt/util.py @@ -7,21 +7,7 @@ import numpy as np - -class NotUniqueError(Exception): - """A point is non-unique.""" - - -class ConstraintNotSupportedError(Exception): - """Raised when constrained optimization is not supported.""" - - -class NoValidPointRegisteredError(Exception): - """Raised when an acquisition function depends on previous points but none are registered.""" - - -class TargetSpaceEmptyError(Exception): - """Raised when the target space is empty.""" +from bayes_opt.exception import NotUniqueError def load_logs(optimizer, logs): diff --git a/docsrc/index.rst b/docsrc/index.rst index d6f9384d0..ac664a582 100644 --- a/docsrc/index.rst +++ b/docsrc/index.rst @@ -26,6 +26,7 @@ reference/constraint reference/domain_reduction reference/target_space + reference/exception reference/other .. raw:: html diff --git a/docsrc/reference/exception.rst b/docsrc/reference/exception.rst new file mode 100644 index 000000000..9315628c9 --- /dev/null +++ b/docsrc/reference/exception.rst @@ -0,0 +1,5 @@ +:py:mod:`bayes_opt.exception` +------------------------------- + +.. automodule:: bayes_opt.exception + :members: diff --git a/tests/test_bayesian_optimization.py b/tests/test_bayesian_optimization.py index 48283ade6..64af3581f 100644 --- a/tests/test_bayesian_optimization.py +++ b/tests/test_bayesian_optimization.py @@ -9,9 +9,9 @@ from bayes_opt import BayesianOptimization, acquisition from bayes_opt.acquisition import AcquisitionFunction from bayes_opt.event import DEFAULT_EVENTS, Events +from bayes_opt.exception import NotUniqueError from bayes_opt.logger import ScreenLogger from bayes_opt.target_space import TargetSpace -from bayes_opt.util import NotUniqueError def target_func(**kwargs): diff --git a/tests/test_target_space.py b/tests/test_target_space.py index ee196a2f1..e1e9163c1 100644 --- a/tests/test_target_space.py +++ b/tests/test_target_space.py @@ -4,8 +4,8 @@ import pytest from bayes_opt.constraint import ConstraintModel +from bayes_opt.exception import NotUniqueError from bayes_opt.target_space import TargetSpace -from bayes_opt.util import NotUniqueError def target_func(**kwargs):