def simple_benchmark_problem_from_json( object_json: Dict[str, Any]) -> SimpleBenchmarkProblem: """Load a benchmark problem from JSON.""" uses_synthetic_function = object_json.pop("uses_synthetic_function") if uses_synthetic_function: function_name = object_json.pop("function_name") from_botorch_prefix = synthetic_functions.FromBotorch.__name__ if function_name.startswith(from_botorch_prefix): botorch_function_name = function_name.replace( f"{from_botorch_prefix}_", "") botorch_function = getattr(botorch_synthetic, botorch_function_name)() f = from_botorch(botorch_function) else: f = getattr(synthetic_functions, function_name)() else: f = pickle.loads(object_json.pop("f").encode()) domain = object_from_json(object_json.pop("domain")) assert isinstance(domain, list) and all( isinstance(x, (tuple, list)) for x in domain) return SimpleBenchmarkProblem( f=f, name=object_json.pop("name"), domain=cast(List[Tuple[float, float]], domain), minimize=object_json.pop("minimize"), )
def testEncodeDecodeSimpleBenchmarkProblem(self): branin_problem = get_branin_simple_benchmark_problem() sum_problem = get_sum_simple_benchmark_problem() new_branin_problem = object_from_json(object_to_json(branin_problem)) new_sum_problem = object_from_json(object_to_json(sum_problem)) self.assertEqual(branin_problem.f(1, 2), new_branin_problem.f(1, 2), branin(1, 2)) self.assertEqual(sum_problem.f([1, 2]), new_sum_problem.f([1, 2]), 3) # Test using `from_botorch`. ackley_problem = SimpleBenchmarkProblem(f=from_botorch(Ackley()), noise_sd=0.0, minimize=True) new_ackley_problem = object_from_json(object_to_json(ackley_problem)) self.assertEqual(ackley_problem.f(1, 2), new_ackley_problem.f(1, 2), ackley(1, 2))
def testEncodeDecodeSimpleBenchmarkProblem(self): branin_problem = get_branin_simple_benchmark_problem() sum_problem = get_sum_simple_benchmark_problem() new_branin_problem = object_from_json( object_to_json( branin_problem, encoder_registry=DEPRECATED_ENCODER_REGISTRY, class_encoder_registry=DEPRECATED_CLASS_ENCODER_REGISTRY, ), decoder_registry=DEPRECATED_DECODER_REGISTRY, class_decoder_registry=DEPRECATED_CLASS_DECODER_REGISTRY, ) new_sum_problem = object_from_json( object_to_json( sum_problem, encoder_registry=DEPRECATED_ENCODER_REGISTRY, class_encoder_registry=DEPRECATED_CLASS_ENCODER_REGISTRY, ), decoder_registry=DEPRECATED_DECODER_REGISTRY, class_decoder_registry=DEPRECATED_CLASS_DECODER_REGISTRY, ) self.assertEqual( branin_problem.f(1, 2), new_branin_problem.f(1, 2), branin(1, 2) ) self.assertEqual(sum_problem.f([1, 2]), new_sum_problem.f([1, 2]), 3) # Test using `from_botorch`. ackley_problem = SimpleBenchmarkProblem( f=from_botorch(Ackley()), noise_sd=0.0, minimize=True ) new_ackley_problem = object_from_json( object_to_json( ackley_problem, encoder_registry=DEPRECATED_ENCODER_REGISTRY, class_encoder_registry=DEPRECATED_CLASS_ENCODER_REGISTRY, ), decoder_registry=DEPRECATED_DECODER_REGISTRY, class_decoder_registry=DEPRECATED_CLASS_DECODER_REGISTRY, ) self.assertEqual( ackley_problem.f(1, 2), new_ackley_problem.f(1, 2), ackley(1, 2) )
# LICENSE file in the root directory of this source tree. from ax.benchmark.benchmark_problem import BenchmarkProblem, SimpleBenchmarkProblem from ax.utils.measurement.synthetic_functions import from_botorch from ax.utils.testing.core_stubs import ( get_augmented_branin_optimization_config, get_augmented_hartmann_optimization_config, get_branin_search_space, get_hartmann_search_space, ) from botorch.test_functions.synthetic import Ackley, Branin # Initialize the single-fidelity problems ackley = SimpleBenchmarkProblem(f=from_botorch(Ackley()), noise_sd=0.0, minimize=True) branin = SimpleBenchmarkProblem(f=from_botorch(Branin()), noise_sd=0.0, minimize=True) single_fidelity_problem_group = [ackley, branin] # Initialize the multi-fidelity problems augmented_branin = BenchmarkProblem( search_space=get_branin_search_space(with_fidelity_parameter=True), optimization_config=get_augmented_branin_optimization_config(), ) augmented_hartmann = BenchmarkProblem( search_space=get_hartmann_search_space(with_fidelity_parameter=True), optimization_config=get_augmented_hartmann_optimization_config(), ) multi_fidelity_problem_group = [augmented_branin, augmented_hartmann] # Gather all of the problems
# # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from ax.benchmark.benchmark_problem import BenchmarkProblem, SimpleBenchmarkProblem from ax.utils.measurement.synthetic_functions import from_botorch from ax.utils.testing.core_stubs import ( get_augmented_branin_optimization_config, get_augmented_hartmann_optimization_config, get_branin_search_space, get_hartmann_search_space, ) from botorch.test_functions.synthetic import Ackley, Branin # Initialize the single-fidelity problems ackley = SimpleBenchmarkProblem(f=from_botorch(Ackley()), noise_sd=0.0, minimize=True) branin = SimpleBenchmarkProblem(f=from_botorch(Branin()), noise_sd=0.0, minimize=True) single_fidelity_problem_group = [ackley, branin] # Initialize the multi-fidelity problems augmented_branin = BenchmarkProblem( search_space=get_branin_search_space(with_fidelity_parameter=True), optimization_config=get_augmented_branin_optimization_config(), ) augmented_hartmann = BenchmarkProblem( search_space=get_hartmann_search_space(with_fidelity_parameter=True), optimization_config=get_augmented_hartmann_optimization_config(),
AlignedAugHartmann6(), # Ax support. "hartmann6": Hartmann6(), # d: 6; [(0, 1) for i in range(6)] "AugHartmann6": Aug_Hartmann6(), # d: 7; [(0, 1) for i in range(7)] "branin": Branin(), # d: 2; [(-5, 10), (0, 15)] "AugBranin": Aug_Branin(), # d: 3; [(-5, 10), (0, 15), (0, 1)] # From Botorch # # dim; _optimal_value; _bounds; _optimizers; # (2); 0.0; [(-32.768, 32.768),(-32.768, 32.768)]; [(0.0, 0.0)] "ackley2": from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley(dim=2)), "ackley3": from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley(dim=3)), "ackley4": from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley(dim=4)), "ackley7": from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley(dim=7)), # 2; 0.0; [(-4.5, 4.5), (-4.5, 4.5)]; [(3.0, 0.5)] "beale": from_botorch(botorch_synthetic_function=botorch_synthetic.Beale()), # 2; 0.0; [(-15.0, -5.0), (-3.0, 3.0)]; [(-10.0, 1.0)] "bukin": from_botorch(botorch_synthetic_function=botorch_synthetic.Bukin()), # 8; 0.8; [(-1.0, 1.0) for _ in range(8)]; [tuple(0.0 for _ in range(8))] "cosine8": from_botorch(botorch_synthetic_function=botorch_synthetic.Cosine8()),