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/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 diff --git a/requirements-freeze.txt b/requirements-freeze.txt index bd764af..328b1df 100644 --- a/requirements-freeze.txt +++ b/requirements-freeze.txt @@ -8,7 +8,7 @@ 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 @@ -19,8 +19,8 @@ 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 @@ -28,17 +28,17 @@ MarkupSafe==1.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[browniebee]==0.7.7 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 @@ -47,7 +47,7 @@ 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==4.4.0