@@ -74,59 +74,65 @@ def test_get_augmented_branin_problem(self) -> None:
7474class TestFromBoTorch (TestCase ):
7575 def test_single_objective_from_botorch (self ) -> None :
7676 for botorch_test_problem in [Ackley (), ConstrainedHartmann (dim = 6 )]:
77- test_problem = create_problem_from_botorch (
78- test_problem_class = botorch_test_problem .__class__ ,
79- test_problem_kwargs = {},
80- num_trials = 1 ,
81- baseline_value = 100.0 ,
82- )
83-
84- # Test search space
85- self .assertEqual (
86- len (test_problem .search_space .parameters ), botorch_test_problem .dim
87- )
88- self .assertEqual (
89- len (test_problem .search_space .parameters ),
90- len (test_problem .search_space .range_parameters ),
91- )
92- self .assertTrue (
93- all (
94- test_problem .search_space .range_parameters [f"x{ i } " ].lower
95- == botorch_test_problem ._bounds [i ][0 ]
96- for i in range (botorch_test_problem .dim )
97- ),
98- "Parameters' lower bounds must all match Botorch problem's bounds." ,
99- )
100- self .assertTrue (
101- all (
102- test_problem .search_space .range_parameters [f"x{ i } " ].upper
103- == botorch_test_problem ._bounds [i ][1 ]
104- for i in range (botorch_test_problem .dim )
105- ),
106- "Parameters' upper bounds must all match Botorch problem's bounds." ,
107- )
77+ with self .subTest (problem = botorch_test_problem .__class__ .__name__ ):
78+ test_problem = create_problem_from_botorch (
79+ test_problem_class = botorch_test_problem .__class__ ,
80+ test_problem_kwargs = {},
81+ num_trials = 1 ,
82+ baseline_value = 100.0 ,
83+ )
10884
109- # Test optimum
110- self .assertEqual (
111- test_problem .optimal_value , botorch_test_problem ._optimal_value
112- )
113- # test optimization config
114- metric_name = test_problem .optimization_config .objective .metric .name
115- self .assertEqual (metric_name , test_problem .name )
116- self .assertTrue (test_problem .optimization_config .objective .minimize )
117- # test repr method
118- if isinstance (botorch_test_problem , Ackley ):
85+ # Test search space
86+ self .assertEqual (
87+ len (test_problem .search_space .parameters ),
88+ botorch_test_problem .dim ,
89+ )
11990 self .assertEqual (
120- test_problem .optimization_config .outcome_constraints , []
91+ len (test_problem .search_space .parameters ),
92+ len (test_problem .search_space .range_parameters ),
12193 )
122- else :
123- outcome_constraint = (
124- test_problem .optimization_config .outcome_constraints [0 ]
94+ self .assertTrue (
95+ all (
96+ test_problem .search_space .range_parameters [f"x{ i } " ].lower
97+ == botorch_test_problem ._bounds [i ][0 ]
98+ for i in range (botorch_test_problem .dim )
99+ ),
100+ "Parameters' lower bounds must all match Botorch problem's bounds." ,
101+ )
102+ self .assertTrue (
103+ all (
104+ test_problem .search_space .range_parameters [f"x{ i } " ].upper
105+ == botorch_test_problem ._bounds [i ][1 ]
106+ for i in range (botorch_test_problem .dim )
107+ ),
108+ "Parameters' upper bounds must all match Botorch problem's bounds." ,
109+ )
110+
111+ # Test optimum
112+ self .assertEqual (
113+ test_problem .optimal_value ,
114+ botorch_test_problem ._optimal_value ,
125115 )
126- self .assertEqual (outcome_constraint .metric .name , "constraint_slack_0" )
127- self .assertEqual (outcome_constraint .op , ComparisonOp .GEQ )
128- self .assertFalse (outcome_constraint .relative )
129- self .assertEqual (outcome_constraint .bound , 0.0 )
116+ # test optimization config
117+ metric_name = test_problem .optimization_config .objective .metric .name
118+ self .assertEqual (metric_name , test_problem .name )
119+ self .assertTrue (test_problem .optimization_config .objective .minimize )
120+ # test repr method
121+ if isinstance (botorch_test_problem , Ackley ):
122+ self .assertEqual (
123+ test_problem .optimization_config .outcome_constraints ,
124+ [],
125+ )
126+ else :
127+ outcome_constraint = (
128+ test_problem .optimization_config .outcome_constraints [0 ]
129+ )
130+ self .assertEqual (
131+ outcome_constraint .metric .name , "constraint_slack_0"
132+ )
133+ self .assertEqual (outcome_constraint .op , ComparisonOp .GEQ )
134+ self .assertFalse (outcome_constraint .relative )
135+ self .assertEqual (outcome_constraint .bound , 0.0 )
130136
131137 def _test_constrained_from_botorch (
132138 self ,
@@ -259,8 +265,9 @@ def _test_moo_from_botorch(self, lower_is_better: bool) -> None:
259265 )
260266
261267 def test_moo_from_botorch (self ) -> None :
262- self ._test_moo_from_botorch (lower_is_better = True )
263- self ._test_moo_from_botorch (lower_is_better = False )
268+ for lower_is_better in [True , False ]:
269+ with self .subTest (lower_is_better = lower_is_better ):
270+ self ._test_moo_from_botorch (lower_is_better = lower_is_better )
264271
265272 def test_create_problem_from_botorch_with_shifted_function (self ) -> None :
266273 ax_problem = create_problem_from_botorch (
0 commit comments