4
4
The handler functions are mapped to the OpenAPI specification through the "operationId" field
5
5
in the specification.yml file found in the folder "openapi" in the root of this project.
6
6
"""
7
+
7
8
import os
8
9
import platform
9
10
import time
21
22
from rq .command import send_stop_job_command
22
23
from redis import Redis
23
24
from ProcessOptimizer import Optimizer , expected_minimum
24
- from ProcessOptimizer .plots import plot_objective , plot_convergence , plot_Pareto
25
+ from ProcessOptimizer .plots import (
26
+ plot_objective ,
27
+ plot_convergence ,
28
+ plot_Pareto ,
29
+ plot_brownie_bee_frontend ,
30
+ )
25
31
from ProcessOptimizer .space import Real
26
32
from ProcessOptimizer .space .constraints import SumEquals
27
33
import matplotlib .pyplot as plt
28
34
import numpy
29
35
import connexion
30
36
31
- from optimizerapi .plot_patch import plot_brownie_bee
32
37
from .securepickle import pickleToString , get_crypto
33
38
34
39
numpy .random .seed (42 )
@@ -82,7 +87,7 @@ def disconnect_check():
82
87
except NoSuchJobError :
83
88
print ("Creating new job" )
84
89
job = queue .enqueue (do_run_work , body , job_id = job_id , result_ttl = TTL , timeout = WORKER_TIMEOUT )
85
- while job .return_value is None :
90
+ while job .return_value () is None :
86
91
if disconnect_check ():
87
92
try :
88
93
print (f"Client disconnected, cancelling job { job .id } " )
@@ -93,7 +98,7 @@ def disconnect_check():
93
98
pass
94
99
return {}
95
100
time .sleep (0.2 )
96
- return job .return_value
101
+ return job .return_value ()
97
102
return do_run_work (body )
98
103
99
104
@@ -124,11 +129,13 @@ def __handle_run(body) -> dict:
124
129
)
125
130
space = [
126
131
(
127
- convert_number_type (x ["from" ], x ["type" ]),
128
- convert_number_type (x ["to" ], x ["type" ]),
132
+ (
133
+ convert_number_type (x ["from" ], x ["type" ]),
134
+ convert_number_type (x ["to" ], x ["type" ]),
135
+ )
136
+ if (x ["type" ] == "discrete" or x ["type" ] == "continuous" )
137
+ else tuple (x ["categories" ])
129
138
)
130
- if (x ["type" ] == "discrete" or x ["type" ] == "continuous" )
131
- else tuple (x ["categories" ])
132
139
for x in cfg ["space" ]
133
140
]
134
141
dimensions = [x ["name" ] for x in cfg ["space" ]]
@@ -248,9 +255,10 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space):
248
255
if "experimentSuggestionCount" in extras :
249
256
experiment_suggestion_count = extras ["experimentSuggestionCount" ]
250
257
251
-
252
258
if "constraints" in cfg and len (cfg ["constraints" ]) > 0 :
253
- next_exp = optimizer .ask (n_points = experiment_suggestion_count , strategy = "cl_min" )
259
+ next_exp = optimizer .ask (
260
+ n_points = experiment_suggestion_count , strategy = "cl_min"
261
+ )
254
262
else :
255
263
next_exp = optimizer .ask (n_points = experiment_suggestion_count )
256
264
if len (next_exp ) > 0 and not any (isinstance (x , list ) for x in next_exp ):
@@ -264,7 +272,7 @@ def process_result(result, optimizer, dimensions, cfg, extras, data, space):
264
272
if graph_format == "png" :
265
273
for idx , model in enumerate (result ):
266
274
if "single" in graphs_to_return :
267
- bb_plots = plot_brownie_bee (model , max_quality = max_quality )
275
+ bb_plots = plot_brownie_bee_frontend (model , max_quality = max_quality )
268
276
for i , plot in enumerate (bb_plots ):
269
277
pic_io_bytes = io .BytesIO ()
270
278
plot .savefig (pic_io_bytes , format = "png" )
0 commit comments