From 04cc5c869fa611cb849e1af3fe69ba2f7eb0ce0b Mon Sep 17 00:00:00 2001 From: "Grossberger Lukas (CR/AIR2.2)" Date: Mon, 5 Jun 2023 15:39:07 +0200 Subject: [PATCH] add test for dask distributed example Signed-off-by: Grossberger Lukas (CR/AIR2.2) --- blackboxopt/examples/dask_distributed.py | 6 +++++- tests/examples_test.py | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/blackboxopt/examples/dask_distributed.py b/blackboxopt/examples/dask_distributed.py index aa0a8a8a..65c745cf 100644 --- a/blackboxopt/examples/dask_distributed.py +++ b/blackboxopt/examples/dask_distributed.py @@ -27,7 +27,7 @@ def evaluation_function(eval_spec: EvaluationSpecification) -> Evaluation: ) -if __name__ == "__main__": +def main(): space = ps.ParameterSpace() space.add(ps.ContinuousParameter("p1", (-1.0, 1.0))) optimizer = RandomSearch( @@ -42,3 +42,7 @@ def evaluation_function(eval_spec: EvaluationSpecification) -> Evaluation: n_successes = len([e for e in evaluations if not e.all_objectives_none]) print(f"Successfully evaluated {n_successes}/{len(evaluations)}") + + +if __name__ == "__main__": + main() diff --git a/tests/examples_test.py b/tests/examples_test.py index 423e76c4..2cab18ee 100644 --- a/tests/examples_test.py +++ b/tests/examples_test.py @@ -2,11 +2,12 @@ import pytest -from blackboxopt.examples import multi_objective_multi_param +from blackboxopt.examples import dask_distributed, multi_objective_multi_param -@pytest.mark.parametrize("example_module", [multi_objective_multi_param]) -@pytest.mark.integration_test +@pytest.mark.parametrize( + "example_module", [multi_objective_multi_param, dask_distributed] +) def test_full_loop_examples(tmp_path, monkeypatch, example_module): if not example_module: return @@ -17,6 +18,7 @@ def test_full_loop_examples(tmp_path, monkeypatch, example_module): def run_sequential_mocked(*args, **kwargs): kwargs["timeout_s"] = 5 + kwargs["max_evaluations"] = None return run_sequential(*args, **kwargs) monkeypatch.setattr(example_module, "run_optimization_loop", run_sequential_mocked)