def test_distributed_optimization(tmp_dir):
    hps = hp_module.HyperParameters()
    hps.Int('a', 0, 10)
    hps.Float('b', (- 1), 1, step=0.1)
    hps.Float('c', 1e-05, 0.01, sampling='log')

    def evaluate(hp):
        return ((abs((hp['a'] - 4)) - hp['b']) + (0.1 * abs((3 + math.log(hp['c'], 10)))))
    oracle = bo_module.BayesianOptimizationOracle(objective=kt.Objective('score', 'min'), hyperparameters=hps, max_trials=60)
    oracle._set_project_dir(tmp_dir, 'untitled')
    tuners = 4
    for _ in range(10):
        trials = []
        for i in range(tuners):
            trial = oracle.create_trial(('tuner_' + str(i)))
            trials.append(trial)
        for trial in trials:
            oracle.update_trial(trial.trial_id, {'score': evaluate(trial.hyperparameters)})
        for trial in trials:
            oracle.end_trial(trial.trial_id, 'COMPLETED')
    (atol, rtol) = (0.1, 0.1)
    best_trial = oracle.get_best_trials()[0]
    best_hps = best_trial.hyperparameters
    assert (best_trial.score < (- 0.8)), best_hps.values
    assert np.isclose(best_hps['a'], 4, atol=atol, rtol=rtol)
    assert np.isclose(best_hps['b'], 1, atol=atol, rtol=rtol)
    log_best_c = math.log(best_hps['c'], 10)
    assert ((log_best_c > (- 4)) and (log_best_c < (- 2)))
def test_distributed_optimization(tmp_dir):
    hps = hp_module.HyperParameters()
    hps.Int('a', 0, 10)
    hps.Float('b', (- 1), 1, step=0.1)
    hps.Float('c', 1e-05, 0.01, sampling='log')

    def evaluate(hp):
        return ((abs((hp['a'] - 4)) - hp['b']) + (0.1 * abs((3 + math.log(hp['c'], 10)))))
    oracle = bo_module.BayesianOptimizationOracle(objective=kt.Objective('score', 'min'), hyperparameters=hps, max_trials=60)
    oracle._set_project_dir(tmp_dir, 'untitled')
    tuners = 4
    for _ in range(10):
        trials = []
        for i in range(tuners):
            trial = oracle.create_trial(('tuner_' + str(i)))
            trials.append(trial)
        for trial in trials:
            oracle.update_trial(trial.trial_id, {'score': evaluate(trial.hyperparameters)})
        for trial in trials:
            oracle.end_trial(trial.trial_id, 'COMPLETED')
    (atol, rtol) = (0.1, 0.1)
    best_trial = oracle.get_best_trials()[0]
    best_hps = best_trial.hyperparameters
    assert (best_trial.score < (- 0.8)), best_hps.values
    assert np.isclose(best_hps['a'], 4, atol=atol, rtol=rtol)
    assert np.isclose(best_hps['b'], 1, atol=atol, rtol=rtol)
    log_best_c = math.log(best_hps['c'], 10)
    assert ((log_best_c > (- 4)) and (log_best_c < (- 2)))