From 4b9d721768f2e8798e6dd189d9944318ed502570 Mon Sep 17 00:00:00 2001 From: abbl-DTI Date: Wed, 28 Sep 2022 16:04:00 +0200 Subject: [PATCH 1/5] Changes made so for Pareto plotting --- optimizerapi/optimizer.py | 56 +++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/optimizerapi/optimizer.py b/optimizerapi/optimizer.py index 0e268bd..f8fd8af 100644 --- a/optimizerapi/optimizer.py +++ b/optimizerapi/optimizer.py @@ -17,7 +17,7 @@ from rq import Queue from redis import Redis from ProcessOptimizer import Optimizer, expected_minimum -from ProcessOptimizer.plots import plot_objective, plot_convergence, plot_Pareto +from ProcessOptimizer.plots import plot_objective, plot_convergence, plot_Pareto_bokeh from ProcessOptimizer.space import Real import matplotlib.pyplot as plt import numpy @@ -162,7 +162,7 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space): a dictionary containing results and plots. The dictionary has this structure: { - plots: [{id: plotname, plot: BASE64 encoded png}], + plots: [{id: plotname, plot: BASE64 encoded png or JSON-object}], result: { dict with relevant properties, e.g., suggestions for next experiment, model representation etc.} @@ -202,12 +202,12 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space): if graph_format == "png": for idx, model in enumerate(result): plot_convergence(model) - add_plot(plots, f"convergence_{idx}") + add_plt_plot(plots, f"convergence_{idx}") plot_objective(model, dimensions=dimensions, usepartialdependence=False, show_confidence=True) - add_plot(plots, f"objective_{idx}") + add_plt_plot(plots, f"objective_{idx}") if optimizer.n_objectives == 1: minimum = expected_minimum(result[0]) @@ -215,8 +215,11 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space): result_details["expected_minimum"] = [ round_to_length_scales(minimum[0], optimizer.space), round(minimum[1], 2)] else: - plot_Pareto(optimizer) - add_plot(plots, "pareto") + json_bokeh = plot_Pareto_bokeh(optimizer, + dimensions=dimensions, + return_data=False, + return_type_bokeh='json') + add_JSON_item(plots, json_bokeh, id="pareto") result_details["pickled"] = pickleToString( result, get_crypto()) @@ -250,7 +253,7 @@ def process_model(model, optimizer): return result_details -def add_plot(result, id="generic", close=True, debug=False): +def add_plt_plot(result, id="generic", close=True, debug=False): """Add the current figure to result as a base64 encoded string. This function should be called after every plot that is generated. @@ -281,14 +284,45 @@ def add_plot(result, id="generic", close=True, debug=False): }) if debug: - with open('tmp/process_optimizer_' + id + '.png', 'wb') as imgfile: - plt.savefig(imgfile, bbox_inches='tight', pad_inches=0) - - # print("IMAGE: " + str(pic_hash, "utf-8")) + # with open('tmp/process_optimizer_' + id + '.png', 'wb') as imgfile: + # plt.savefig(imgfile, bbox_inches='tight', pad_inches=0) + print("IMAGE: " + str(pic_hash, "utf-8")) if close: plt.clf() +def add_JSON_item(result, json_obj, id="generic", clean=True, debug=False): + """Add the 'json_obj' to result as a base64 encoded string. + + This function should be called after every plot that is generated. + It takes the current state of the figure canvas and writes it to + a base64 encoded string which is then appended to the list supplied. + + Parameters + ---------- + result : list + The list of plots to which new plots should be addeed. + json_obj : json.dumps-object + A Bokeh json-export object that . + id : str + Identifier for the plot (default is "generic") + debug : bool + Indicate if plots should be written to local files. + If set to True plots are stored in tmp/process_optimizer_[id].png + relative to current working directory. (default is False) + """ + result.append({ + "id": id, + "plot": json_obj + }) + if debug: + print("JSON:\n") + print(json_obj) + + if clean: + del json_obj + + def round_to_length_scales(x, space): """ Rounds a suggested experiment to to the length scales of each dimension From 76640fc320f5c4976974b0c28e67857d54824ddf Mon Sep 17 00:00:00 2001 From: abbl-DTI Date: Mon, 31 Oct 2022 09:42:09 +0100 Subject: [PATCH 2/5] Update 'requirements-freeze.txt' --- LICENSE | 2 +- requirements-freeze.txt | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/LICENSE b/LICENSE index 2796459..d81a48d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2021, BoostV +Copyright (c) 2022, BoostV All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/requirements-freeze.txt b/requirements-freeze.txt index 857e588..6a32eb8 100644 --- a/requirements-freeze.txt +++ b/requirements-freeze.txt @@ -1,5 +1,5 @@ attrs==20.3.0 -bokeh==2.2.3 +bokeh==2.4.3 certifi==2020.12.5 cffi==1.14.5 chardet==4.0.0 @@ -9,7 +9,7 @@ colorama==0.4.4 connexion==2.7.0 cryptography==3.4.7 cycler==0.10.0 -deap==1.3.1 +deap==1.3.3 Deprecated==1.2.13 docopt==0.6.2 Flask==1.1.2 @@ -24,13 +24,13 @@ json-tricks==3.15.5 jsonschema==3.2.0 kiwisolver==1.3.1 MarkupSafe==1.1.1 -matplotlib==3.3.4 -numpy==1.23.0 +matplotlib==3.5.3 +numpy==1.23.3 openapi-spec-validator==0.2.9 packaging==20.9 Pillow==9.0.1 pluggy==0.13.1 -ProcessOptimizer==0.7.3 +ProcessOptimizer==0.7.5 py==1.10.0 pycparser==2.20 pyparsing==2.4.7 @@ -38,17 +38,17 @@ pyrsistent==0.17.3 pytest==6.2.2 pytest-watch==4.2.0 python-dateutil==2.8.1 -PyYAML==5.4.1 +PyYAML==6.0 redis==4.0.2 requests==2.25.1 rq==1.10.0 -scikit-learn==0.24.2 -scipy==1.6.0 -six==1.15.0 +scikit-learn==1.1.2 +scipy==1.9.1 +six==1.16.0 swagger-ui-bundle==0.0.8 threadpoolctl==2.1.0 toml==0.10.2 -tornado==6.1 +tornado==6.2 typing-extensions==3.7.4.3 urllib3==1.26.5 waitress==2.1.1 From 8dd99a1fad866de275ff83b40a7017eb70c35c28 Mon Sep 17 00:00:00 2001 From: abbl-DTI Date: Mon, 31 Oct 2022 09:54:11 +0100 Subject: [PATCH 3/5] typing-extensions version updated --- requirements-freeze.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-freeze.txt b/requirements-freeze.txt index 6a32eb8..9ad0e76 100644 --- a/requirements-freeze.txt +++ b/requirements-freeze.txt @@ -49,7 +49,7 @@ swagger-ui-bundle==0.0.8 threadpoolctl==2.1.0 toml==0.10.2 tornado==6.2 -typing-extensions==3.7.4.3 +typing-extensions==3.10.0 urllib3==1.26.5 waitress==2.1.1 watchdog==2.0.2 From fc45c5af475218ca4e8fa2a9850d3db4beafcebe Mon Sep 17 00:00:00 2001 From: abbl-DTI Date: Thu, 3 Nov 2022 15:13:10 +0100 Subject: [PATCH 4/5] Update to latest ProcessOptimizer --- requirements-freeze.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-freeze.txt b/requirements-freeze.txt index 9ad0e76..645e7f0 100644 --- a/requirements-freeze.txt +++ b/requirements-freeze.txt @@ -30,7 +30,7 @@ openapi-spec-validator==0.2.9 packaging==20.9 Pillow==9.0.1 pluggy==0.13.1 -ProcessOptimizer==0.7.5 +ProcessOptimizer==0.7.6 py==1.10.0 pycparser==2.20 pyparsing==2.4.7 diff --git a/requirements.txt b/requirements.txt index 449c2bd..865f686 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ connexion==2.7.0 connexion[swagger-ui] Flask==1.1.2 Flask-Cors==3.0.10 -ProcessOptimizer==0.7.3 +ProcessOptimizer==0.7.6 json-tricks==3.15.5 cryptography==3.4.7 waitress==2.1.1 From e92069ecb0de07a88dc062c830a4ad99b2cffc65 Mon Sep 17 00:00:00 2001 From: Jakob Langdal Date: Fri, 4 Nov 2022 12:44:38 +0000 Subject: [PATCH 5/5] Use ProcessOptimizer with locked deps Use the Brownie Bee specific package of ProcessOptimizer. Update frozen requirements according to README --- requirements-freeze.txt | 23 ++++++++++++----------- requirements.txt | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/requirements-freeze.txt b/requirements-freeze.txt index 645e7f0..7cfd28d 100644 --- a/requirements-freeze.txt +++ b/requirements-freeze.txt @@ -8,36 +8,37 @@ clickclick==20.10.2 colorama==0.4.4 connexion==2.7.0 cryptography==3.4.7 -cycler==0.10.0 +cycler==0.11.0 deap==1.3.3 Deprecated==1.2.13 docopt==0.6.2 Flask==1.1.2 Flask-Cors==3.0.10 +fonttools==4.38.0 idna==2.10 inflection==0.5.1 iniconfig==1.1.1 itsdangerous==1.1.0 -Jinja2==2.11.3 -joblib==1.0.1 +Jinja2==3.1.2 +joblib==1.2.0 json-tricks==3.15.5 jsonschema==3.2.0 -kiwisolver==1.3.1 -MarkupSafe==1.1.1 +kiwisolver==1.4.4 +MarkupSafe==2.1.1 matplotlib==3.5.3 numpy==1.23.3 openapi-spec-validator==0.2.9 -packaging==20.9 -Pillow==9.0.1 +packaging==21.3 +Pillow==9.3.0 pluggy==0.13.1 ProcessOptimizer==0.7.6 py==1.10.0 pycparser==2.20 -pyparsing==2.4.7 +pyparsing==3.0.9 pyrsistent==0.17.3 pytest==6.2.2 pytest-watch==4.2.0 -python-dateutil==2.8.1 +python-dateutil==2.8.2 PyYAML==6.0 redis==4.0.2 requests==2.25.1 @@ -46,10 +47,10 @@ scikit-learn==1.1.2 scipy==1.9.1 six==1.16.0 swagger-ui-bundle==0.0.8 -threadpoolctl==2.1.0 +threadpoolctl==3.1.0 toml==0.10.2 tornado==6.2 -typing-extensions==3.10.0 +typing_extensions==4.4.0 urllib3==1.26.5 waitress==2.1.1 watchdog==2.0.2 diff --git a/requirements.txt b/requirements.txt index 865f686..3ad76ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ connexion==2.7.0 connexion[swagger-ui] Flask==1.1.2 Flask-Cors==3.0.10 -ProcessOptimizer==0.7.6 +ProcessOptimizer[browniebee]==0.7.6 json-tricks==3.15.5 cryptography==3.4.7 waitress==2.1.1