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

Migrate Alebo from code deprecated in closures refactor #1906

Closed
wants to merge 2 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
2 changes: 2 additions & 0 deletions ax/models/random/alebo_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# LICENSE file in the root directory of this source tree.

from typing import Callable, Dict, List, Optional, Tuple
from warnings import warn

import numpy as np
from ax.models.random.uniform import UniformGenerator
Expand Down Expand Up @@ -43,6 +44,7 @@ def __init__(
init_bound: int = 16,
seed: Optional[int] = None,
) -> None:
warn("ALEBOInitializer is deprecated.", DeprecationWarning)
# pyre-fixme[4]: Attribute must be annotated.
self.Q = np.linalg.pinv(B) @ B # Projects down to B and then back up
self.nsamp = nsamp
Expand Down
48 changes: 29 additions & 19 deletions ax/models/tests/test_alebo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def test_ALEBOKernel(self) -> None:
B = torch.tensor(
[[1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0]], dtype=torch.double
)
k = ALEBOKernel(B=B, batch_shape=torch.Size([]))
with self.assertWarnsRegex(DeprecationWarning, "ALEBOKernel is deprecated"):
k = ALEBOKernel(B=B, batch_shape=torch.Size([]))

self.assertEqual(k.d, 2)
self.assertTrue(torch.equal(B, k.B))
Expand Down Expand Up @@ -72,14 +73,18 @@ def test_ALEBOGP(self) -> None:
train_Y = torch.tensor([[1.0], [2.0], [3.0]], dtype=torch.double)
train_Yvar = 0.1 * torch.ones(3, 1, dtype=torch.double)

mll = get_map_model(
B=B,
train_X=train_X,
train_Y=train_Y,
train_Yvar=train_Yvar,
restarts=1,
init_state_dict=None,
)
with self.assertWarnsRegex(
DeprecationWarning,
"`get_map_model` from ax.models.torch.alebo.py is deprecated",
):
mll = get_map_model(
B=B,
train_X=train_X,
train_Y=train_Y,
train_Yvar=train_Yvar,
restarts=1,
init_state_dict=None,
)
m = mll.model
m.eval()
self.assertIsInstance(m, ALEBOGP)
Expand Down Expand Up @@ -116,15 +121,19 @@ def test_ALEBOGP(self) -> None:

# The whole process in get_fitted_model
init_state_dict = m.state_dict()
m_b2 = get_fitted_model(
B=B,
train_X=train_X,
train_Y=train_Y,
train_Yvar=train_Yvar,
restarts=1,
nsamp=5,
init_state_dict=init_state_dict,
)
with self.assertWarnsRegex(
DeprecationWarning,
"`get_fitted_model` from ax.models.torch.alebo.py is deprecated",
):
m_b2 = get_fitted_model(
B=B,
train_X=train_X,
train_Y=train_Y,
train_Yvar=train_Yvar,
restarts=1,
nsamp=5,
init_state_dict=init_state_dict,
)
self.assertEqual(m_b2._aug_batch_shape, torch.Size([5]))

# Test extract_map_statedict
Expand Down Expand Up @@ -171,7 +180,8 @@ def test_Acq(self) -> None:
train_X = torch.tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=torch.double)
train_Y = torch.tensor([[1.0], [2.0], [3.0]], dtype=torch.double)
train_Yvar = 0.1 * torch.ones(3, 1, dtype=torch.double)
m = ALEBOGP(B=B, train_X=train_X, train_Y=train_Y, train_Yvar=train_Yvar)
with self.assertWarnsRegex(DeprecationWarning, "ALEBOGP is deprecated"):
m = ALEBOGP(B=B, train_X=train_X, train_Y=train_Y, train_Yvar=train_Yvar)
m.eval()

objective_weights = torch.tensor([1.0], dtype=torch.double)
Expand Down
Loading