mg-pso-gui 0.1.13__py3-none-any.whl → 0.1.40__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- {mg_pso_gui-0.1.13.dist-info → mg_pso_gui-0.1.40.dist-info}/METADATA +1 -1
- {mg_pso_gui-0.1.13.dist-info → mg_pso_gui-0.1.40.dist-info}/RECORD +14 -12
- mgpsogui/gui/HomePage.py +566 -510
- mgpsogui/gui/RunTab/RunTab.py +1 -20
- mgpsogui/gui/VisualizeTab/SideBar.py +108 -0
- mgpsogui/gui/VisualizeTab/VisualizeTab.py +9 -5
- mgpsogui/gui/images/test.png +0 -0
- mgpsogui/util/GraphGenerator.py +34 -0
- mgpsogui/util/PSORunner.py +39 -76
- mgpsogui/util/recosu/pso/csip_access.py +2 -35
- mgpsogui/util/recosu/pso/pso.py +0 -48
- {mg_pso_gui-0.1.13.dist-info → mg_pso_gui-0.1.40.dist-info}/WHEEL +0 -0
- {mg_pso_gui-0.1.13.dist-info → mg_pso_gui-0.1.40.dist-info}/entry_points.txt +0 -0
- {mg_pso_gui-0.1.13.dist-info → mg_pso_gui-0.1.40.dist-info}/top_level.txt +0 -0
mgpsogui/gui/HomePage.py
CHANGED
@@ -30,6 +30,7 @@ from queue import Empty
|
|
30
30
|
|
31
31
|
from ..util import PSORunner
|
32
32
|
from ..util import GraphGenerator
|
33
|
+
from ..util.CTkToolTip import CTkToolTip as ctt
|
33
34
|
|
34
35
|
import subprocess
|
35
36
|
import plotly.express as px
|
@@ -56,517 +57,572 @@ stderr_queue = Queue()
|
|
56
57
|
cosu_queue = Queue()
|
57
58
|
|
58
59
|
class App(customtkinter.CTk):
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
60
|
+
def __init__(self):
|
61
|
+
super().__init__()
|
62
|
+
|
63
|
+
self.option_manager = om.OptionManager()
|
64
|
+
|
65
|
+
self.graph_selector_value = tk.StringVar()
|
66
|
+
self.graph_selector_value.set("Best Cost Stacked")
|
67
|
+
|
68
|
+
self.selected_csv = tk.StringVar()
|
69
|
+
self.selected_csv.set("No files found...")
|
70
|
+
self.open_file = "None"
|
71
|
+
self.csv_data = None
|
72
|
+
|
73
|
+
self.selected_x = tk.StringVar()
|
74
|
+
self.selected_x.set("time")
|
75
|
+
|
76
|
+
self.selected_y1 = tk.StringVar()
|
77
|
+
self.selected_y1.set("NONE")
|
78
|
+
|
79
|
+
self.selected_y2 = tk.StringVar()
|
80
|
+
self.selected_y2.set("NONE")
|
81
|
+
|
82
|
+
self.running_config = None
|
83
|
+
self.selected_graph_name = None
|
84
|
+
|
85
|
+
self.train_process = None
|
86
|
+
self.minikube_process = None
|
87
|
+
self.data_x = [0]
|
88
|
+
self.data_y = [0]
|
89
|
+
|
90
|
+
self.image_scale = 1
|
91
|
+
self.image_width = 1280
|
92
|
+
self.image_height = 720
|
93
|
+
self.progress_data = None
|
94
|
+
self.calibration_data = None
|
95
|
+
|
96
|
+
# configure window
|
97
|
+
self.title("CSIP PSO")
|
98
|
+
self.geometry(f"{1920}x{1080}")
|
99
|
+
|
100
|
+
# configure grid layout (4x4)
|
101
|
+
self.grid_columnconfigure(0, weight=1)
|
102
|
+
self.grid_rowconfigure(1, weight=1)
|
103
|
+
|
104
|
+
header_padding_x = (5, 5)
|
105
|
+
header_padding_y = (10, 10)
|
106
|
+
|
107
|
+
self.sidebar_frame = customtkinter.CTkFrame(self, width=140, corner_radius=0)
|
108
|
+
self.sidebar_frame.grid(row=0, column=0, sticky="nsew")
|
109
|
+
self.sidebar_frame.grid_columnconfigure(4, weight=1)
|
110
|
+
self.logo_label = customtkinter.CTkLabel(self.sidebar_frame, text="CSIP PSO", font=customtkinter.CTkFont(size=20, weight="bold"))
|
111
|
+
self.logo_label.grid(row=0, column=0, padx=(20, 10), pady=header_padding_y)
|
112
|
+
self.save_button = customtkinter.CTkButton(self.sidebar_frame, text="Save", width=60, command=self.save_project)
|
113
|
+
self.save_button.grid(row=0, column=1, padx=header_padding_x, pady=header_padding_y)
|
114
|
+
self.load_button = customtkinter.CTkButton(self.sidebar_frame, text="Load", width=60, command=self.load_project)
|
115
|
+
self.load_button.grid(row=0, column=2, padx=header_padding_x, pady=header_padding_y)
|
116
|
+
|
117
|
+
# 4 is service URL
|
118
|
+
self.service_label = customtkinter.CTkLabel(self.sidebar_frame, text="Service:", anchor="w")
|
119
|
+
self.service_label.grid(row=0, column=3, padx=(80, 5), pady=header_padding_y)
|
120
|
+
self.service_url = customtkinter.CTkEntry(self.sidebar_frame, textvariable=self.option_manager.get_arguments()['url'])
|
121
|
+
self.service_url.grid(row=0, column=4, columnspan=1, padx=header_padding_x, pady=header_padding_y, sticky="nsew")
|
122
|
+
refresh_image = customtkinter.CTkImage(Image.open(os.path.join("./images", "refresh.png")), size=(20, 20))
|
123
|
+
self.refresh_button = customtkinter.CTkButton(self.sidebar_frame, text=None, width=30, image=refresh_image, command=self.load)
|
124
|
+
ctt(self.refresh_button, delay=0.1, alpha=0.95, message="Connect to Service")
|
125
|
+
self.refresh_button.grid(row=0, column=5, padx=(5, 80), pady=header_padding_y)
|
126
|
+
|
127
|
+
self.scaling_label = customtkinter.CTkLabel(self.sidebar_frame, text="Scale:", anchor="w")
|
128
|
+
self.scaling_label.grid(row=0, column=6, padx=header_padding_x, pady=header_padding_y)
|
129
|
+
self.scaling_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["50%", "75%", "100%", "125%", "150%", "175%", "200%"], width=60,
|
130
|
+
command=self.change_scaling_event)
|
131
|
+
self.scaling_optionemenu.grid(row=0, column=7, padx=header_padding_x, pady=header_padding_y)
|
132
|
+
self.scaling_optionemenu.set("100%")
|
133
|
+
|
134
|
+
expand_image = customtkinter.CTkImage(Image.open(os.path.join("./images", "expand.png")), size=(20, 20))
|
135
|
+
self.new_window = customtkinter.CTkButton(self.sidebar_frame, text=None, width=30, image=expand_image, command=self.new_window)
|
136
|
+
ctt(self.new_window, delay=0.1, alpha=0.95, message="Open New Window")
|
137
|
+
self.new_window.grid(row=0, column=8, padx=(5, 20), pady=header_padding_y)
|
138
|
+
|
139
|
+
self.tabview = customtkinter.CTkTabview(self, bg_color="transparent", fg_color="transparent")
|
140
|
+
self.tabview.grid(row=1, column=0, padx=(0, 0), pady=(10, 10), sticky="nsew")
|
141
|
+
tab1 = "Platform"
|
142
|
+
tab2 = "Setup"
|
143
|
+
tab3 = "Logs"
|
144
|
+
tab4 = "Results"
|
145
|
+
#tab5 = "Results"
|
146
|
+
|
147
|
+
self.tabview.add(tab1)
|
148
|
+
self.tabview.add(tab2)
|
149
|
+
self.tabview.add(tab4)
|
150
|
+
self.tabview.add(tab3)
|
151
|
+
#self.tabview.add(tab5)
|
152
|
+
|
153
|
+
#self.tabview.configure(state="disabled")
|
154
|
+
|
155
|
+
pt.create_tab(self, self.tabview.tab(tab1))
|
156
|
+
st.create_tab(self, self.tabview.tab(tab2))
|
157
|
+
rt.create_tab(self, self.tabview.tab(tab3))
|
158
|
+
vt.create_tab(self, self.tabview.tab(tab4))
|
159
|
+
|
160
|
+
self.footer_frame = customtkinter.CTkFrame(self, corner_radius=0)
|
161
|
+
self.footer_frame.grid(row=2, column=0, sticky="nsew")
|
162
|
+
self.footer_frame.grid_columnconfigure(4, weight=1)
|
163
|
+
|
164
|
+
self.footer_progress_label = customtkinter.CTkLabel(self.footer_frame, text="Stopped", width=150, font=customtkinter.CTkFont(size=16, weight="bold"), anchor="w")
|
165
|
+
self.footer_progress_label.grid(row=0, column=0, padx=(20, 5), pady=header_padding_y)
|
166
|
+
|
167
|
+
self.footer_progress_bar = customtkinter.CTkProgressBar(self.footer_frame)
|
168
|
+
self.footer_progress_bar.grid(row=0, column=4, padx=(50, 100), pady=header_padding_y, sticky="ew")
|
169
|
+
self.footer_progress_bar.set(0)
|
170
|
+
|
171
|
+
self.algorithm_optionmenu = customtkinter.CTkOptionMenu(self.footer_frame, values=["PSO", "Halton"], width=50)
|
172
|
+
self.algorithm_optionmenu.grid(row=0, column=6, padx=header_padding_x, pady=header_padding_y)
|
173
|
+
self.algorithm_optionmenu.set("PSO")
|
174
|
+
|
175
|
+
play_image = customtkinter.CTkImage(Image.open(os.path.join("./images", "play.png")), size=(20, 20))
|
176
|
+
self.run_button = customtkinter.CTkButton(self.footer_frame, text=None, width=30, image=play_image, command=self.run)
|
177
|
+
ctt(self.run_button, delay=0.1, alpha=0.95, message="Start Calibration")
|
178
|
+
self.run_button.grid(row=0, column=7, padx=(20, 5), pady=header_padding_y)
|
179
|
+
|
180
|
+
test_image = customtkinter.CTkImage(Image.open(os.path.join("./images", "test.png")), size=(20, 20))
|
181
|
+
self.test_button = customtkinter.CTkButton(self.footer_frame, text=None, width=30, image=test_image, command=self.run)
|
182
|
+
ctt(self.test_button, delay=0.1, alpha=0.95, message="Start Testing")
|
183
|
+
self.test_button.grid(row=0, column=8, padx=(5, 5), pady=header_padding_y)
|
184
|
+
|
185
|
+
stop_image = customtkinter.CTkImage(Image.open(os.path.join("./images", "stop.png")), size=(20, 20))
|
186
|
+
self.stop_button = customtkinter.CTkButton(self.footer_frame, text=None, width=30, image=stop_image, command=self.stop)
|
187
|
+
ctt(self.stop_button, delay=0.1, alpha=0.95, message="Stop")
|
188
|
+
self.stop_button.grid(row=0, column=9, padx=(5, 20), pady=header_padding_y)
|
189
|
+
|
190
|
+
download_image = customtkinter.CTkImage(Image.open(os.path.join("./images", "down.png")), size=(20, 20))
|
191
|
+
self.download_button = customtkinter.CTkButton(self.footer_frame, text=None, width=30, image=download_image, command=self.stop)
|
192
|
+
ctt(self.download_button, delay=0.1, alpha=0.95, message="Download Results")
|
193
|
+
self.download_button.grid(row=0, column=10, padx=(5, 20), pady=header_padding_y)
|
194
|
+
|
195
|
+
self.after(1000, self.running_loop)
|
196
|
+
|
197
|
+
def update_graph(self, value):
|
198
|
+
self.vis_sidebar.refresh()
|
199
|
+
GraphGenerator.generate_graphs(self)
|
200
|
+
|
201
|
+
'''def _resize_image(self, event):
|
202
|
+
self.graph_label.update_idletasks()
|
203
|
+
new_width = self.graph_label.winfo_width()
|
204
|
+
new_height = self.graph_label.winfo_height()
|
205
|
+
|
206
|
+
alt_width = new_height * 1.77778
|
207
|
+
alt_height = new_width / 1.77778
|
208
|
+
|
209
|
+
if (new_width < new_height):
|
210
|
+
new_height = alt_height
|
211
|
+
else:
|
212
|
+
new_width = alt_width
|
213
|
+
|
214
|
+
self.image_width = new_width
|
215
|
+
self.image_height = new_height
|
216
|
+
|
217
|
+
self.graph_image = customtkinter.CTkImage(self.graph_image_obj, size=(new_width, new_height))
|
218
|
+
self.graph_label.configure(image=self.graph_image)
|
219
|
+
self.graph_label.update_idletasks()
|
220
|
+
|
221
|
+
|
222
|
+
def update_graph(self, value):
|
223
|
+
selected_graph = self.graph_selector_value.get()
|
224
|
+
info = self.option_manager.get_project_data()
|
225
|
+
folder = os.path.join(info['path'], info['name'])
|
226
|
+
|
227
|
+
if not os.path.exists(folder):
|
228
|
+
os.makedirs(folder)
|
229
|
+
|
230
|
+
if (selected_graph == "Best Cost Stacked"):
|
231
|
+
self.selected_graph_name = "best_cost_stacked"
|
232
|
+
elif (selected_graph == "Best Cost by Round"):
|
233
|
+
self.selected_graph_name = "best_cost_by_round"
|
234
|
+
elif (selected_graph == "Iteration Table"):
|
235
|
+
self.selected_graph_name = "table"
|
236
|
+
elif (selected_graph == "Calibrated Parameters"):
|
237
|
+
self.selected_graph_name = "calibrated_params_by_round"
|
238
|
+
|
239
|
+
image_path = os.path.join(folder, self.selected_graph_name + ".png")
|
240
|
+
if not os.path.exists(image_path):
|
241
|
+
image_path = os.path.join("./images", "up.png")
|
242
|
+
self.graph_image_obj = Image.open(image_path)
|
243
|
+
self.graph_image = customtkinter.CTkImage(self.graph_image_obj, size=(self.image_width * self.image_scale, self.image_height * self.image_scale))
|
244
|
+
self.graph_label.configure(image=self.graph_image)'''
|
245
|
+
|
246
|
+
def save_project(self):
|
247
|
+
metrics = self.option_manager.get_metrics()
|
248
|
+
|
249
|
+
# Add the calibration_progress dataframe to the json
|
250
|
+
if (self.progress_data is not None):
|
251
|
+
metrics["calibration_progress"] = self.progress_data.to_json()
|
252
|
+
# Add the calibration_data to the json
|
253
|
+
if (self.calibration_data is not None):
|
254
|
+
metrics["calibration_data"] = self.calibration_data
|
255
|
+
|
256
|
+
filename = asksaveasfilename(filetypes=[("JSON", "*.json")], initialfile="config", defaultextension="json", title="Save Project")
|
257
|
+
|
258
|
+
try:
|
259
|
+
|
260
|
+
# Convert metrics to json and save to file with proper spacing
|
261
|
+
with open(filename, "w") as f:
|
262
|
+
f.write(json.dumps(metrics, indent=4))
|
263
|
+
|
264
|
+
self.save_button.configure(text="Saved!")
|
265
|
+
self.after(3000, lambda: self.save_button.configure(text="Save"))
|
266
|
+
except Exception as e:
|
267
|
+
self.save_button.configure(text="Error!")
|
268
|
+
print(e)
|
269
|
+
self.after(3000, lambda: self.save_button.configure(text="Save"))
|
270
|
+
|
271
|
+
def new_window(self):
|
272
|
+
# Shell out and run ./main.py
|
273
|
+
subprocess.Popen(["python3", "../mgpsogui.py"])
|
274
|
+
|
275
|
+
def load_project(self):
|
276
|
+
|
277
|
+
filename = askopenfilename(filetypes=[("JSON", "*.json")], title="Open Project", multiple=False)
|
278
|
+
print(filename)
|
279
|
+
|
280
|
+
try:
|
281
|
+
|
282
|
+
# Load config.json and convert to metrics
|
283
|
+
with open(filename, "r") as f:
|
284
|
+
metrics = json.loads(f.read())
|
285
|
+
|
286
|
+
self.option_manager.set_path(filename)
|
287
|
+
|
288
|
+
if "arguments" in metrics:
|
289
|
+
metrics["arguments"]["calibration_parameters"] = metrics["calibration_parameters"]
|
290
|
+
|
291
|
+
if "service_parameters" in metrics:
|
292
|
+
self.option_manager.set_service_parameters(metrics["service_parameters"])
|
293
|
+
self.tabview.configure(state="enabled")
|
294
|
+
|
295
|
+
if "calibration_progress" in metrics:
|
296
|
+
self.progress_data = pd.read_json(metrics["calibration_progress"])
|
297
|
+
self.calibration_data = metrics["calibration_data"]
|
298
|
+
print(self.progress_data)
|
299
|
+
|
300
|
+
if "calibration_data" in metrics:
|
301
|
+
self.calibration_data = metrics["calibration_data"]
|
302
|
+
print(self.calibration_data)
|
303
|
+
|
304
|
+
print(metrics)
|
305
|
+
|
306
|
+
self.option_manager.clear()
|
307
|
+
self.option_manager.add_arguments(metrics["arguments"])
|
308
|
+
self.option_manager.add_steps(metrics["steps"])
|
309
|
+
|
310
|
+
self.steps_frame.clear()
|
311
|
+
self.steps_frame.render()
|
312
|
+
|
313
|
+
self.static_param_frame.clear()
|
314
|
+
self.static_param_frame.render()
|
315
|
+
|
316
|
+
self.calib_param_frame.clear()
|
317
|
+
self.calib_param_frame.render()
|
318
|
+
|
319
|
+
info = self.option_manager.get_project_data()
|
320
|
+
folder = os.path.join(info['path'], info['name'])
|
321
|
+
self.HRU_data = pd.read_csv(os.path.join(folder, "results", "HRU_1.csv"), skiprows=3)
|
322
|
+
print(self.HRU_data)
|
323
|
+
|
324
|
+
self.load_button.configure(text="Loaded!")
|
325
|
+
self.after(3000, lambda: self.load_button.configure(text="Load"))
|
326
|
+
|
327
|
+
except Exception as e:
|
328
|
+
print(e)
|
329
|
+
self.load_button.configure(text="Error!")
|
330
|
+
self.after(3000, lambda: self.load_button.configure(text="Load"))
|
331
|
+
|
332
|
+
def change_appearance_mode_event(self, new_appearance_mode: str):
|
333
|
+
customtkinter.set_appearance_mode(new_appearance_mode)
|
334
|
+
|
335
|
+
def change_scaling_event(self, new_scaling: str):
|
336
|
+
new_scaling_float = int(new_scaling.replace("%", "")) / 100
|
337
|
+
customtkinter.set_widget_scaling(new_scaling_float)
|
338
|
+
|
339
|
+
def change_scaling_event(self, new_scaling: str):
|
340
|
+
new_scaling_float = int(new_scaling.replace("%", "")) / 100
|
341
|
+
customtkinter.set_widget_scaling(new_scaling_float)
|
342
|
+
|
343
|
+
def make_request(self):
|
344
|
+
service_url = self.service_url.get()
|
345
|
+
try:
|
346
|
+
response = requests.get(service_url)
|
347
|
+
|
348
|
+
response_json = json.loads(response.text)
|
349
|
+
status = response.status_code
|
350
|
+
|
351
|
+
self.option_manager.set_service_parameters(response_json)
|
352
|
+
|
353
|
+
self.service_status.delete('0.0', tk.END)
|
354
|
+
self.service_status.insert(text=str(status), index='0.0')
|
355
|
+
self.service_name.delete('0.0', tk.END)
|
356
|
+
self.service_name.insert(text=str(response_json["metainfo"]["name"]), index='0.0')
|
357
|
+
self.service_description.delete('0.0', tk.END)
|
358
|
+
self.service_description.insert(text=str(response_json["metainfo"]["description"]), index='0.0')
|
359
|
+
self.service_details.delete('0.0', tk.END)
|
360
|
+
self.service_details.insert(text=json.dumps(response_json, indent=4), index='0.0')
|
361
|
+
|
362
|
+
self.refresh_button.configure(fg_color="green")
|
363
|
+
except Exception as e:
|
364
|
+
self.refresh_button.configure(fg_color="red")
|
365
|
+
|
366
|
+
|
367
|
+
def load(self):
|
368
|
+
# Make HTTP request to service_url and save the result to bounds.json
|
369
|
+
|
370
|
+
self.default_button_color = self.refresh_button.cget("fg_color")
|
371
|
+
|
372
|
+
self.refresh_button.configure(fg_color="gray")
|
373
|
+
|
374
|
+
self.after(10, self.make_request)
|
375
|
+
self.after(3000, lambda: self.refresh_button.configure(fg_color=self.default_button_color))
|
376
|
+
|
377
|
+
def run(self):
|
378
|
+
metrics = self.option_manager.get_metrics()
|
379
|
+
self.running_config = metrics
|
380
|
+
|
381
|
+
self.progress_data = None
|
382
|
+
self.calibration_data = None
|
383
|
+
|
384
|
+
#self.progress_bar.configure(mode="indeterminnate")
|
385
|
+
#self.progress_bar.start()
|
386
|
+
self.footer_progress_bar.configure(mode="indeterminnate")
|
387
|
+
self.footer_progress_bar.start()
|
388
|
+
|
389
|
+
self.data_x = [0]
|
390
|
+
self.data_y = [0]
|
391
|
+
|
392
|
+
self.progress_message_middle.configure(text="Calibration starting...")
|
393
|
+
self.footer_progress_label.configure(text="Starting...")
|
394
|
+
|
395
|
+
self.textbox.insert("0.0", "Starting calibration...\n\n")
|
396
|
+
self.textbox.insert("0.0", "Calibration Parameters:\n")
|
397
|
+
self.textbox.insert("0.0", json.dumps(metrics, indent=4) + "\n\n")
|
398
|
+
try:
|
399
|
+
info = self.option_manager.get_project_data()
|
400
|
+
folder = os.path.join(info['path'], info['name'])
|
401
|
+
|
402
|
+
if not os.path.exists(folder):
|
403
|
+
os.makedirs(folder)
|
404
|
+
|
405
|
+
if (os.path.exists(os.path.join(folder, 'output.txt'))):
|
406
|
+
os.remove(os.path.join(folder, 'output.txt'))
|
407
|
+
|
408
|
+
if (os.path.exists(os.path.join(folder, 'error.txt'))):
|
409
|
+
os.remove(os.path.join(folder, 'error.txt'))
|
410
|
+
|
411
|
+
self.train_process = Process(target=PSORunner.run_process, args=(stdout_queue, stderr_queue, results_queue, cosu_queue, metrics, folder))
|
412
|
+
self.train_process.daemon = True
|
413
|
+
self.train_process.start()
|
414
|
+
self.after(1000, self.watch_loop)
|
415
|
+
self.string_cache = ""
|
416
|
+
self.data_cache = ""
|
417
|
+
|
418
|
+
except Exception as e:
|
419
|
+
self.textbox.insert("0.0", "An exception occurred!\n Exception: " + str(e) + "\n\n")
|
420
|
+
self.textbox.insert("0.0", "Stack trace:\n")
|
421
|
+
self.textbox.insert("0.0", traceback.format_exc())
|
422
|
+
self.textbox.insert("0.0", "\n\n")
|
423
|
+
self.textbox.insert("0.0", "Calibration failed!")
|
424
|
+
self.progress_message_left.configure(text="")
|
425
|
+
self.progress_message_middle.configure(text="Calibration failed! See error log below.")
|
426
|
+
self.progress_message_right.configure(text="")
|
427
|
+
self.footer_progress_label.configure(text="Failed")
|
428
|
+
#self.progress_bar.stop()
|
429
|
+
self.footer_progress_bar.stop()
|
430
|
+
#self.progress_bar.configure(mode="determinate")
|
431
|
+
self.footer_progress_bar.configure(mode="determinate")
|
432
|
+
#self.progress_bar.set(0)
|
433
|
+
self.footer_progress_bar.set(0)
|
434
|
+
|
435
|
+
def stop(self):
|
436
|
+
print("Stopping...")
|
437
|
+
self.train_process.terminate()
|
438
|
+
|
439
|
+
info = self.option_manager.get_project_data()
|
440
|
+
folder = os.path.join(info['path'], info['name'])
|
441
|
+
|
442
|
+
if not os.path.exists(folder):
|
443
|
+
os.makedirs(folder)
|
444
|
+
|
445
|
+
# Stop the process
|
446
|
+
if (os.path.exists(os.path.join(folder, 'output.txt'))):
|
447
|
+
os.remove(os.path.join(folder, 'output.txt'))
|
448
|
+
|
449
|
+
if (os.path.exists(os.path.join(folder, 'error.txt'))):
|
450
|
+
os.remove(os.path.join(folder, 'error.txt'))
|
451
|
+
|
452
|
+
self.textbox.insert("0.0", "\nCalibration terminated!\n")
|
453
|
+
#self.progress_bar.stop()
|
454
|
+
self.footer_progress_bar.stop()
|
455
|
+
#self.progress_bar.configure(mode="determinate")
|
456
|
+
self.footer_progress_bar.configure(mode="determinate")
|
457
|
+
#self.progress_bar.set(0)
|
458
|
+
self.footer_progress_bar.set(0)
|
459
|
+
self.progress_message_left.configure(text="")
|
460
|
+
self.progress_message_middle.configure(text="Calibration stopped!")
|
461
|
+
self.footer_progress_label.configure(text="Stopped")
|
462
|
+
self.progress_message_right.configure(text="")
|
463
|
+
|
464
|
+
def running_loop(self):
|
465
|
+
try:
|
466
|
+
active_tab = self.tabview.get()
|
467
|
+
if (active_tab == "Results"):
|
468
|
+
GraphGenerator.generate_graphs(self)
|
469
|
+
finally:
|
470
|
+
self.after(1000, self.running_loop)
|
471
|
+
|
472
|
+
def watch_loop(self):
|
473
|
+
# Check if file exists:
|
474
|
+
info = self.option_manager.get_project_data()
|
475
|
+
folder = os.path.join(info['path'], info['name'])
|
476
|
+
|
477
|
+
if not os.path.exists(folder):
|
478
|
+
os.makedirs(folder)
|
479
|
+
|
480
|
+
while True:
|
481
|
+
try:
|
482
|
+
stdout_line = stdout_queue.get_nowait()
|
483
|
+
|
484
|
+
print("# " + stdout_line, flush=True)
|
485
|
+
with open(os.path.join(folder, 'output.txt'), 'a') as f:
|
486
|
+
f.write(stdout_line)
|
487
|
+
|
488
|
+
except Empty:
|
489
|
+
break
|
490
|
+
|
491
|
+
while True:
|
492
|
+
try:
|
493
|
+
stderr_line = stderr_queue.get_nowait()
|
494
|
+
|
495
|
+
print("? " + stderr_line, flush=True)
|
496
|
+
with open(os.path.join(folder, 'error.txt'), 'a') as f:
|
497
|
+
f.write(stderr_line)
|
498
|
+
|
499
|
+
except Empty:
|
500
|
+
break
|
501
|
+
|
502
|
+
while True:
|
503
|
+
try:
|
504
|
+
cosu_line = cosu_queue.get_nowait()
|
505
|
+
|
506
|
+
print("COSU " + cosu_line, flush=True)
|
507
|
+
except Empty:
|
508
|
+
break
|
509
|
+
|
510
|
+
if (os.path.exists(os.path.join(folder, 'output.txt'))):
|
511
|
+
with open(os.path.join(folder, 'output.txt'), 'r') as f:
|
512
|
+
lines = f.readlines()
|
513
|
+
lines_string = "".join(lines)
|
514
|
+
|
515
|
+
new_characters = lines_string.replace(self.string_cache, "")
|
516
|
+
# Update the textbox with characters not in self.string_cache
|
517
|
+
self.textbox.insert('0.0', new_characters)
|
518
|
+
self.string_cache = lines_string
|
519
|
+
print(new_characters, end="")
|
520
|
+
|
521
|
+
try:
|
522
|
+
with open(os.path.join(folder, "output.txt"), "r") as f:
|
523
|
+
text = f.read()
|
524
|
+
|
525
|
+
calibrated_params_pattern = r"calibrated params: ({.*?})"
|
526
|
+
best_particle_values_pattern = r"best particle values: (\[.*?\])"
|
527
|
+
progress_pattern = r"Progress - best_round_cost:(.*?), rel_round_tol:(.*?), rtol:(.*?)\n"
|
528
|
+
|
529
|
+
calibrated_params = re.findall(calibrated_params_pattern, text)
|
530
|
+
best_particle_values = re.findall(best_particle_values_pattern, text)
|
531
|
+
progress_values = re.findall(progress_pattern, text)
|
532
|
+
|
533
|
+
for index, pp in enumerate(best_particle_values):
|
534
|
+
pp = pp.strip()
|
535
|
+
pp = pp.replace('[ ', '[')
|
536
|
+
pp = pp.replace(' ', ',')
|
537
|
+
pp = pp.replace(' ', ',')
|
538
|
+
best_particle_values[index] = pp
|
539
|
+
|
540
|
+
calibrated_params = [ast.literal_eval(i) for i in calibrated_params]
|
541
|
+
best_particle_values = [ast.literal_eval(i) for i in best_particle_values]
|
542
|
+
progress_values = [tuple(map(float, i)) for i in progress_values]
|
543
|
+
|
544
|
+
#print("Current params: " + str(calibrated_params), flush=True)
|
545
|
+
|
546
|
+
self.calibration_data = calibrated_params
|
547
|
+
|
548
|
+
#GraphGenerator.calibrated_params_by_round(self.running_config['steps'], calibrated_params, self.option_manager)
|
549
|
+
#self.update_graph("")
|
550
|
+
except Exception as e:
|
551
|
+
# Print stack trace
|
552
|
+
traceback.print_exc()
|
553
|
+
|
554
|
+
print(e)
|
555
|
+
|
556
|
+
if (os.path.exists(os.path.join(folder, 'error.txt'))):
|
557
|
+
with open(os.path.join(folder, 'error.txt'), 'r') as f:
|
558
|
+
lines = f.readlines()
|
559
|
+
lines_string = "".join(lines)
|
560
|
+
self.data_cache = lines_string
|
561
|
+
|
562
|
+
pattern = r'(\d+)%\|.*\|(\d+)/(\d+)(?:,\sbest_cost=(\d+\.\d+))?' # The magic of AI
|
563
|
+
matches = re.findall(pattern, self.data_cache)
|
564
|
+
filtered_matches = [match for match in matches if match[3] != '']
|
565
|
+
matches = filtered_matches
|
566
|
+
|
567
|
+
if len(matches) > 0:
|
568
|
+
df = pd.DataFrame(matches, columns=['percent', 'completed_rounds', 'total_rounds', 'best_cost'], dtype=float)
|
569
|
+
df = df[df['best_cost'] != '']
|
570
|
+
df = df.dropna()
|
571
|
+
df = df.drop_duplicates()
|
572
|
+
df['round_step'] = (df['completed_rounds'].diff() < 0).cumsum()
|
573
|
+
df = df.drop_duplicates(subset=['completed_rounds', 'round_step'])
|
574
|
+
self.progress_data = df
|
575
|
+
|
576
|
+
match = matches[-1]
|
577
|
+
percent = int(match[0])
|
578
|
+
completed_rounds = int(match[1])
|
579
|
+
total_rounds = int(match[2])
|
580
|
+
best_cost = float(match[3]) if match[3] else None
|
581
|
+
|
582
|
+
if (percent > 0):
|
583
|
+
#self.progress_bar.stop()
|
584
|
+
self.footer_progress_bar.stop()
|
585
|
+
#self.progress_bar.configure(mode="determinate")
|
586
|
+
self.footer_progress_bar.configure(mode="determinate")
|
587
|
+
#self.progress_bar.set(percent/100)
|
588
|
+
self.footer_progress_bar.set(percent/100)
|
589
|
+
self.progress_message_left.configure(text="Percent Complete: " + str(percent) + "%")
|
590
|
+
self.progress_message_middle.configure(text=str(completed_rounds) + "/" + str(total_rounds))
|
591
|
+
self.footer_progress_label.configure(text=str(completed_rounds) + "/" + str(total_rounds))
|
592
|
+
self.progress_message_right.configure(text="Best Cost: " + str(best_cost))
|
593
|
+
else:
|
594
|
+
#self.progress_bar.configure(mode="indeterminate")
|
595
|
+
self.footer_progress_bar.configure(mode="indeterminate")
|
596
|
+
#self.progress_bar.start()
|
597
|
+
self.footer_progress_bar.start()
|
598
|
+
self.progress_message_left.configure(text="")
|
599
|
+
self.progress_message_middle.configure(text="Starting new round...")
|
600
|
+
self.footer_progress_label.configure(text="Next round...")
|
601
|
+
self.progress_message_right.configure(text="")
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
if self.train_process.is_alive():
|
606
|
+
self.after(1000, self.watch_loop)
|
607
|
+
else:
|
608
|
+
#self.progress_bar.stop()
|
609
|
+
self.footer_progress_bar.stop()
|
610
|
+
#self.progress_bar.configure(mode="indeterminate")
|
611
|
+
self.footer_progress_bar.configure(mode="indeterminate")
|
612
|
+
#self.progress_bar.start()
|
613
|
+
self.footer_progress_bar.start()
|
614
|
+
self.progress_message_left.configure(text="")
|
615
|
+
self.progress_message_middle.configure(text="Calibration finished!")
|
616
|
+
self.progress_message_right.configure(text="")
|
617
|
+
self.textbox.insert("0.0", "\nCalibration finished!\n")
|
618
|
+
|
619
|
+
|
620
|
+
|
565
621
|
|
566
622
|
def start():
|
567
|
-
|
568
|
-
|
623
|
+
app = App()
|
624
|
+
app.mainloop()
|
569
625
|
|
570
626
|
if __name__ == "__main__":
|
571
|
-
|
572
|
-
|
627
|
+
app = App()
|
628
|
+
app.mainloop()
|