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

Delete legacy get posterior mean #2613

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
119 changes: 0 additions & 119 deletions ax/models/tests/test_posterior_mean.py

This file was deleted.

17 changes: 0 additions & 17 deletions ax/models/torch/botorch_modular/list_surrogate.py

This file was deleted.

5 changes: 2 additions & 3 deletions ax/models/torch/botorch_modular/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def use_model_list(
):
# Use batch models if allowed
return not allow_batched_models
# If there are multiple Xs and they are not all equal, we
# use `ListSurrogate` and `ModelListGP`.
# If there are multiple Xs and they are not all equal, we use `ModelListGP`.
return True


Expand Down Expand Up @@ -209,7 +208,7 @@ def convert_to_block_design(
"outcomes use `force=True`."
)
warnings.warn(
"Forcing converion of data not complying to a block design "
"Forcing conversion of data not complying to a block design "
"to block design by dropping observations that are not shared "
"between outcomes.",
AxWarning,
Expand Down
84 changes: 0 additions & 84 deletions ax/models/torch/posterior_mean.py

This file was deleted.

5 changes: 2 additions & 3 deletions ax/models/torch/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def setUp(self) -> None:
outcome_names=["y2"],
)
]
self.metric_names_for_list_surrogate = ["y", "y2"]
self.search_space_digest = SearchSpaceDigest(
feature_names=self.feature_names,
bounds=[(0.0, 10.0), (0.0, 10.0), (0.0, 10.0)],
Expand Down Expand Up @@ -280,11 +279,11 @@ def test__construct__converts_non_block(self, _: Mock) -> None:
Y=ds.Y,
Yvar=ds.Yvar,
feature_names=ds.feature_names,
outcome_names=self.metric_names_for_list_surrogate[1:],
outcome_names=["y2"],
),
]
with self.assertWarnsRegex(
AxWarning, "Forcing converion of data not complying to a block design"
AxWarning, "Forcing conversion of data not complying to a block design"
):
self.model.fit(
datasets=datasets,
Expand Down
4 changes: 2 additions & 2 deletions ax/models/torch/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def test_convert_to_block_design(self) -> None:
self.assertTrue(any(issubclass(w.category, AxWarning)) for w in ws)
self.assertTrue(
any(
"Forcing converion of data not complying to a block design"
"Forcing conversion of data not complying to a block design"
in str(w.message)
for w in ws
)
Expand All @@ -476,7 +476,7 @@ def test_convert_to_block_design(self) -> None:
self.assertTrue(any(issubclass(w.category, AxWarning) for w in ws))
self.assertTrue(
any(
"Forcing converion of data not complying to a block design"
"Forcing conversion of data not complying to a block design"
in str(w.message)
for w in ws
)
Expand Down
38 changes: 12 additions & 26 deletions ax/plot/pareto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
from ax.modelbridge.registry import Models
from ax.modelbridge.torch import TorchModelBridge
from ax.modelbridge.transforms.search_space_to_float import SearchSpaceToFloat
from ax.models.torch.posterior_mean import get_PosteriorMean
from ax.models.torch_base import TorchModel
from ax.utils.common.logger import get_logger
from ax.utils.common.typeutils import checked_cast
from ax.utils.stats.statstools import relativize
from botorch.acquisition.monte_carlo import qSimpleRegret
from botorch.utils.multi_objective import is_non_dominated
from botorch.utils.multi_objective.hypervolume import infer_reference_point

Expand Down Expand Up @@ -347,7 +347,6 @@ def compute_posterior_pareto_frontier(
absolute_metrics: Optional[List[str]] = None,
num_points: int = 10,
trial_index: Optional[int] = None,
chebyshev: bool = True,
) -> ParetoFrontierResults:
"""Compute the Pareto frontier between two objectives. For experiments
with batch trials, a trial index or data object must be provided.
Expand All @@ -368,16 +367,10 @@ def compute_posterior_pareto_frontier(
will be in % relative to status_quo).
num_points: The number of points to compute on the
Pareto frontier.
chebyshev: Whether to use augmented_chebyshev_scalarization
when computing Pareto Frontier points.

Returns:
ParetoFrontierResults: A NamedTuple with fields listed in its definition.
"""
model_gen_options = {
"acquisition_function_kwargs": {"chebyshev_scalarization": chebyshev}
}

if (
trial_index is None
and data is None
Expand Down Expand Up @@ -415,7 +408,7 @@ def compute_posterior_pareto_frontier(
# The weights here are just dummy weights that we pass in to construct the
# modelbridge. We set the weight to -1 if `lower_is_better` is `True` and
# 1 otherwise. This code would benefit from a serious revamp.
oc = _build_new_optimization_config(
oc = _build_scalarized_optimization_config(
weights=np.array(
[
-1 if primary_objective.lower_is_better else 1,
Expand All @@ -426,11 +419,11 @@ def compute_posterior_pareto_frontier(
secondary_objective=secondary_objective,
outcome_constraints=outcome_constraints,
)
model = Models.MOO(
model = Models.BOTORCH_MODULAR(
experiment=experiment,
data=data,
acqf_constructor=get_PosteriorMean,
optimization_config=oc,
botorch_acqf_class=qSimpleRegret,
)

status_quo = experiment.status_quo
Expand Down Expand Up @@ -463,16 +456,13 @@ def compute_posterior_pareto_frontier(
weights_list = np.stack([primary_weight, secondary_weight]).transpose()
for weights in weights_list:
outcome_constraints = outcome_constraints
oc = _build_new_optimization_config(
oc = _build_scalarized_optimization_config(
weights=weights,
primary_objective=primary_objective,
secondary_objective=secondary_objective,
outcome_constraints=outcome_constraints,
)
# TODO: (jej) T64002590 Let this serve as a starting point for optimization.
# ex. Add global spacing criterion. Implement on BoTorch side.
# pyre-fixme [6]: Expected different type for model_gen_options
run = model.gen(1, model_gen_options=model_gen_options, optimization_config=oc)
run = model.gen(1, optimization_config=oc)
param_dicts.append(run.arms[0].parameters)

# Call predict on points to get their decomposed metrics.
Expand Down Expand Up @@ -554,19 +544,15 @@ def _validate_outcome_constraints(
)


def _build_new_optimization_config(
# pyre-fixme[2]: Parameter must be annotated.
weights,
# pyre-fixme[2]: Parameter must be annotated.
primary_objective,
# pyre-fixme[2]: Parameter must be annotated.
secondary_objective,
# pyre-fixme[2]: Parameter must be annotated.
outcome_constraints=None,
def _build_scalarized_optimization_config(
weights: np.ndarray,
primary_objective: Metric,
secondary_objective: Metric,
outcome_constraints: Optional[List[OutcomeConstraint]] = None,
) -> MultiObjectiveOptimizationConfig:
obj = ScalarizedObjective(
metrics=[primary_objective, secondary_objective],
weights=weights,
weights=weights.tolist(),
minimize=False,
)
optimization_config = MultiObjectiveOptimizationConfig(
Expand Down
Loading