From a95607787db84343a53158b3279ae8b68d5ca661 Mon Sep 17 00:00:00 2001 From: Sebastian Ament Date: Mon, 26 Feb 2024 16:42:54 -0800 Subject: [PATCH] Removing `soft_eval_constraints` Summary: `soft_eval_constraints` has been deprecated for 7 months. This commit removed the function before the next BoTorch release. Reviewed By: Balandat Differential Revision: D54207128 fbshipit-source-id: 07f1bef38990ddf97058a564dec6d7e0d64e46f4 --- botorch/utils/objective.py | 28 ---------------------------- test/utils/test_objective.py | 10 ---------- 2 files changed, 38 deletions(-) diff --git a/botorch/utils/objective.py b/botorch/utils/objective.py index d618cb0b31..277a3bfadd 100644 --- a/botorch/utils/objective.py +++ b/botorch/utils/objective.py @@ -10,8 +10,6 @@ from __future__ import annotations -import warnings - from typing import Callable, List, Optional, Union import torch @@ -182,32 +180,6 @@ def compute_smoothed_feasibility_indicator( return is_feasible if log else is_feasible.exp() -# TODO: deprecate this function -def soft_eval_constraint(lhs: Tensor, eta: float = 1e-3) -> Tensor: - r"""Element-wise evaluation of a constraint in a 'soft' fashion - - `value(x) = 1 / (1 + exp(x / eta))` - - Args: - lhs: The left hand side of the constraint `lhs <= 0`. - eta: The temperature parameter of the softmax function. As eta - decreases, this approximates the Heaviside step function. - - Returns: - Element-wise 'soft' feasibility indicator of the same shape as `lhs`. - For each element `x`, `value(x) -> 0` as `x` becomes positive, and - `value(x) -> 1` as x becomes negative. - """ - warnings.warn( - "`soft_eval_constraint` is deprecated. Please consider `torch.utils.sigmoid` " - + "with its `fat` and `log` options to compute feasibility indicators.", - DeprecationWarning, - ) - if eta <= 0: - raise ValueError("eta must be positive.") - return torch.sigmoid(-lhs / eta) - - def apply_constraints( obj: Tensor, constraints: List[Callable[[Tensor], Tensor]], diff --git a/test/utils/test_objective.py b/test/utils/test_objective.py index 1596546ab9..19f779007d 100644 --- a/test/utils/test_objective.py +++ b/test/utils/test_objective.py @@ -10,7 +10,6 @@ from botorch.utils.objective import ( compute_feasibility_indicator, compute_smoothed_feasibility_indicator, - soft_eval_constraint, ) from botorch.utils.testing import BotorchTestCase from torch import Tensor @@ -75,15 +74,6 @@ def test_apply_constraints(self): eta=0.0, ) - # soft_eval_constraint is not in the path of apply_constraints, adding this test - # for coverage. - with self.assertRaisesRegex(ValueError, "eta must be positive."): - soft_eval_constraint(lhs=obj, eta=0.0) - ind = soft_eval_constraint(lhs=ones_f(samples), eta=1e-6) - self.assertAllClose(ind, torch.zeros_like(ind)) - ind = soft_eval_constraint(lhs=-ones_f(samples), eta=1e-6) - self.assertAllClose(ind, torch.ones_like(ind)) - def test_apply_constraints_multi_output(self): # nonnegative objective, one constraint tkwargs = {"device": self.device}