Skip to content

Commit

Permalink
Merge 94bac90 into c14ff08
Browse files Browse the repository at this point in the history
  • Loading branch information
Balandat authored Dec 6, 2023
2 parents c14ff08 + 94bac90 commit 6e5dd6e
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions ax/benchmark/benchmark_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ax.metrics.botorch_test_problem import BotorchTestProblemMetric
from ax.runners.botorch_test_problem import BotorchTestProblemRunner
from ax.utils.common.base import Base
from ax.utils.common.typeutils import checked_cast
from botorch.test_functions.base import BaseTestProblem, ConstrainedBaseTestProblem
from botorch.test_functions.multi_objective import MultiObjectiveTestProblem
from botorch.test_functions.synthetic import SyntheticTestFunction
Expand Down Expand Up @@ -146,27 +147,45 @@ def from_botorch(

dim = test_problem_kwargs.get("dim", None)
name = _get_name(test_problem, infer_noise, dim)

if infer_noise:
noise_sd = None
elif isinstance(test_problem.noise_std, list):
# Convention is to have the first outcome be the objective,
# and the remaining ones the constraints.
noise_sd = test_problem.noise_std[0]
else:
noise_sd = checked_cast(float, test_problem.noise_std or 0.0)

# TODO: Support constrained MOO problems.

objective = Objective(
metric=BotorchTestProblemMetric(
name=name,
noise_sd=None if infer_noise else (test_problem.noise_std or 0),
noise_sd=noise_sd,
index=0,
),
minimize=True,
)

if is_constrained:
n_con = test_problem.num_constraints
if isinstance(test_problem.noise_std, list):
constraint_noise_sds = test_problem.constraint_noise_std[1 : n_con + 1]
else:
constraint_noise_sds = [noise_sd] * n_con
outcome_constraints = [
OutcomeConstraint(
metric=BotorchTestProblemMetric(
name=f"constraint_slack_{i}",
noise_sd=None if infer_noise else (test_problem.noise_std or 0),
noise_sd=constraint_noise_sds[i],
index=i,
),
op=ComparisonOp.GEQ,
bound=0.0,
relative=False,
)
for i in range(test_problem.num_constraints)
for i in range(n_con)
]
else:
outcome_constraints = []
Expand Down Expand Up @@ -328,13 +347,21 @@ def from_botorch_multi_objective(
dim = test_problem_kwargs.get("dim", None)
name = _get_name(test_problem, infer_noise, dim)

n_obj = test_problem.num_objectives
if infer_noise:
noise_stds = [None] * n_obj
elif isinstance(test_problem.noise_std, list):
noise_stds = test_problem.noise_std
else:
noise_stds = [checked_cast(float, test_problem.noise_std or 0.0)] * n_obj

metrics = [
BotorchTestProblemMetric(
name=f"{name}_{i}",
noise_sd=None if infer_noise else (test_problem.noise_std or 0),
noise_sd=noise_std,
index=i,
)
for i in range(test_problem.num_objectives)
for i, noise_std in enumerate(noise_stds)
]
optimization_config = MultiObjectiveOptimizationConfig(
objective=MultiObjective(
Expand Down

0 comments on commit 6e5dd6e

Please sign in to comment.