Skip to content
Open
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
2 changes: 1 addition & 1 deletion ax/adapter/tests/test_torch_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ def test_pairwise_preference_generator(self) -> None:
surrogate=surrogate,
),
optimization_config=OptimizationConfig(
Objective(
objective=Objective(
metric=Metric(Keys.PAIRWISE_PREFERENCE_QUERY.value),
minimize=False,
)
Expand Down
13 changes: 9 additions & 4 deletions ax/adapter/tests/test_torch_moo_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ def test_hypervolume(self, _, cuda: bool = False) -> None:
)
for trial in exp.trials.values():
trial.mark_running(no_runner_required=True).mark_completed()
# pyre-fixme[16]: Optional type has no attribute `metrics`.
metrics_dict = exp.metrics
# Objective thresholds and synthetic observations chosen to have closed-form
# hypervolumes to test.
Expand Down Expand Up @@ -464,9 +463,15 @@ def test_infer_objective_thresholds(self, _, cuda: bool = False) -> None:
first = sub_exprs[0]
if not first.startswith("-"):
sub_exprs[0] = f"-{first}"
oc.objective = Objective(
expression=", ".join(sub_exprs),
metric_name_to_signature={s.lstrip("-"): s.lstrip("-") for s in sub_exprs},
oc = oc.clone_with_args(
objectives=[
Objective(
expression=", ".join(sub_exprs),
metric_name_to_signature={
s.lstrip("-"): s.lstrip("-") for s in sub_exprs
},
)
]
)

for use_partial_thresholds in (False, True):
Expand Down
7 changes: 4 additions & 3 deletions ax/adapter/transforms/relativize.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def transform_optimization_config(
"Expected multi-objective, got single-objective"
)
new_optimization_config = optimization_config.clone_with_args(
objective=objective,
objectives=[objective],
outcome_constraints=constraints,
)
elif isinstance(optimization_config, MultiObjectiveOptimizationConfig):
Expand All @@ -174,13 +174,14 @@ def transform_optimization_config(
)

new_optimization_config = optimization_config.clone_with_args(
objective=optimization_config.objective,
objectives=[optimization_config.objective],
outcome_constraints=constraints,
objective_thresholds=obj_thresholds,
)
else:
new_optimization_config = optimization_config.clone_with_args(
objective=optimization_config.objective, outcome_constraints=constraints
objectives=[optimization_config.objective],
outcome_constraints=constraints,
)

return new_optimization_config
Expand Down
10 changes: 6 additions & 4 deletions ax/adapter/transforms/standardize_y.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ def transform_optimization_config(
(name, new_w)
for (name, _), new_w in zip(objective.metric_weights, new_weights)
]
optimization_config.objective = _build_objective_from_metric_weights(
new_metric_weights,
metric_name_to_signature=objective.metric_name_to_signature,
)
optimization_config._objectives = [
_build_objective_from_metric_weights(
new_metric_weights,
metric_name_to_signature=objective.metric_name_to_signature,
)
]

new_constraints = self._transform_constraints(
optimization_config.outcome_constraints, adapter
Expand Down
10 changes: 6 additions & 4 deletions ax/adapter/transforms/stratified_standardize_y.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,12 @@ def transform_optimization_config(
(name, new_w)
for (name, _), new_w in zip(objective.metric_weights, new_weights)
]
optimization_config.objective = _build_objective_from_metric_weights(
new_metric_weights,
metric_name_to_signature=objective.metric_name_to_signature,
)
optimization_config._objectives = [
_build_objective_from_metric_weights(
new_metric_weights,
metric_name_to_signature=objective.metric_name_to_signature,
)
]

optimization_config.outcome_constraints = self._transform_constraints(
optimization_config.outcome_constraints, strata, adapter
Expand Down
12 changes: 6 additions & 6 deletions ax/adapter/transforms/tests/test_log_y_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ def test_TransformOptimizationConfig(self) -> None:
# basic test
m1 = Metric(name="m1")
objective_m1 = Objective(metric=m1, minimize=False)
oc = OptimizationConfig(objective=objective_m1, outcome_constraints=[])
oc = OptimizationConfig(objectives=[objective_m1], outcome_constraints=[])
tf = LogY(search_space=None, config={"metrics": ["m1"]})
oc_tf = tf.transform_optimization_config(deepcopy(oc), None, None)
self.assertEqual(oc_tf, oc)
# output constraint on a different metric should work
m2 = Metric(name="m2")
oc = OptimizationConfig(
objective=objective_m1,
objectives=[objective_m1],
outcome_constraints=[
get_outcome_constraint(metric=m2, bound=-1, relative=False)
],
Expand All @@ -155,7 +155,7 @@ def test_TransformOptimizationConfig(self) -> None:
# output constraint with a negative bound should fail
objective_m2 = Objective(metric=m2, minimize=False)
oc = OptimizationConfig(
objective=objective_m2,
objectives=[objective_m2],
outcome_constraints=[
get_outcome_constraint(metric=m1, bound=-1.234, relative=False)
],
Expand All @@ -170,7 +170,7 @@ def test_TransformOptimizationConfig(self) -> None:
)
# output constraint with a zero bound should also fail
oc = OptimizationConfig(
objective=objective_m2,
objectives=[objective_m2],
outcome_constraints=[
get_outcome_constraint(metric=m1, bound=0, relative=False)
],
Expand All @@ -185,7 +185,7 @@ def test_TransformOptimizationConfig(self) -> None:
)
# output constraint with a positive bound should work
oc = OptimizationConfig(
objective=objective_m2,
objectives=[objective_m2],
outcome_constraints=[
get_outcome_constraint(metric=m1, bound=2.345, relative=False)
],
Expand All @@ -200,7 +200,7 @@ def test_TransformOptimizationConfig(self) -> None:
self.assertEqual(oc_tf, oc)
# output constraint with a relative bound should fail
oc = OptimizationConfig(
objective=objective_m2,
objectives=[objective_m2],
outcome_constraints=[
get_outcome_constraint(metric=m1, bound=2.345, relative=True)
],
Expand Down
14 changes: 8 additions & 6 deletions ax/adapter/transforms/tests/test_power_y_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_transform_optimization_config(self) -> None:
# basic test
m1 = Metric(name="m1")
objective_m1 = Objective(metric=m1, minimize=False)
oc = OptimizationConfig(objective=objective_m1, outcome_constraints=[])
oc = OptimizationConfig(objectives=[objective_m1], outcome_constraints=[])
tf = PowerTransformY(
search_space=None,
experiment_data=self.experiment_data,
Expand All @@ -219,7 +219,7 @@ def test_transform_optimization_config(self) -> None:
m2 = Metric(name="m2")
for bound in [-1.234, 0, 2.345]:
oc = OptimizationConfig(
objective=objective_m1,
objectives=[objective_m1],
outcome_constraints=get_constraint(
metric=m2, bound=bound, relative=False
),
Expand All @@ -230,7 +230,7 @@ def test_transform_optimization_config(self) -> None:
objective_m2 = Objective(metric=m2, minimize=False)
for bound in [-1.234, 0, 2.345]:
oc = OptimizationConfig(
objective=objective_m2,
objectives=[objective_m2],
outcome_constraints=get_constraint(
metric=m1, bound=bound, relative=False
),
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_transform_optimization_config(self) -> None:
self.assertAlmostEqual(c_actual.bound, c_expected.bound, places=5)
# Relative constraints aren't supported
oc = OptimizationConfig(
objective=objective_m2,
objectives=[objective_m2],
outcome_constraints=get_constraint(metric=m1, bound=2.345, relative=True),
)
with self.assertRaisesRegex(
Expand All @@ -277,7 +277,7 @@ def test_transform_optimization_config(self) -> None:
# Support for scalarized outcome constraints isn't implemented
m3 = Metric(name="m3")
oc = OptimizationConfig(
objective=objective_m2,
objectives=[objective_m2],
outcome_constraints=[
ScalarizedOutcomeConstraint(
metrics=[m1, m3], op=ComparisonOp.GEQ, bound=2.345, relative=False
Expand All @@ -295,7 +295,9 @@ def test_transform_optimization_config(self) -> None:
scalarized_objective = ScalarizedObjective(
metrics=[m1, m3], weights=[1.0, 2.0], minimize=False
)
oc = OptimizationConfig(objective=scalarized_objective, outcome_constraints=[])
oc = OptimizationConfig(
objectives=[scalarized_objective], outcome_constraints=[]
)
with self.assertRaisesRegex(NotImplementedError, "ScalarizedObjective"):
tf.transform_optimization_config(oc, None, None)

Expand Down
14 changes: 7 additions & 7 deletions ax/adapter/transforms/tests/test_standardize_y_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_TransformOptimizationConfig(self) -> None:
),
]

oc = OptimizationConfig(objective=objective, outcome_constraints=cons)
oc = OptimizationConfig(objectives=[objective], outcome_constraints=cons)
with self.assertRaisesRegex(
DataRequiredError, "`StandardizeY` transform requires constraint metric"
):
Expand All @@ -125,7 +125,7 @@ def test_TransformOptimizationConfig(self) -> None:
relative=False,
),
]
oc = OptimizationConfig(objective=objective, outcome_constraints=cons)
oc = OptimizationConfig(objectives=[objective], outcome_constraints=cons)
with self.assertRaisesRegex(
DataRequiredError, "`StandardizeY` transform requires constraint metric"
):
Expand All @@ -145,7 +145,7 @@ def test_TransformOptimizationConfig(self) -> None:
relative=False,
),
]
oc = OptimizationConfig(objective=objective, outcome_constraints=cons)
oc = OptimizationConfig(objectives=[objective], outcome_constraints=cons)
oc = self.t.transform_optimization_config(oc, None, None)
# Verify the transformed constraints have the expected values.
# We compare properties individually to avoid floating-point string
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_TransformOptimizationConfig(self) -> None:
con = OutcomeConstraint(
metric=m1, op=ComparisonOp.GEQ, bound=2.0, relative=True
)
oc = OptimizationConfig(objective=objective, outcome_constraints=[con])
oc = OptimizationConfig(objectives=[objective], outcome_constraints=[con])
with self.assertRaises(ValueError):
oc = self.t.transform_optimization_config(oc, None, None)

Expand Down Expand Up @@ -229,7 +229,7 @@ def test_TransformOptimizationConfigWithScalarizedObjective(self) -> None:
objective = ScalarizedObjective(
metrics=[m1, m2], weights=[0.5, 0.5], minimize=False
)
oc = OptimizationConfig(objective=objective)
oc = OptimizationConfig(objectives=[objective])
oc_transformed = self.t.transform_optimization_config(oc, None, None)

# Check that weights are scaled by standard deviations
Expand All @@ -245,7 +245,7 @@ def test_TransformOptimizationConfigWithScalarizedObjective(self) -> None:
objective_missing = ScalarizedObjective(
metrics=[m1, m3], weights=[0.5, 0.5], minimize=False
)
oc_missing = OptimizationConfig(objective=objective_missing)
oc_missing = OptimizationConfig(objectives=[objective_missing])
with self.assertRaisesRegex(
DataRequiredError, "`StandardizeY` transform requires objective metric"
):
Expand All @@ -255,7 +255,7 @@ def test_TransformOptimizationConfigWithScalarizedObjective(self) -> None:
objective_minimize = ScalarizedObjective(
metrics=[m1, m2], weights=[1.0, -2.0], minimize=True
)
oc_minimize = OptimizationConfig(objective=objective_minimize)
oc_minimize = OptimizationConfig(objectives=[objective_minimize])
oc_minimize_transformed = self.t.transform_optimization_config(
oc_minimize, None, None
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_TransformObservations(self) -> None:

def test_TransformOptimizationConfig(self) -> None:
cons2 = deepcopy(self.cons)
oc = OptimizationConfig(objective=self.objective, outcome_constraints=cons2)
oc = OptimizationConfig(objectives=[self.objective], outcome_constraints=cons2)
fixed_features = ObservationFeatures({"z": "a"})
oc = self.t.transform_optimization_config(oc, None, fixed_features)
# Verify constraint values approximately (expression-string equality
Expand All @@ -330,7 +330,7 @@ def test_TransformOptimizationConfig(self) -> None:
self.assertTrue(oc.objective == self.objective)

# No constraints
oc2 = OptimizationConfig(objective=self.objective)
oc2 = OptimizationConfig(objectives=[self.objective])
oc3 = deepcopy(oc2)
fixed_features = ObservationFeatures({"z": "a"})
oc3 = self.t.transform_optimization_config(oc3, None, fixed_features)
Expand All @@ -340,7 +340,7 @@ def test_TransformOptimizationConfig(self) -> None:
con = OutcomeConstraint(
metric=self.m1, op=ComparisonOp.GEQ, bound=2.0, relative=True
)
oc = OptimizationConfig(objective=self.objective, outcome_constraints=[con])
oc = OptimizationConfig(objectives=[self.objective], outcome_constraints=[con])
with self.assertRaises(ValueError):
oc = self.t.transform_optimization_config(oc, None, fixed_features)
# Fail without strat param fixed
Expand All @@ -350,10 +350,10 @@ def test_TransformOptimizationConfig(self) -> None:

def test_TransformOptimizationConfigWithStrataMapping(self) -> None:
cons2 = deepcopy(self.cons)
oc = OptimizationConfig(objective=self.objective, outcome_constraints=cons2)
oc = OptimizationConfig(objectives=[self.objective], outcome_constraints=cons2)
fixed_features = ObservationFeatures({"z": "a"})
cons2 = deepcopy(self.cons)
oc = OptimizationConfig(objective=self.objective, outcome_constraints=cons2)
oc = OptimizationConfig(objectives=[self.objective], outcome_constraints=cons2)
oc = self.t2.transform_optimization_config(oc, None, fixed_features)
# Verify constraint values approximately.
self.assertEqual(len(oc.outcome_constraints), 2)
Expand All @@ -367,7 +367,7 @@ def test_TransformOptimizationConfigWithStrataMapping(self) -> None:
self.assertTrue(oc.objective == self.objective)
fixed_features = ObservationFeatures({"z": "c"})
cons2 = deepcopy(self.cons)
oc = OptimizationConfig(objective=self.objective, outcome_constraints=cons2)
oc = OptimizationConfig(objectives=[self.objective], outcome_constraints=cons2)
oc = self.t2.transform_optimization_config(oc, None, fixed_features)
# Verify constraint values approximately.
self.assertEqual(len(oc.outcome_constraints), 2)
Expand Down Expand Up @@ -441,7 +441,7 @@ def test_TransformOptimizationConfigWithScalarizedObjective(self) -> None:
objective = ScalarizedObjective(
metrics=[self.m1, self.m2], weights=[0.5, 0.5], minimize=False
)
oc = OptimizationConfig(objective=objective)
oc = OptimizationConfig(objectives=[objective])
expected_weights = {
"a": [0.5 * 1.0, 0.5 * sqrt(2) * 3],
"b": [0.5 * 2 * sqrt(2), 0.5 * sqrt(2) * 0.5],
Expand Down Expand Up @@ -476,7 +476,7 @@ def test_TransformAndUntransformScalarizedOutcomeConstraint(self) -> None:
relative=False,
)
oc = OptimizationConfig(
objective=self.objective, outcome_constraints=[scalarized_constraint]
objectives=[self.objective], outcome_constraints=[scalarized_constraint]
)
fixed_features = ObservationFeatures({"z": "a"})
oc_transformed = self.t.transform_optimization_config(oc, None, fixed_features)
Expand Down
2 changes: 1 addition & 1 deletion ax/api/utils/instantiation/from_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ def optimization_config_from_string(
)

return OptimizationConfig(
objective=objective,
objectives=[objective],
outcome_constraints=outcome_constraints,
)
2 changes: 1 addition & 1 deletion ax/benchmark/benchmark_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def get_soo_opt_config(
)

config = OptimizationConfig(
objective=objective, outcome_constraints=outcome_constraints
objectives=[objective], outcome_constraints=outcome_constraints
)
return config, [obj_metric] + constraint_metrics

Expand Down
18 changes: 10 additions & 8 deletions ax/benchmark/problems/surrogate/hss/cifar10_surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@ def get_cifar10_surrogate_benchmark(
)

optimization_config = OptimizationConfig(
objective=Objective(
metric=BenchmarkMetric(
name="CIFAR10 Test Accuracy",
lower_is_better=False,
observe_noise_sd=False,
),
minimize=False,
)
objectives=[
Objective(
metric=BenchmarkMetric(
name="CIFAR10 Test Accuracy",
lower_is_better=False,
observe_noise_sd=False,
),
minimize=False,
)
],
)

return BenchmarkProblem(
Expand Down
Loading
Loading