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

Remove parameter constraints when expanding model space in Adapter #3408

Closed
wants to merge 1 commit 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
5 changes: 4 additions & 1 deletion ax/modelbridge/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def __init__(
expand_model_space: If True, expand range parameter bounds in model
space to cover given training data. This will make the modeling
space larger than the search space if training data fall outside
the search space.
the search space. Will also include training points that violate
parameter constraints in the modeling.
fit_out_of_design: If specified, all training data are used.
Otherwise, only in design points are used.
fit_abandoned: Whether data for abandoned arms or trials should be
Expand Down Expand Up @@ -441,6 +442,8 @@ def _set_model_space(self, observations: list[Observation]) -> None:
if isinstance(p, RangeParameter):
p.lower = min(p.lower, min(param_vals[p.name]))
p.upper = max(p.upper, max(param_vals[p.name]))
# Remove parameter constraints from the model space.
self._model_space.set_parameter_constraints([])

def _set_status_quo(
self,
Expand Down
21 changes: 18 additions & 3 deletions ax/modelbridge/tests/test_base_modelbridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from ax.core.observation import ObservationData, ObservationFeatures
from ax.core.optimization_config import OptimizationConfig
from ax.core.parameter import FixedParameter, ParameterType, RangeParameter
from ax.core.parameter_constraint import SumConstraint
from ax.core.search_space import SearchSpace
from ax.exceptions.core import UnsupportedError, UserInputError
from ax.modelbridge.base import (
Expand Down Expand Up @@ -1000,10 +1001,21 @@ def test_SetModelSpace(self) -> None:
experiment.attach_data(get_branin_data_batch(batch=trial, fill_vals=sq_vals))
trial.mark_completed()
data = experiment.lookup_data()
# Make search space with a parameter constraint
ss = experiment.search_space.clone()
ss.set_parameter_constraints(
[
SumConstraint(
parameters=list(ss.parameters.values()),
is_upper_bound=True,
bound=30.0,
)
]
)

# Check that SQ and custom are OOD
m = Adapter(
search_space=experiment.search_space,
search_space=ss,
model=None,
experiment=experiment,
data=data,
Expand All @@ -1014,10 +1026,11 @@ def test_SetModelSpace(self) -> None:
self.assertEqual(set(ood_arms), {"status_quo", "custom"})
self.assertEqual(m.model_space.parameters["x1"].lower, -5.0) # pyre-ignore[16]
self.assertEqual(m.model_space.parameters["x2"].upper, 15.0) # pyre-ignore[16]
self.assertEqual(len(m.model_space.parameter_constraints), 1)

# With expand model space, custom is not OOD, and model space is expanded
m = Adapter(
search_space=experiment.search_space,
search_space=ss,
model=None,
experiment=experiment,
data=data,
Expand All @@ -1027,10 +1040,11 @@ def test_SetModelSpace(self) -> None:
self.assertEqual(set(ood_arms), {"status_quo"})
self.assertEqual(m.model_space.parameters["x1"].lower, -20.0)
self.assertEqual(m.model_space.parameters["x2"].upper, 18.0)
self.assertEqual(m.model_space.parameter_constraints, [])

# With fill values, SQ is also in design, and x2 is further expanded
m = Adapter(
search_space=experiment.search_space,
search_space=ss,
model=None,
experiment=experiment,
data=data,
Expand All @@ -1039,6 +1053,7 @@ def test_SetModelSpace(self) -> None:
)
self.assertEqual(sum(m.training_in_design), 7)
self.assertEqual(m.model_space.parameters["x2"].upper, 20)
self.assertEqual(m.model_space.parameter_constraints, [])

@mock.patch(
"ax.modelbridge.base.observations_from_data",
Expand Down