Skip to content

Commit

Permalink
add module exception (#506)
Browse files Browse the repository at this point in the history
* feat: exceptions

* fix: rename exceptions -> exception

* fix tests

* docs: add reference/exception.rst
  • Loading branch information
phi-friday authored Sep 8, 2024
1 parent 9a315ed commit 04670dd
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 19 deletions.
6 changes: 5 additions & 1 deletion bayes_opt/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions bayes_opt/exception.py
Original file line number Diff line number Diff line change
@@ -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."""
3 changes: 2 additions & 1 deletion bayes_opt/target_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 1 addition & 15 deletions bayes_opt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions docsrc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
reference/constraint
reference/domain_reduction
reference/target_space
reference/exception
reference/other

.. raw:: html
Expand Down
5 changes: 5 additions & 0 deletions docsrc/reference/exception.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:py:mod:`bayes_opt.exception`
-------------------------------

.. automodule:: bayes_opt.exception
:members:
2 changes: 1 addition & 1 deletion tests/test_bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_target_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 04670dd

Please sign in to comment.