Skip to content

Commit f09a318

Browse files
saitcakmakfacebook-github-bot
authored andcommitted
Remove get_GPEI factory function (facebook#3019)
Summary: Pull Request resolved: facebook#3019 Factory functions mostly duplicate an existing registry entry and are not recommended. This diff cleans up `get_GPEI` factory function, which re-packages legacy GPEI. Reviewed By: dme65 Differential Revision: D65486831 fbshipit-source-id: 11d6a912997ce1f737065e75f5877dfb3b7fb0b3
1 parent f2c2695 commit f09a318

File tree

3 files changed

+4
-56
lines changed

3 files changed

+4
-56
lines changed

ax/modelbridge/factory.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -140,28 +140,6 @@ def get_botorch(
140140
)
141141

142142

143-
def get_GPEI(
144-
experiment: Experiment,
145-
data: Data,
146-
search_space: SearchSpace | None = None,
147-
dtype: torch.dtype = torch.double,
148-
device: torch.device = DEFAULT_TORCH_DEVICE,
149-
) -> TorchModelBridge:
150-
"""Instantiates a GP model that generates points with EI."""
151-
if data.df.empty:
152-
raise ValueError("GP+EI BotorchModel requires non-empty data.")
153-
return checked_cast(
154-
TorchModelBridge,
155-
Models.LEGACY_BOTORCH(
156-
experiment=experiment,
157-
data=data,
158-
search_space=search_space or experiment.search_space,
159-
torch_dtype=dtype,
160-
torch_device=device,
161-
),
162-
)
163-
164-
165143
def get_factorial(search_space: SearchSpace) -> DiscreteModelBridge:
166144
"""Instantiates a factorial generator."""
167145
return checked_cast(

ax/modelbridge/tests/test_factory.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,21 @@
99
from ax.core.outcome_constraint import ComparisonOp, ObjectiveThreshold
1010
from ax.modelbridge.discrete import DiscreteModelBridge
1111
from ax.modelbridge.factory import (
12-
get_botorch,
1312
get_empirical_bayes_thompson,
1413
get_factorial,
15-
get_GPEI,
1614
get_sobol,
1715
get_thompson,
1816
get_uniform,
1917
)
2018
from ax.modelbridge.random import RandomModelBridge
21-
from ax.modelbridge.torch import TorchModelBridge
2219
from ax.models.discrete.eb_thompson import EmpiricalBayesThompsonSampler
2320
from ax.models.discrete.thompson import ThompsonSampler
2421
from ax.utils.common.testutils import TestCase
2522
from ax.utils.testing.core_stubs import (
2623
get_branin_experiment,
2724
get_branin_experiment_with_multi_objective,
28-
get_branin_optimization_config,
2925
get_factorial_experiment,
3026
)
31-
from ax.utils.testing.mock import mock_botorch_optimize
3227

3328

3429
# pyre-fixme[3]: Return type must be annotated.
@@ -52,31 +47,6 @@ def get_multi_obj_exp_and_opt_config():
5247

5348

5449
class ModelBridgeFactoryTestSingleObjective(TestCase):
55-
@mock_botorch_optimize
56-
def test_sobol_GPEI(self) -> None:
57-
"""Tests sobol + GPEI instantiation."""
58-
exp = get_branin_experiment()
59-
# Check that factory generates a valid sobol modelbridge.
60-
sobol = get_sobol(search_space=exp.search_space)
61-
self.assertIsInstance(sobol, RandomModelBridge)
62-
for _ in range(5):
63-
sobol_run = sobol.gen(n=1)
64-
exp.new_batch_trial().add_generator_run(sobol_run).run().mark_completed()
65-
# Check that factory generates a valid GP+EI modelbridge.
66-
exp.optimization_config = get_branin_optimization_config()
67-
gpei = get_GPEI(experiment=exp, data=exp.fetch_data())
68-
self.assertIsInstance(gpei, TorchModelBridge)
69-
gpei = get_GPEI(
70-
experiment=exp, data=exp.fetch_data(), search_space=exp.search_space
71-
)
72-
self.assertIsInstance(gpei, TorchModelBridge)
73-
botorch = get_botorch(experiment=exp, data=exp.fetch_data())
74-
self.assertIsInstance(botorch, TorchModelBridge)
75-
76-
# Check that .gen returns without failure
77-
gpei_run = gpei.gen(n=1)
78-
self.assertEqual(len(gpei_run.arms), 1)
79-
8050
def test_model_kwargs(self) -> None:
8151
"""Tests that model kwargs are passed correctly."""
8252
exp = get_branin_experiment()

docs/models.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Additional arguments can be passed to [`get_sobol`](../api/modelbridge.html#ax.m
2222
Sobol sequences are typically used to select initialization points, and this model does not implement [`predict`](../api/modelbridge.html#ax.modelbridge.base.ModelBridge.predict). It can be used on search spaces with any combination of discrete and continuous parameters.
2323

2424
#### Gaussian Process with EI
25-
Gaussian Processes (GPs) are used for [Bayesian Optimization](bayesopt.md) in Ax, the [`get_GPEI`](../api/modelbridge.html#ax.modelbridge.factory.get_gpei) function constructs a model that fits a GP to the data, and uses the EI acquisition function to generate new points on calls to [`gen`](../api/modelbridge.html#ax.modelbridge.base.ModelBridge.gen). This code fits a GP and generates a batch of 5 points which maximizes EI:
25+
Gaussian Processes (GPs) are used for [Bayesian Optimization](bayesopt.md) in Ax, the [`Models.BOTORCH_MODULAR`](../api/modelbridge.html#ax.modelbridge.registry.Models) registry entry constructs a modular BoTorch model that fits a GP to the data, and uses qLogNEI (or qLogNEHVI for MOO) acquisition function to generate new points on calls to [`gen`](../api/modelbridge.html#ax.modelbridge.base.ModelBridge.gen). This code fits a GP and generates a batch of 5 points which maximizes EI:
2626
```Python
27-
from ax.modelbridge.factory import get_GPEI
27+
from ax.modelbridge.registry import Models
2828

29-
m = get_GPEI(experiment, data)
29+
m = Models.BOTORCH_MODULAR(experiment=experiment, data=data)
3030
gr = m.gen(n=5, optimization_config=optimization_config)
3131
```
3232

@@ -158,7 +158,7 @@ The primary role of the [`ModelBridge`](../api/modelbridge.html#ax.modelbridge.b
158158

159159
## Transforms
160160

161-
The transformations in the [`ModelBridge`](../api/modelbridge.html#ax.modelbridge.base.ModelBridge) are done by chaining together a set of individual Transform objects. For continuous space models obtained via factory functions ([`get_sobol`](/api/data.html#.data.users.adamobeng.fbsource.fbcode.ax.ax.modelbridge.factory.get_sobol) and [`get_GPEI`](/api/data.html#.data.users.adamobeng.fbsource.fbcode.ax.ax.modelbridge.factory.get_GPEI)), the following transforms will be applied by default, in this sequence:
161+
The transformations in the [`ModelBridge`](../api/modelbridge.html#ax.modelbridge.base.ModelBridge) are done by chaining together a set of individual Transform objects. For continuous space models obtained via factory functions ([`get_sobol`](/api/data.html#.data.users.adamobeng.fbsource.fbcode.ax.ax.modelbridge.factory.get_sobol) and [`Models.BOTORCH_MODULAR`](/api/data.html#.data.users.adamobeng.fbsource.fbcode.ax.ax.modelbridge.registry.Models)), the following transforms will be applied by default, in this sequence:
162162
* [`RemoveFixed`](../api/modelbridge.html#ax.modelbridge.transforms.remove_fixed.RemoveFixed): Remove [`FixedParameters`](../api/core.html#ax.core.parameter.FixedParameter) from the search space.
163163
* [`OrderedChoiceEncode`](../api/modelbridge.html#ax.modelbridge.transforms.choice_encode.OrderedChoiceEncode): [`ChoiceParameters`](../api/core.html#ax.core.parameter.ChoiceParameter) with `is_ordered` set to `True` are encoded as a sequence of integers.
164164
* [`OneHot`](../api/modelbridge.html#ax.modelbridge.transforms.one_hot.OneHot): [`ChoiceParameters`](../api/core.html#ax.core.parameter.ChoiceParameter) with `is_ordered` set to `False` are one-hot encoded.

0 commit comments

Comments
 (0)