17
17
MultiObjectiveBenchmarkProblem ,
18
18
)
19
19
from ax .benchmark .benchmark_result import AggregatedBenchmarkResult , BenchmarkResult
20
- from ax .benchmark .metrics .benchmark import BenchmarkMetric
21
20
from ax .benchmark .problems .surrogate import (
22
21
MOOSurrogateBenchmarkProblem ,
23
22
SOOSurrogateBenchmarkProblem ,
24
23
)
25
24
from ax .benchmark .runners .surrogate import SurrogateRunner
26
25
from ax .core .experiment import Experiment
27
- from ax .core .objective import MultiObjective , Objective
28
26
from ax .core .optimization_config import (
29
27
MultiObjectiveOptimizationConfig ,
30
28
OptimizationConfig ,
31
29
)
32
- from ax .core .outcome_constraint import ObjectiveThreshold
33
30
from ax .modelbridge .generation_strategy import GenerationStep , GenerationStrategy
34
31
from ax .modelbridge .registry import Models
35
32
from ax .modelbridge .torch import TorchModelBridge
36
33
from ax .models .torch .botorch_modular .model import BoTorchModel
37
34
from ax .models .torch .botorch_modular .surrogate import Surrogate
38
35
from ax .service .scheduler import SchedulerOptions
39
36
from ax .utils .common .constants import Keys
37
+ from ax .utils .common .typeutils import checked_cast
40
38
from ax .utils .testing .core_stubs import (
41
39
get_branin_experiment ,
42
40
get_branin_experiment_with_multi_objective ,
@@ -62,13 +60,11 @@ def get_single_objective_benchmark_problem(
62
60
63
61
64
62
def get_multi_objective_benchmark_problem (
65
- observe_noise_sd : bool = False ,
66
- num_trials : int = 4 ,
67
- test_problem_kwargs : Optional [Dict [str , Any ]] = None ,
63
+ observe_noise_sd : bool = False , num_trials : int = 4
68
64
) -> MultiObjectiveBenchmarkProblem :
69
65
return create_multi_objective_problem_from_botorch (
70
66
test_problem_class = BraninCurrin ,
71
- test_problem_kwargs = {} if test_problem_kwargs is None else test_problem_kwargs ,
67
+ test_problem_kwargs = {},
72
68
num_trials = num_trials ,
73
69
observe_noise_sd = observe_noise_sd ,
74
70
)
@@ -98,97 +94,61 @@ def get_sobol_benchmark_method() -> BenchmarkMethod:
98
94
)
99
95
100
96
101
- def get_soo_surrogate (noise_stds : float = 0.0 ) -> SOOSurrogateBenchmarkProblem :
102
- outcome_name = "branin"
103
- observe_noise_stds = True
97
+ def get_soo_surrogate () -> SOOSurrogateBenchmarkProblem :
104
98
experiment = get_branin_experiment (with_completed_trial = True )
105
-
106
- optimization_config = OptimizationConfig (
107
- objective = Objective (
108
- metric = BenchmarkMetric (
109
- name = outcome_name ,
110
- lower_is_better = False ,
111
- observe_noise_sd = observe_noise_stds ,
112
- ),
113
- minimize = False ,
114
- )
115
- )
116
- surrogate = Surrogate (botorch_model_class = SingleTaskGP )
117
- model_bridge = TorchModelBridge (
99
+ surrogate = TorchModelBridge (
118
100
experiment = experiment ,
119
101
search_space = experiment .search_space ,
120
- model = BoTorchModel (surrogate = surrogate ),
102
+ model = BoTorchModel (surrogate = Surrogate ( botorch_model_class = SingleTaskGP ) ),
121
103
data = experiment .lookup_data (),
122
104
transforms = [],
123
105
)
124
- datasets = surrogate .training_data
125
106
runner = SurrogateRunner (
126
- name = outcome_name ,
107
+ name = "test" ,
127
108
search_space = experiment .search_space ,
128
- outcome_names = [outcome_name ],
129
- get_surrogate_and_datasets = lambda : (model_bridge , datasets ),
130
- noise_stds = noise_stds ,
109
+ outcome_names = ["branin" ],
110
+ get_surrogate_and_datasets = lambda : (surrogate , []),
131
111
)
132
112
return SOOSurrogateBenchmarkProblem (
133
113
name = "test" ,
134
114
search_space = experiment .search_space ,
135
- optimization_config = optimization_config ,
115
+ optimization_config = checked_cast (
116
+ OptimizationConfig , experiment .optimization_config
117
+ ),
136
118
num_trials = 6 ,
137
- observe_noise_stds = observe_noise_stds ,
119
+ observe_noise_stds = True ,
138
120
optimal_value = 0.0 ,
139
121
runner = runner ,
140
122
is_noiseless = runner .is_noiseless ,
141
123
)
142
124
143
125
144
- def get_moo_surrogate (noise_stds : float = 0.0 ) -> MOOSurrogateBenchmarkProblem :
145
- observe_noise_stds = True
146
- outcome_names = ["branin_a" , "branin_b" ]
147
- # set this to be easy to beat, so hypervolume computations aren't all zero
148
- ref_point = [10.0 , 10.0 ]
149
- surrogate = Surrogate (botorch_model_class = SingleTaskGP )
126
+ def get_moo_surrogate () -> MOOSurrogateBenchmarkProblem :
150
127
experiment = get_branin_experiment_with_multi_objective (with_completed_trial = True )
151
- model_bridge = TorchModelBridge (
128
+ surrogate = TorchModelBridge (
152
129
experiment = experiment ,
153
130
search_space = experiment .search_space ,
154
- model = BoTorchModel (surrogate = surrogate ),
131
+ model = BoTorchModel (surrogate = Surrogate ( botorch_model_class = SingleTaskGP ) ),
155
132
data = experiment .lookup_data (),
156
133
transforms = [],
157
134
)
158
135
159
136
runner = SurrogateRunner (
160
137
name = "test" ,
161
138
search_space = experiment .search_space ,
162
- outcome_names = outcome_names ,
163
- get_surrogate_and_datasets = lambda : (model_bridge , surrogate .training_data ),
164
- noise_stds = noise_stds ,
139
+ outcome_names = ["branin_a" , "branin_b" ],
140
+ get_surrogate_and_datasets = lambda : (surrogate , []),
165
141
)
166
- metrics = [
167
- BenchmarkMetric (
168
- name = name ,
169
- lower_is_better = True ,
170
- observe_noise_sd = observe_noise_stds ,
171
- )
172
- for name in outcome_names
173
- ]
174
- objectives = [Objective (metric = metric ) for metric in metrics ]
175
- objective_thresholds = [
176
- ObjectiveThreshold (metric = metric , bound = ref_p , relative = False )
177
- for metric , ref_p in zip (metrics , ref_point )
178
- ]
179
- optimization_config = MultiObjectiveOptimizationConfig (
180
- objective = MultiObjective (objectives = objectives ),
181
- objective_thresholds = objective_thresholds ,
182
- )
183
-
184
142
return MOOSurrogateBenchmarkProblem (
185
143
name = "test" ,
186
144
search_space = experiment .search_space ,
187
- optimization_config = optimization_config ,
145
+ optimization_config = checked_cast (
146
+ MultiObjectiveOptimizationConfig , experiment .optimization_config
147
+ ),
188
148
num_trials = 10 ,
189
149
observe_noise_stds = True ,
190
150
optimal_value = 1.0 ,
191
- reference_point = ref_point ,
151
+ reference_point = [] ,
192
152
runner = runner ,
193
153
is_noiseless = runner .is_noiseless ,
194
154
)
0 commit comments