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

Allow removal of parameters with different values in RemoveFixed transform #2779

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
10 changes: 2 additions & 8 deletions ax/modelbridge/transforms/remove_fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,8 @@ def transform_observation_features(
self, observation_features: list[ObservationFeatures]
) -> list[ObservationFeatures]:
for obsf in observation_features:
for p_name, fixed_p in self.fixed_parameters.items():
if p_name in obsf.parameters:
if obsf.parameters[p_name] != fixed_p.value:
raise ValueError(
f"Fixed parameter {p_name} with out of design value: "
f"{obsf.parameters[p_name]} passed to `RemoveFixed`."
)
obsf.parameters.pop(p_name)
for p_name in self.fixed_parameters:
obsf.parameters.pop(p_name, None)
return observation_features

def _transform_search_space(self, search_space: SearchSpace) -> SearchSpace:
Expand Down
11 changes: 7 additions & 4 deletions ax/modelbridge/transforms/tests/test_remove_fixed_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ def test_TransformObservationFeatures(self) -> None:
observation_features = [
ObservationFeatures(parameters={"a": 2.2, "b": "b", "c": "a"})
]
observation_features_invalid = [
observation_features_different = [
ObservationFeatures(parameters={"a": 2.2, "b": "b", "c": "b"})
]
# Fixed parameter out of design!
with self.assertRaises(ValueError):
self.t.transform_observation_features(observation_features_invalid)
# Fixed parameter is out of design. It will still get removed.
t_obs = self.t.transform_observation_features(observation_features)
t_obs_different = self.t.transform_observation_features(
observation_features_different
)
self.assertEqual(t_obs, t_obs_different)

def test_TransformSearchSpace(self) -> None:
ss2 = self.search_space.clone()
Expand Down
Loading