# Copyright (c) 2020 - for information on the respective copyright owner# see the NOTICE file and/or the repository https://github.com/boschresearch/blackboxopt## SPDX-License-Identifier: Apache-2.0importparameterspaceaspstry:importdask.distributedasddexceptImportError:raiseImportError("Unable to import Dask Distributed specific dependencies. "+"Make sure to install blackboxopt[dask]")fromblackboxoptimportEvaluation,EvaluationSpecification,Objectivefromblackboxopt.optimization_loops.dask_distributedimport(run_optimization_loop,)fromblackboxopt.optimizers.random_searchimportRandomSearchdefevaluation_function(eval_spec:EvaluationSpecification)->Evaluation:returneval_spec.create_evaluation(objectives={"loss":eval_spec.configuration["p1"]**2},user_info={"weather":"sunny"},)if__name__=="__main__":space=ps.ParameterSpace()space.add(ps.ContinuousParameter("p1",(-1.0,1.0)))optimizer=RandomSearch(space,[Objective("loss",greater_is_better=False)],max_steps=1000,)evaluations=run_optimization_loop(optimizer,evaluation_function,dd.Client(),max_evaluations=100)n_successes=len([eforeinevaluationsifnote.all_objectives_none])print(f"Successfully evaluated {n_successes}/{len(evaluations)}")