Example #1
0
 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))
Example #2
0
 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)
     )