Skip to content

Commit 5dccf83

Browse files
saitcakmakmeta-codesync[bot]
authored andcommitted
Add deprecation warning to AxClient (facebook#4749)
Summary: Pull Request resolved: facebook#4749 Since this was our primary API for a long time, we should signal its removal with a deprecation warning before removing it for good. Reviewed By: mpolson64 Differential Revision: D90390538 Privacy Context Container: L1413903 fbshipit-source-id: 9242f9689507ff8bdbad2d8ae6eaea3ccb03e970
1 parent ceea2cb commit 5dccf83

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ax/service/ax_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ def __init__(
179179
early_stopping_strategy: BaseEarlyStoppingStrategy | None = None,
180180
global_stopping_strategy: BaseGlobalStoppingStrategy | None = None,
181181
) -> None:
182+
if self.__class__.__name__ in ["AxClient", "AxClientInternal"]:
183+
warnings.warn(
184+
"The `AxClient` class is deprecated and will be removed in Ax 1.4.0. "
185+
"Please migrate to the modern Ax API / `Client` class, found under "
186+
"ax/api. For example usage, check out the tutorials at https://ax.dev ",
187+
DeprecationWarning,
188+
stacklevel=2,
189+
)
190+
182191
super().__init__(
183192
db_settings=db_settings,
184193
suppress_all_errors=suppress_storage_errors,

ax/service/tests/test_ax_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import math
1010
import sys
1111
import time
12+
import warnings
1213
from itertools import product
1314
from math import ceil
1415
from typing import Any, TYPE_CHECKING
@@ -267,6 +268,20 @@ def get_client_with_simple_discrete_moo_problem(
267268
class TestAxClient(TestCase):
268269
"""Tests service-like API functionality."""
269270

271+
def test_deprecation_warning(self) -> None:
272+
# Should warn for AxClient but not for arbitrary subclasses.
273+
with self.assertWarnsRegex(
274+
DeprecationWarning, "`AxClient` class is deprecated and will be removed"
275+
):
276+
AxClient()
277+
278+
class TestAxClient(AxClient):
279+
pass
280+
281+
with warnings.catch_warnings(record=True) as ws:
282+
TestAxClient()
283+
self.assertEqual(len(ws), 0)
284+
270285
@mock_botorch_optimize
271286
def test_interruption(self) -> None:
272287
ax_client = AxClient()

0 commit comments

Comments
 (0)