blackboxopt.optimizers.staged.optimizer
StagedIterationOptimizer
get_evaluation_specification(self)
Get next configuration and settings to evaluate.
Exceptions:
Type | Description |
---|---|
OptimizationComplete |
When the optimization run is finished, e.g. when the budget has been exhausted. |
OptimizerNotReady |
When the optimizer is not ready to propose a new evaluation specification. |
Source code in blackboxopt/optimizers/staged/optimizer.py
def get_evaluation_specification(self) -> EvaluationSpecification:
"""Get next configuration and settings to evaluate.
Raises:
OptimizationComplete: When the optimization run is finished, e.g. when the
budget has been exhausted.
OptimizerNotReady: When the optimizer is not ready to propose a new
evaluation specification.
"""
# check if any of the already active iterations returns a configuration and
# simply return that
for idx, iteration in enumerate(self.iterations):
es = iteration.get_evaluation_specification()
if es is not None:
self.evaluation_uuid_to_iteration[str(es.optimizer_info["id"])] = idx
self.pending_configurations[str(es.optimizer_info["id"])] = es
return es
# if that didn't work, check if there another iteration can be started and then
# ask it for a configuration
if len(self.iterations) < self.num_iterations:
self.iterations.append(self._create_new_iteration(len(self.iterations)))
es = self.iterations[-1].get_evaluation_specification()
self.evaluation_uuid_to_iteration[str(es.optimizer_info["id"])] = (
len(self.iterations) - 1
)
self.pending_configurations[str(es.optimizer_info["id"])] = es
return es
# check if the optimization is already complete or whether the optimizer is
# waiting for evaluation results -> raise corresponding error
if all([iteration.finished for iteration in self.iterations]):
raise OptimizationComplete
raise OptimizerNotReady
report_evaluation(self, evaluation)
Report an evaluated evaluation specification.
NOTE: Not all optimizers support reporting results for evaluation specifications that were not proposed by the optimizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
evaluation |
Evaluation |
An evaluated evaluation specification. |
required |
Source code in blackboxopt/optimizers/staged/optimizer.py
def report_evaluation(self, evaluation: Evaluation) -> None:
super().report_evaluation(evaluation)
evaluation_specification_id = evaluation.optimizer_info.get("id")
if evaluation_specification_id is None:
raise ValueError(
"Missing evaluation specification ID in optimizer info. Did you try to "
+ "report an evaluation for a configuration which the optimizer did not"
" pick? This is not supported at the moment."
)
self.pending_configurations.pop(str(evaluation_specification_id))
idx = self.evaluation_uuid_to_iteration.pop(str(evaluation_specification_id))
self.iterations[idx].digest_evaluation(evaluation_specification_id, evaluation)