Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianLara authored Dec 16, 2024
2 parents 020412d + 7715ff4 commit 8f84d61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions botorch/exceptions/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ def __init__(self, /, *args: Any, current_x: npt.NDArray, **kwargs: Any) -> None
"""
super().__init__(*args, **kwargs)
self.current_x = current_x


class InfeasibilityError(BotorchError, ValueError):
r"""Exception raised when infeasibility occurs."""

pass
8 changes: 4 additions & 4 deletions botorch/utils/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import numpy.typing as npt
import scipy
import torch
from botorch.exceptions.errors import BotorchError
from botorch.exceptions.errors import BotorchError, InfeasibilityError
from botorch.exceptions.warnings import UserInputWarning
from botorch.sampling.qmc import NormalQMCEngine
from botorch.utils.transforms import unnormalize
Expand Down Expand Up @@ -249,7 +249,7 @@ def sample_polytope(
"""
# Check that starting point satisfies the constraints.
if not ((slack := A @ x0 - b) <= 0).all():
raise ValueError(
raise InfeasibilityError(
f"Starting point does not satisfy the constraints. Inputs: {A=},"
f"{b=}, {x0=}, A@x0-b={slack}."
)
Expand Down Expand Up @@ -442,7 +442,7 @@ def find_interior_point(
)

if result.status == 2:
raise ValueError(
raise InfeasibilityError(
"No feasible point found. Constraint polytope appears empty. "
+ "Check your constraints."
)
Expand Down Expand Up @@ -524,7 +524,7 @@ def __init__(
if self.feasible(interior_point):
self.x0 = interior_point
else:
raise ValueError("The given input point is not feasible.")
raise InfeasibilityError("The given input point is not feasible.")
else:
self.x0 = self.find_interior_point()

Expand Down
3 changes: 3 additions & 0 deletions test/exceptions/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
BotorchTensorDimensionError,
CandidateGenerationError,
DeprecationError,
InfeasibilityError,
InputDataError,
OptimizationGradientError,
OptimizationTimeoutError,
Expand All @@ -28,6 +29,7 @@ def test_botorch_exception_hierarchy(self):
InputDataError,
UnsupportedError,
BotorchTensorDimensionError,
InfeasibilityError,
]:
self.assertIsInstance(ErrorClass(), BotorchError)

Expand All @@ -38,6 +40,7 @@ def test_raise_botorch_exceptions(self):
CandidateGenerationError,
InputDataError,
UnsupportedError,
InfeasibilityError,
):
with self.assertRaises(ErrorClass):
raise ErrorClass("message")
Expand Down

0 comments on commit 8f84d61

Please sign in to comment.