Ejemplo n.º 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))
Ejemplo n.º 2
0
def _extract_optimization_trace_from_synthetic_function(
    experiment: Experiment, problem: SimpleBenchmarkProblem
) -> np.ndarray:
    if any(isinstance(trial, BatchTrial) for trial in experiment.trials.values()):
        raise NotImplementedError("Batched trials are not yet supported.")
    true_values = []
    for trial in experiment.trials.values():
        parameters = not_none(checked_cast(Trial, trial).arm).parameters
        # Expecting numerical parameters only.
        value = problem.f(*[float(x) for x in parameters.values()])  # pyre-ignore[6]
        true_values.append(value)
    return best_feasible_objective(
        optimization_config=experiment.optimization_config,
        values={problem.name: true_values},
    )
Ejemplo n.º 3
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)
     )