From 8b2dfa9c6896e90448e214de4428346bdc2f6c85 Mon Sep 17 00:00:00 2001 From: SRFU Date: Tue, 6 Sep 2022 13:35:36 +0200 Subject: [PATCH 1/9] feat: Allows for not creating graphs --- optimizerapi/optimizer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/optimizerapi/optimizer.py b/optimizerapi/optimizer.py index 0ede01a..747312a 100644 --- a/optimizerapi/optimizer.py +++ b/optimizerapi/optimizer.py @@ -179,6 +179,10 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space): "plots": plots, "result": result_details } + # GraphFormat should, at the moment, be either "png" or "none". Default (legacy) + # behavior is "png", so the API returns png images. Any other input is interpreted + # as "None" at the moment. + graph_format = extras.get("graphFormat","png") # In the following section details that should be reported to # clients should go into the "resultDetails" dictionary and plots @@ -190,7 +194,7 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space): next_exp = optimizer.ask(n_points=experiment_suggestion_count) result_details["next"] = round_to_length_scales(next_exp, optimizer.space) - if len(data) >= cfg["initialPoints"]: + if len(data) >= cfg["initialPoints"] and graph_format == "png": # Some calculations are only possible if the model has # processed more than "initialPoints" data points result_details["models"] = [process_model( From 32a022631f371468143453fce38a585d9677b5a6 Mon Sep 17 00:00:00 2001 From: SRFU Date: Wed, 7 Sep 2022 11:06:40 +0200 Subject: [PATCH 2/9] chore: Added virtual environment to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ff517b5..6036b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ **.pyc .vscode /tmp -version.txt \ No newline at end of file +version.txt +.env \ No newline at end of file From 15ebb6a39a7c7bc7ac5a225b2ad10186a37e9468 Mon Sep 17 00:00:00 2001 From: SRFU Date: Wed, 7 Sep 2022 11:06:59 +0200 Subject: [PATCH 3/9] test: started testing for deselcting plotting --- tests/test_optimizer.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py index 3d73a21..cf16a49 100644 --- a/tests/test_optimizer.py +++ b/tests/test_optimizer.py @@ -71,6 +71,26 @@ def test_generates_plots_when_run_with_more_than_initialPoints_samples(): assert len(result["plots"]) == 2 +def test_deselcting_plots(): + result = optimizer.run(body={ + "data": sampleData, + "optimizerConfig": sampleConfig, + "extras": {"graphFormat","png"} + }) + validateResult(result) + assert len(result["result"]["models"]) > 0 + assert len(result["plots"]) == 2 + + result = optimizer.run(body={ + "data": sampleData, + "optimizerConfig": sampleConfig, + "extras": {"graphFormat","none"} + }) + validateResult(result) + assert len(result["result"]["models"]) > 0 + assert len(result["plots"]) == 0 + + def test_can_accept_multi_objective_data(): result = optimizer.run(body={ "data": sampleMultiObjectiveData, From 9fe4b2c5181d046e1b95e85b2b374e7c966f0a3a Mon Sep 17 00:00:00 2001 From: SRFU Date: Wed, 7 Sep 2022 11:21:45 +0200 Subject: [PATCH 4/9] fix: SAtupid mistake in new tests fixed --- tests/test_optimizer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py index cf16a49..a869d5e 100644 --- a/tests/test_optimizer.py +++ b/tests/test_optimizer.py @@ -71,20 +71,20 @@ def test_generates_plots_when_run_with_more_than_initialPoints_samples(): assert len(result["plots"]) == 2 -def test_deselcting_plots(): +def test_deselecting_plots(): result = optimizer.run(body={ "data": sampleData, "optimizerConfig": sampleConfig, - "extras": {"graphFormat","png"} + "extras": {"graphFormat": "png"} }) validateResult(result) assert len(result["result"]["models"]) > 0 assert len(result["plots"]) == 2 - + result = optimizer.run(body={ "data": sampleData, "optimizerConfig": sampleConfig, - "extras": {"graphFormat","none"} + "extras": {"graphFormat": "none"} }) validateResult(result) assert len(result["result"]["models"]) > 0 From c1802ce4c3c2c646fd1a8514030de9ea6842c92f Mon Sep 17 00:00:00 2001 From: SRFU Date: Wed, 7 Sep 2022 11:22:47 +0200 Subject: [PATCH 5/9] fix: Returning models if plot are deselected --- optimizerapi/optimizer.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/optimizerapi/optimizer.py b/optimizerapi/optimizer.py index 747312a..0e268bd 100644 --- a/optimizerapi/optimizer.py +++ b/optimizerapi/optimizer.py @@ -182,7 +182,7 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space): # GraphFormat should, at the moment, be either "png" or "none". Default (legacy) # behavior is "png", so the API returns png images. Any other input is interpreted # as "None" at the moment. - graph_format = extras.get("graphFormat","png") + graph_format = extras.get("graphFormat", "png") # In the following section details that should be reported to # clients should go into the "resultDetails" dictionary and plots @@ -194,28 +194,29 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space): next_exp = optimizer.ask(n_points=experiment_suggestion_count) result_details["next"] = round_to_length_scales(next_exp, optimizer.space) - if len(data) >= cfg["initialPoints"] and graph_format == "png": + if len(data) >= cfg["initialPoints"]: # Some calculations are only possible if the model has # processed more than "initialPoints" data points result_details["models"] = [process_model( model, optimizer) for model in result] - for idx, model in enumerate(result): - plot_convergence(model) - add_plot(plots, f"convergence_{idx}") - - plot_objective(model, dimensions=dimensions, - usepartialdependence=False, - show_confidence=True) - add_plot(plots, f"objective_{idx}") - - if optimizer.n_objectives == 1: - minimum = expected_minimum(result[0]) - - result_details["expected_minimum"] = [ - round_to_length_scales(minimum[0], optimizer.space), round(minimum[1], 2)] - else: - plot_Pareto(optimizer) - add_plot(plots, "pareto") + if graph_format == "png": + for idx, model in enumerate(result): + plot_convergence(model) + add_plot(plots, f"convergence_{idx}") + + plot_objective(model, dimensions=dimensions, + usepartialdependence=False, + show_confidence=True) + add_plot(plots, f"objective_{idx}") + + if optimizer.n_objectives == 1: + minimum = expected_minimum(result[0]) + + result_details["expected_minimum"] = [ + round_to_length_scales(minimum[0], optimizer.space), round(minimum[1], 2)] + else: + plot_Pareto(optimizer) + add_plot(plots, "pareto") result_details["pickled"] = pickleToString( result, get_crypto()) From 06e5868b26dfd5d964076e3bcfb8d8b7dfbcda66 Mon Sep 17 00:00:00 2001 From: SRFU Date: Wed, 7 Sep 2022 11:24:14 +0200 Subject: [PATCH 6/9] doc: Explained how new test works --- tests/test_optimizer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py index a869d5e..fa63859 100644 --- a/tests/test_optimizer.py +++ b/tests/test_optimizer.py @@ -81,6 +81,7 @@ def test_deselecting_plots(): assert len(result["result"]["models"]) > 0 assert len(result["plots"]) == 2 + # If grapFormat is none, no plots should be returned. This should be faster. result = optimizer.run(body={ "data": sampleData, "optimizerConfig": sampleConfig, From 1def58f2a0b195de8b83243fe8fe7a31d483acb8 Mon Sep 17 00:00:00 2001 From: SRFU Date: Wed, 7 Sep 2022 11:26:38 +0200 Subject: [PATCH 7/9] chore: Stupid spelling mistakes are stupid --- tests/test_optimizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py index fa63859..33baa9b 100644 --- a/tests/test_optimizer.py +++ b/tests/test_optimizer.py @@ -81,7 +81,7 @@ def test_deselecting_plots(): assert len(result["result"]["models"]) > 0 assert len(result["plots"]) == 2 - # If grapFormat is none, no plots should be returned. This should be faster. + # If graphFormat is none, no plots should be returned. This should be faster. result = optimizer.run(body={ "data": sampleData, "optimizerConfig": sampleConfig, From 34000e7bde37e3ea35f4a445b3b9886a0b38b049 Mon Sep 17 00:00:00 2001 From: SRFU Date: Fri, 9 Sep 2022 13:40:55 +0200 Subject: [PATCH 8/9] teast: Fixing te4sts for deselecting plotting Splitting the test into three, one for explicit new behavior, one for explicitly wanting the old behavior, and one where "extras" is empty. --- tests/test_optimizer.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py index 33baa9b..3dfaaa1 100644 --- a/tests/test_optimizer.py +++ b/tests/test_optimizer.py @@ -71,7 +71,18 @@ def test_generates_plots_when_run_with_more_than_initialPoints_samples(): assert len(result["plots"]) == 2 -def test_deselecting_plots(): +def test_specifying_png_plots(): + result = optimizer.run(body={ + "data": sampleData, + "optimizerConfig": sampleConfig, + "extras": {"graphFormat": "png"} + }) + validateResult(result) + assert len(result["result"]["models"]) > 0 + assert len(result["plots"]) == 2 + + +def test_specifying_png_plots(): result = optimizer.run(body={ "data": sampleData, "optimizerConfig": sampleConfig, @@ -81,6 +92,19 @@ def test_deselecting_plots(): assert len(result["result"]["models"]) > 0 assert len(result["plots"]) == 2 + +def test_specifying_empty_extras_preserve_legacy_plotting(): + result = optimizer.run(body={ + "data": sampleData, + "optimizerConfig": sampleConfig, + "extras": {} + }) + validateResult(result) + assert len(result["result"]["models"]) > 0 + assert len(result["plots"]) == 2 + + +def test_deselecting_plots(): # If graphFormat is none, no plots should be returned. This should be faster. result = optimizer.run(body={ "data": sampleData, From b0d3107b030235de672752c43d5da5adf7eb2164 Mon Sep 17 00:00:00 2001 From: SRFU Date: Fri, 9 Sep 2022 13:48:08 +0200 Subject: [PATCH 9/9] chore: Removed duplicated test --- tests/test_optimizer.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py index 3dfaaa1..41cdfa3 100644 --- a/tests/test_optimizer.py +++ b/tests/test_optimizer.py @@ -82,17 +82,6 @@ def test_specifying_png_plots(): assert len(result["plots"]) == 2 -def test_specifying_png_plots(): - result = optimizer.run(body={ - "data": sampleData, - "optimizerConfig": sampleConfig, - "extras": {"graphFormat": "png"} - }) - validateResult(result) - assert len(result["result"]["models"]) > 0 - assert len(result["plots"]) == 2 - - def test_specifying_empty_extras_preserve_legacy_plotting(): result = optimizer.run(body={ "data": sampleData,