Exemple #1
0
 def test_single_valued_choice_to_fixed_param_conversion(self):
     representation = {
         "name": "test",
         "type": "choice",
         "values": [1.0],
     }
     output = parameter_from_json(representation)
     self.assertIsInstance(output, FixedParameter)
     self.assertEqual(output.value, 1.0)
Exemple #2
0
 def with_evaluation_function(
     parameters: List[TParameterRepresentation],
     evaluation_function: TEvaluationFunction,
     experiment_name: Optional[str] = None,
     objective_name: Optional[str] = None,
     minimize: bool = False,
     parameter_constraints: Optional[List[str]] = None,
     outcome_constraints: Optional[List[str]] = None,
     total_trials: int = 20,
     arms_per_trial: int = 1,
     wait_time: int = 0,
     random_seed: Optional[int] = None,
     generation_strategy: Optional[GenerationStrategy] = None,
 ) -> "OptimizationLoop":
     """Constructs a synchronous `OptimizationLoop` using an evaluation
     function."""
     exp_parameters = [parameter_from_json(p) for p in parameters]
     parameter_map = {p.name: p for p in exp_parameters}
     experiment = SimpleExperiment(
         name=experiment_name,
         search_space=SearchSpace(
             parameters=exp_parameters,
             parameter_constraints=None
             if parameter_constraints is None else [
                 constraint_from_str(c, parameter_map)
                 for c in parameter_constraints
             ],
         ),
         objective_name=objective_name,
         evaluation_function=evaluation_function,
         minimize=minimize,
         outcome_constraints=[
             outcome_constraint_from_str(c)
             for c in (outcome_constraints or [])
         ],
     )
     return OptimizationLoop(
         experiment=experiment,
         total_trials=total_trials,
         arms_per_trial=arms_per_trial,
         random_seed=random_seed,
         wait_time=wait_time,
         generation_strategy=generation_strategy,
     )