def test_optimisation_implementations(tmp_path):
    # These are the implementations to test
    implementations = [
        optimisation.RandomOptimisation(),
        optimisation.ParticleFilter(),
        optimisation.GPyOpt(),
        optimisation.CMAOptimisation(),
        optimisation.Ampgo(),
        optimisation.TuRBO(max_evals=11, n_training_steps=30)
        # optimisation.Pygmo,  # excluded because of a mandatory install
        # optimisation.PyScannerBit  # excluded because of a mandatory install
    ]

    for procedure in implementations:
        experiment = exp.OptimisationExperiment(procedure, str(tmp_path))
        experiment.run(func.Himmelblau(), finish_line=250)
        shutil.rmtree(str(tmp_path))
Example #2
0
def test_experiment_optimisation():
    procedure = TmpProcedure()
    path = "./tmpexperiment"
    experiment = exp.OptimisationExperiment(procedure, path)
    # Test start_experiment event
    experiment._event_start_experiment()
    assert experiment.best_x is None
    assert experiment.best_y is None
    # Test that end experiment event does return nothing
    # TODO: how to test a function that does nothing?
    assert experiment._event_end_experiment() is None
    x = np.random.rand(100, 2)
    y = x[:, 1]
    m = np.argmin(y)
    experiment._event_new_samples(x, y)
    assert np.array_equal(experiment.best_x[0], x[m]) is True
    assert np.array_equal(experiment.best_y[0], y[m]) is True
    # Test make metrics function
    metrics = experiment.make_metrics()
    assert isinstance(experiment.make_metrics(), dict)
    assert metrics['best_point'] == x[m].tolist()
    assert metrics['best_value'] == y[m].tolist()
Example #3
0
def test_optimisation_turbo(tmp_path):
    procedure = optimisation.TuRBO(max_evals=11, n_training_steps=30)
    experiment = exp.OptimisationExperiment(procedure, str(tmp_path))
    experiment.run(func.Himmelblau(), finish_line=250)
    shutil.rmtree(str(tmp_path))
Example #4
0
def test_optimisation_cmae(tmp_path):
    procedure = optimisation.CMAOptimisation()
    experiment = exp.OptimisationExperiment(procedure, str(tmp_path))
    experiment.run(func.Himmelblau(), finish_line=250)
    shutil.rmtree(str(tmp_path))
Example #5
0
def test_optimisation_particlefilter(tmp_path):
    procedure = optimisation.ParticleFilter()
    experiment = exp.OptimisationExperiment(procedure, str(tmp_path))
    experiment.run(func.Himmelblau(), finish_line=250)
    shutil.rmtree(str(tmp_path))