Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence some warnings in unit tests #2628

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions botorch/generation/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
from botorch.acquisition import AcquisitionFunction
from botorch.exceptions.errors import OptimizationGradientError
from botorch.exceptions.warnings import OptimizationWarning
from botorch.generation.utils import (
_convert_nonlinear_inequality_constraints,
_remove_fixed_features_from_optimization,
)
from botorch.generation.utils import _remove_fixed_features_from_optimization
from botorch.logging import logger
from botorch.optim.parameter_constraints import (
_arrayify,
Expand Down Expand Up @@ -136,16 +133,6 @@ def gen_candidates_scipy(
else:
reduced_domain = None not in fixed_features.values()

if nonlinear_inequality_constraints:
if not isinstance(nonlinear_inequality_constraints, list):
raise ValueError(
"`nonlinear_inequality_constraints` must be a list of tuples, "
f"got {type(nonlinear_inequality_constraints)}."
)
nonlinear_inequality_constraints = _convert_nonlinear_inequality_constraints(
nonlinear_inequality_constraints
)

if reduced_domain:
_no_fixed_features = _remove_fixed_features_from_optimization(
fixed_features=fixed_features,
Expand Down
30 changes: 0 additions & 30 deletions botorch/generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

from __future__ import annotations

import warnings
from collections.abc import Callable
from dataclasses import dataclass

import torch

from botorch.acquisition import AcquisitionFunction, FixedFeatureAcquisitionFunction
from botorch.optim.parameter_constraints import (
_generate_unfixed_lin_constraints,
Expand All @@ -20,34 +18,6 @@
from torch import Tensor


def _convert_nonlinear_inequality_constraints(
nonlinear_inequality_constraints: list[Callable | tuple[Callable, bool]],
) -> list[tuple[Callable, bool]]:
"""Convert legacy defintions of nonlinear inequality constraints into the new
format. Assumes intra-point constraints.
"""
nlcs = []
legacy = False
# return nonlinear_inequality_constraints
for nlc in nonlinear_inequality_constraints:
if callable(nlc):
# old style --> convert
nlcs.append((nlc, True))
legacy = True
else:
nlcs.append(nlc)
if legacy:
warnings.warn(
"The `nonlinear_inequality_constraints` argument is expected "
"take a list of tuples. Passing a list of callables "
"will result in an error in future versions.",
DeprecationWarning,
stacklevel=3,
)

return nlcs


def _flip_sub_unique(x: Tensor, k: int) -> Tensor:
"""Get the first k unique elements of a single-dimensional tensor, traversing the
tensor from the back.
Expand Down
34 changes: 0 additions & 34 deletions botorch/utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from __future__ import annotations

import warnings
from typing import Any

import torch
Expand Down Expand Up @@ -149,39 +148,6 @@ def __eq__(self, other: Any) -> bool:
)


class FixedNoiseDataset(SupervisedDataset):
r"""A SupervisedDataset with an additional field `Yvar` that stipulates
observations variances so that `Y[i] ~ N(f(X[i]), Yvar[i])`.

NOTE: This is deprecated. Use `SupervisedDataset` instead.
Will be removed in a future release (~v0.11).
"""

def __init__(
self,
X: BotorchContainer | Tensor,
Y: BotorchContainer | Tensor,
Yvar: BotorchContainer | Tensor,
feature_names: list[str],
outcome_names: list[str],
validate_init: bool = True,
) -> None:
r"""Initialize a `FixedNoiseDataset` -- deprecated!"""
warnings.warn(
"`FixedNoiseDataset` is deprecated. Use `SupervisedDataset` instead.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(
X=X,
Y=Y,
feature_names=feature_names,
outcome_names=outcome_names,
Yvar=Yvar,
validate_init=validate_init,
)


class RankingDataset(SupervisedDataset):
r"""A SupervisedDataset whose labelled pairs `(x, y)` consist of m-ary combinations
`x ∈ Z^{m}` of elements from a ground set `Z = (z_1, ...)` and ranking vectors
Expand Down
16 changes: 15 additions & 1 deletion botorch/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

import torch
from botorch.acquisition.objective import PosteriorTransform
from botorch.exceptions.warnings import BotorchTensorDimensionWarning, InputDataWarning
from botorch.exceptions.warnings import (
BotorchTensorDimensionWarning,
InputDataWarning,
NumericsWarning,
)
from botorch.models.model import FantasizeMixin, Model
from botorch.posteriors.gpytorch import GPyTorchPosterior
from botorch.posteriors.posterior import Posterior
Expand Down Expand Up @@ -68,6 +72,16 @@ def setUp(self, suppress_input_warnings: bool = True) -> None:
message=r"Data \(input features\) is not",
category=InputDataWarning,
)
warnings.filterwarnings(
"ignore",
message="has known numerical issues",
category=NumericsWarning,
)
warnings.filterwarnings(
"ignore",
message="Model converter code is deprecated",
category=DeprecationWarning,
)

def assertAllClose(
self,
Expand Down
22 changes: 0 additions & 22 deletions test/generation/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,13 @@

from botorch.acquisition import FixedFeatureAcquisitionFunction
from botorch.generation.utils import (
_convert_nonlinear_inequality_constraints,
_flip_sub_unique,
_remove_fixed_features_from_optimization,
)
from botorch.utils.testing import BotorchTestCase, MockAcquisitionFunction


class TestGenerationUtils(BotorchTestCase):
def test_convert_nonlinear_inequality_constraints(self):
def nlc(x):
return x[..., 2]

def nlc2(x):
return x[..., 3]

nlcs = [nlc]
with self.assertWarns(DeprecationWarning):
new_nlcs = _convert_nonlinear_inequality_constraints(nlcs)
self.assertEqual(new_nlcs, [(nlc, True)])

nlcs = [(nlc, False)]
new_nlcs = _convert_nonlinear_inequality_constraints(nlcs)
self.assertEqual(new_nlcs, [(nlc, False)])

nlcs = [(nlc, False), nlc2]
with self.assertWarns(DeprecationWarning):
new_nlcs = _convert_nonlinear_inequality_constraints(nlcs)
self.assertEqual(new_nlcs, [(nlc, False), (nlc2, True)])

def test_flip_sub_unique(self):
for dtype in (torch.float, torch.double):
tkwargs = {"device": self.device, "dtype": dtype}
Expand Down
14 changes: 0 additions & 14 deletions test/optim/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,20 +953,6 @@ def nlc4(x):
)
self.assertEqual(candidates.size(), torch.Size([1, 3]))

# Constraints must be passed in as lists
with self.assertRaisesRegex(
ValueError,
"`nonlinear_inequality_constraints` must be a list of tuples, "
"got <class 'function'>.",
):
optimize_acqf(
acq_function=mock_acq_function,
bounds=bounds,
q=1,
nonlinear_inequality_constraints=nlc1,
num_restarts=num_restarts,
batch_initial_conditions=batch_initial_conditions,
)
# batch_initial_conditions must be feasible
with self.assertRaisesRegex(
ValueError,
Expand Down
14 changes: 1 addition & 13 deletions test/utils/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from botorch.utils.containers import DenseContainer, SliceContainer
from botorch.utils.datasets import (
ContextualDataset,
FixedNoiseDataset,
MultiTaskDataset,
RankingDataset,
SupervisedDataset,
Expand Down Expand Up @@ -129,7 +128,7 @@ def test_fixedNoise(self):
Yvar = rand(3, 1)
feature_names = ["x1", "x2"]
outcome_names = ["y"]
dataset = FixedNoiseDataset(
dataset = SupervisedDataset(
X=X,
Y=Y,
Yvar=Yvar,
Expand All @@ -142,17 +141,6 @@ def test_fixedNoise(self):
self.assertEqual(dataset.feature_names, feature_names)
self.assertEqual(dataset.outcome_names, outcome_names)

with self.assertRaisesRegex(
ValueError, "`Y` and `Yvar`"
), self.assertWarnsRegex(DeprecationWarning, "SupervisedDataset"):
FixedNoiseDataset(
X=X,
Y=Y,
Yvar=Yvar.squeeze(),
feature_names=feature_names,
outcome_names=outcome_names,
)

def test_ranking(self):
# Test `_validate`
X_val = rand(16, 2)
Expand Down