mg-pso-gui 0.0.140__py3-none-any.whl → 0.0.141__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mg-pso-gui
3
- Version: 0.0.140
3
+ Version: 0.0.141
4
4
  Summary: GUI for MG-PSO
5
5
  Author: Robert Cordingly
6
6
  Author-email: <rcording@uw.ed>
@@ -1,11 +1,13 @@
1
1
  mgpsogui/__init__.py,sha256=q7AfBjeJABnFtbsZnsObpUwaXKPDVYtz46G6MKXLF74,42
2
2
  mgpsogui/mgpsogui.py,sha256=NIZmyNcbwC8EgSwf1ubdMUSJscrIEgoD4jLYziqHQ-k,148
3
3
  mgpsogui/start.yaml,sha256=ZjCVLb-MLqAxrGRm9kA7_SDpa-45EuKIELNQ2QqCAiU,4713
4
- mgpsogui/gui/HomePage.py,sha256=mutSXbZsq9BVjFo37k9zR4sOgxgjG1ZapWqfIeg4nCQ,25819
4
+ mgpsogui/gui/HomePage.py,sha256=HpBRrCvvk6kD8HkQLuHsbpm2HhDHY1XpK_QOf48Jk3k,13235
5
5
  mgpsogui/gui/OptionManager.py,sha256=bFN2jWJbx1Din3waOFLmbWGt0BXD_KthGJ8Mgue_FEE,11712
6
6
  mgpsogui/gui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  mgpsogui/gui/PlatformTab/PlatformTab.py,sha256=N2HSRqT45NH4PPeOwXdLhOASMDjh-1OwUa2WmV47T5M,10465
8
8
  mgpsogui/gui/PlatformTab/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ mgpsogui/gui/RunTab/RunTab.py,sha256=IxFDyL_saeyS1N4xu11Nf_3yzmeoGmxzWQGiUgQQ6zI,11178
10
+ mgpsogui/gui/RunTab/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
11
  mgpsogui/gui/SetupTab/BoundsEditorWindow.py,sha256=tDCap4qFQw3MRQo0d81W3vqmQlWQGNZYPh0TyhCwOvs,2848
10
12
  mgpsogui/gui/SetupTab/BoundsList.py,sha256=rWgEHomH5K5UqmG_j04yH7z6NjE-VDA6DBTaV_uYGzk,12288
11
13
  mgpsogui/gui/SetupTab/CalibrationParametersView.py,sha256=ppVBHG3nphku9-P6Z8az-HTpgk8vHxnj-A5m80BZTgA,2784
@@ -25,8 +27,8 @@ mgpsogui/util/PSORunner.py,sha256=7iUYRUXgpZ0l0rqoyHQYY1Yg9q0gl9TE0jNaHZMv04c,29
25
27
  mgpsogui/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
28
  mgpsogui/util/CTkToolTip/__init__.py,sha256=G1jxV55hGtGgwyC1sR-uUUdasDdh0XZgcI-aILgGYA0,225
27
29
  mgpsogui/util/CTkToolTip/ctk_tooltip.py,sha256=SZMovpQIGvdpDRbqCKl9SHs92DrFCO2MOYL2ifolvOE,6329
28
- mg_pso_gui-0.0.140.dist-info/METADATA,sha256=3kQLwDeVJXSz-yF9ekkvkaIAAgp8cvIMVmbQmLZ4T8I,9459
29
- mg_pso_gui-0.0.140.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
30
- mg_pso_gui-0.0.140.dist-info/entry_points.txt,sha256=jg82VOFjR1XDGrchs1wJSCqKYE4Ozv12aBcCSp--koA,117
31
- mg_pso_gui-0.0.140.dist-info/top_level.txt,sha256=y7JuS9xJN5YdxUsQ3PSVjN8MzQAnR146bP3ZN3PYWdE,9
32
- mg_pso_gui-0.0.140.dist-info/RECORD,,
30
+ mg_pso_gui-0.0.141.dist-info/METADATA,sha256=jxPCyoCXnTLhkIaY2g4w0kw3jTH9moiHM7Oj9UFKhKg,9459
31
+ mg_pso_gui-0.0.141.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
32
+ mg_pso_gui-0.0.141.dist-info/entry_points.txt,sha256=jg82VOFjR1XDGrchs1wJSCqKYE4Ozv12aBcCSp--koA,117
33
+ mg_pso_gui-0.0.141.dist-info/top_level.txt,sha256=y7JuS9xJN5YdxUsQ3PSVjN8MzQAnR146bP3ZN3PYWdE,9
34
+ mg_pso_gui-0.0.141.dist-info/RECORD,,
mgpsogui/gui/HomePage.py CHANGED
@@ -38,6 +38,7 @@ from . import OptionManager as om
38
38
 
39
39
  from .SetupTab import SetupTab as st
40
40
  from .PlatformTab import PlatformTab as pt
41
+ from .RunTab import RunTab as rt
41
42
 
42
43
  from ..util.CTkToolTip import CTkToolTip as ctt
43
44
 
@@ -112,70 +113,7 @@ class App(customtkinter.CTk):
112
113
 
113
114
  pt.create_tab(self, self.tabview.tab(tab1))
114
115
  st.create_tab(self, self.tabview.tab(tab2))
115
-
116
- """self.tabview.tab(tab2).grid_columnconfigure(0, weight=8)
117
- self.tabview.tab(tab2).grid_columnconfigure(1, weight=1)
118
- self.tabview.tab(tab2).grid_rowconfigure(0, weight=1)
119
- self.tabview.tab(tab2).grid_rowconfigure(1, weight=1)
120
-
121
- self.steps_frame = sv.StepView(self.tabview.tab(tab2), label_text="Group Editor", option_manager=self.option_manager)
122
- self.steps_frame.grid(row=0, rowspan=2, column=0, padx=(10, 10), pady=(10, 10), sticky="nsew")
123
- self.steps_frame.grid_columnconfigure(0, weight=1)
124
- self.steps_frame.grid_rowconfigure(0, weight=1)
125
-
126
- self.static_param_frame = spv.StaticParameterView(self.tabview.tab(tab2), label_text="Static Parameters", option_manager=self.option_manager)
127
- self.static_param_frame.grid(row=0, column=1, padx=(10, 10), pady=(10, 10), sticky="nsew")
128
- self.static_param_frame.grid_columnconfigure(0, weight=1)
129
- self.static_param_frame.grid_rowconfigure(0, weight=1)
130
-
131
- self.calib_param_frame = cpv.CalibrationParametersView(self.tabview.tab(tab2), label_text="Calibration Parameters", option_manager=self.option_manager)
132
- self.calib_param_frame.grid(row=1, column=1, padx=(10, 10), pady=(10, 10), sticky="nsew")
133
- self.calib_param_frame.grid_columnconfigure(0, weight=1)
134
- self.calib_param_frame.grid_rowconfigure(0, weight=1)
135
- """
136
-
137
- # URL
138
-
139
- self.tabview.tab(tab3).grid_columnconfigure(0, weight=1)
140
- self.tabview.tab(tab3).grid_rowconfigure(0, weight=1)
141
- self.tabview.tab(tab3).grid_rowconfigure(1, weight=1)
142
- self.tabview.tab(tab3).grid_rowconfigure(2, weight=200)
143
- self.url = customtkinter.CTkEntry(self.tabview.tab(tab3), textvariable=self.option_manager.get_arguments()['url'])
144
- self.url.grid(row=0, column=0, columnspan=1, padx=(20, 20), pady=(20, 20), sticky="nsew")
145
-
146
- self.run_button = customtkinter.CTkButton(self.tabview.tab(tab3), text="Run", command=self.run)
147
- self.run_button.grid(row=0, column=1, padx=(20, 20), pady=(20, 20), sticky="nsew")
148
- ctt(self.run_button, delay=0.5, message="Start calibration...")
149
-
150
-
151
- self.stop_button = customtkinter.CTkButton(self.tabview.tab(tab3), text="Stop", command=self.stop)
152
- self.stop_button.grid(row=0, column=2, padx=(20, 20), pady=(20, 20), sticky="nsew")
153
- ctt(self.stop_button, delay=0.5, message="Stop calibration...")
154
-
155
- self.progress_container = customtkinter.CTkFrame(self.tabview.tab(tab3))
156
- self.progress_container.grid_columnconfigure(0, weight=1)
157
- self.progress_container.grid_columnconfigure(1, weight=1)
158
- self.progress_container.grid_columnconfigure(2, weight=1)
159
- self.progress_container.grid(row=1, column=0, columnspan=3, padx=(20, 20), pady=(20, 20), sticky="nsew")
160
-
161
- # Add progress bar to progress container
162
- self.progress_message_left = customtkinter.CTkLabel(self.progress_container, text="")
163
- self.progress_message_left.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="w")
164
-
165
- self.progress_message_middle = customtkinter.CTkLabel(self.progress_container, text="Calibration not running...")
166
- self.progress_message_middle.grid(row=0, column=1, padx=(10, 10), pady=(10, 10), sticky="ew")
167
-
168
- self.progress_message_right = customtkinter.CTkLabel(self.progress_container, text="")
169
- self.progress_message_right.grid(row=0, column=2, padx=(10, 10), pady=(10, 10), sticky="e")
170
-
171
- self.progress_bar = customtkinter.CTkProgressBar(self.progress_container)
172
- self.progress_bar.grid(row=1, column=0, columnspan=3, padx=(10, 10), pady=(10, 10), sticky="ew")
173
- self.progress_bar.set(0)
174
- ctt(self.progress_bar, delay=0.5, message="Current calibration progress")
175
-
176
- self.textbox = customtkinter.CTkTextbox(self.tabview.tab(tab3))
177
- self.textbox.grid(row=2, column=0, columnspan=3, padx=(20, 20), pady=(20, 20), sticky="nsew")
178
- self.textbox.insert("0.0", "Welcome to the CSIP PSO Calibration Tool!\n\nUse the Calibration tab to define steps and calibration parameters. Use this tab to run and observe calibration progress. Once finished, use the Visualization tab to generate figures and graphs.")
116
+ rt.create_tab(self, self.tabview.tab(tab3))
179
117
 
180
118
  self.tabview.tab(tab4).grid_columnconfigure(1, weight=10)
181
119
  self.tabview.tab(tab4).grid_columnconfigure(0, weight=1)
@@ -223,47 +161,6 @@ class App(customtkinter.CTk):
223
161
  def callback_test(self, *args):
224
162
  print("callback_test called")
225
163
 
226
-
227
- def run(self):
228
- metrics = self.option_manager.get_metrics()
229
- self.running_config = metrics
230
-
231
- self.progress_bar.configure(mode="indeterminnate")
232
- self.progress_bar.start()
233
-
234
- self.data_x = [0]
235
- self.data_y = [0]
236
-
237
- self.progress_message_middle.configure(text="Calibration starting...")
238
-
239
- self.textbox.insert("0.0", "Starting calibration...\n\n")
240
- self.textbox.insert("0.0", "Calibration Parameters:\n")
241
- self.textbox.insert("0.0", json.dumps(metrics, indent=4) + "\n\n")
242
- try:
243
- info = self.option_manager.get_project_data()
244
- folder = os.path.join(info['path'], info['name'])
245
-
246
-
247
- self.train_process = Process(target=PSORunner.run_process, args=(metrics, folder))
248
- self.train_process.daemon = True
249
- self.train_process.start()
250
- self.after(1000, self.watch_loop)
251
- self.string_cache = ""
252
- self.data_cache = ""
253
-
254
- except Exception as e:
255
- self.textbox.insert("0.0", "An exception occurred!\n Exception: " + str(e) + "\n\n")
256
- self.textbox.insert("0.0", "Stack trace:\n")
257
- self.textbox.insert("0.0", traceback.format_exc())
258
- self.textbox.insert("0.0", "\n\n")
259
- self.textbox.insert("0.0", "Calibration failed!")
260
- self.progress_message_left.configure(text="")
261
- self.progress_message_middle.configure(text="Calibration failed! See error log below.")
262
- self.progress_message_right.configure(text="")
263
- self.progress_bar.stop()
264
- self.progress_bar.configure(mode="determinate")
265
- self.progress_bar.set(0)
266
-
267
164
  def update_graph(self, value):
268
165
  selected_graph = self.graph_selector_value.get()
269
166
  info = self.option_manager.get_project_data()
@@ -368,117 +265,6 @@ class App(customtkinter.CTk):
368
265
  print(e)
369
266
  self.load_button.configure(text="Error!")
370
267
  self.after(3000, lambda: self.load_button.configure(text="Load"))
371
-
372
-
373
- def watch_loop(self):
374
- # Check if file exists:
375
-
376
- info = self.option_manager.get_project_data()
377
- folder = os.path.join(info['path'], info['name'])
378
-
379
- if not os.path.exists(folder):
380
- os.makedirs(folder)
381
-
382
- if (os.path.exists(os.path.join(folder, 'output.txt'))):
383
- with open(os.path.join(folder, 'output.txt'), 'r') as f:
384
- lines = f.readlines()
385
- lines_string = "".join(lines)
386
-
387
- new_characters = lines_string.replace(self.string_cache, "")
388
- # Update the textbox with characters not in self.string_cache
389
- self.textbox.insert('0.0', new_characters)
390
- self.string_cache = lines_string
391
- print(new_characters, end="")
392
-
393
- try:
394
- with open(os.path.join(folder, "output.txt"), "r") as f:
395
- text = f.read()
396
-
397
- calibrated_params_pattern = r"calibrated params: ({.*?})"
398
- best_particle_values_pattern = r"best particle values: (\[.*?\])"
399
- progress_pattern = r"Progress - best_round_cost:(.*?), rel_round_tol:(.*?), rtol:(.*?)\n"
400
-
401
- calibrated_params = re.findall(calibrated_params_pattern, text)
402
- best_particle_values = re.findall(best_particle_values_pattern, text)
403
- progress_values = re.findall(progress_pattern, text)
404
-
405
- for index, pp in enumerate(best_particle_values):
406
- pp = pp.strip()
407
- pp = pp.replace('[ ', '[')
408
- pp = pp.replace(' ', ',')
409
- pp = pp.replace(' ', ',')
410
- best_particle_values[index] = pp
411
-
412
- calibrated_params = [ast.literal_eval(i) for i in calibrated_params]
413
- best_particle_values = [ast.literal_eval(i) for i in best_particle_values]
414
- progress_values = [tuple(map(float, i)) for i in progress_values]
415
-
416
- print(calibrated_params)
417
-
418
- GraphGenerator.calibrated_params_by_round(self.running_config['steps'], calibrated_params, self.option_manager)
419
- self.update_graph("")
420
- except Exception as e:
421
- # Print stack trace
422
- traceback.print_exc()
423
-
424
- print(e)
425
-
426
- if (os.path.exists(os.path.join(folder, 'error.txt'))):
427
- with open(os.path.join(folder, 'error.txt'), 'r') as f:
428
- lines = f.readlines()
429
- lines_string = "".join(lines)
430
- self.data_cache = lines_string
431
-
432
- pattern = r'(\d+)%\|.*\|(\d+)/(\d+)(?:,\sbest_cost=(\d+\.\d+))?' # The magic of AI
433
- matches = re.findall(pattern, self.data_cache)
434
- filtered_matches = [match for match in matches if match[3] != '']
435
- matches = filtered_matches
436
-
437
- if len(matches) > 0:
438
- df = pd.DataFrame(matches, columns=['percent', 'completed_rounds', 'total_rounds', 'best_cost'], dtype=float)
439
- df = df[df['best_cost'] != '']
440
- df = df.dropna()
441
- df = df.drop_duplicates()
442
- df['round_step'] = (df['completed_rounds'].diff() < 0).cumsum()
443
- df = df.drop_duplicates(subset=['completed_rounds', 'round_step'])
444
-
445
- GraphGenerator.best_cost_stacked(self.running_config['steps'], df, self.option_manager)
446
- GraphGenerator.best_cost_by_round(self.running_config['steps'], df, self.option_manager)
447
- GraphGenerator.table(self.running_config['steps'], df, self.option_manager)
448
- self.update_graph("")
449
-
450
- match = matches[-1]
451
- percent = int(match[0])
452
- completed_rounds = int(match[1])
453
- total_rounds = int(match[2])
454
- best_cost = float(match[3]) if match[3] else None
455
-
456
- if (percent > 0):
457
- self.progress_bar.stop()
458
- self.progress_bar.configure(mode="determinate")
459
- self.progress_bar.set(percent/100)
460
- self.progress_message_left.configure(text="Percent Complete: " + str(percent) + "%")
461
- self.progress_message_middle.configure(text=str(completed_rounds) + "/" + str(total_rounds))
462
- self.progress_message_right.configure(text="Best Cost: " + str(best_cost))
463
- else:
464
- self.progress_bar.configure(mode="indeterminate")
465
- self.progress_bar.start()
466
- self.progress_message_left.configure(text="")
467
- self.progress_message_middle.configure(text="Starting new round...")
468
- self.progress_message_right.configure(text="")
469
-
470
-
471
-
472
- if self.train_process.is_alive():
473
- self.after(1000, self.watch_loop)
474
- else:
475
- self.progress_bar.stop()
476
- self.progress_bar.configure(mode="indeterminate")
477
- self.progress_bar.start()
478
- self.progress_message_left.configure(text="")
479
- self.progress_message_middle.configure(text="Calibration finished!")
480
- self.progress_message_right.configure(text="")
481
- self.textbox.insert("0.0", "\nCalibration finished!\n")
482
268
 
483
269
  def open_graph_in_browser(self):
484
270
  # Open the file in the default program
@@ -497,32 +283,6 @@ class App(customtkinter.CTk):
497
283
  else:
498
284
  subprocess.Popen(["xdg-open", file_path])
499
285
 
500
- def stop(self):
501
- print("Stopping...")
502
- self.train_process.terminate()
503
-
504
- info = self.option_manager.get_project_data()
505
- folder = os.path.join(info['path'], info['name'])
506
-
507
- if not os.path.exists(folder):
508
- os.makedirs(folder)
509
-
510
- # Stop the process
511
- if (os.path.exists(os.path.join(folder, 'output.txt'))):
512
- os.remove(os.path.join(folder, 'output.txt'))
513
-
514
- if (os.path.exists(os.path.join(folder, 'error.txt'))):
515
- os.remove(os.path.join(folder, 'error.txt'))
516
-
517
- self.textbox.insert("0.0", "\nCalibration terminated!\n")
518
- self.progress_bar.stop()
519
- self.progress_bar.configure(mode="determinate")
520
- self.progress_bar.set(0)
521
- self.progress_message_left.configure(text="")
522
- self.progress_message_middle.configure(text="Calibration stopped!")
523
- self.progress_message_right.configure(text="")
524
-
525
-
526
286
  def open_input_dialog_event(self):
527
287
  dialog = customtkinter.CTkInputDialog(text="Type in a number:", title="CTkInputDialog")
528
288
  print("CTkInputDialog:", dialog.get_input())
@@ -0,0 +1,234 @@
1
+
2
+ import customtkinter
3
+ import json
4
+ import os
5
+ from multiprocessing import Process
6
+ import traceback
7
+ import re
8
+ import ast
9
+ import pandas as pd
10
+ import numpy as np
11
+
12
+ from ...util import PSORunner
13
+ from ...util import GraphGenerator
14
+ from ...util.CTkToolTip import CTkToolTip as ctt
15
+
16
+ def create_tab(self, tab):
17
+
18
+ def run():
19
+ metrics = self.option_manager.get_metrics()
20
+ self.running_config = metrics
21
+
22
+ self.progress_bar.configure(mode="indeterminnate")
23
+ self.progress_bar.start()
24
+
25
+ self.data_x = [0]
26
+ self.data_y = [0]
27
+
28
+ self.progress_message_middle.configure(text="Calibration starting...")
29
+
30
+ self.textbox.insert("0.0", "Starting calibration...\n\n")
31
+ self.textbox.insert("0.0", "Calibration Parameters:\n")
32
+ self.textbox.insert("0.0", json.dumps(metrics, indent=4) + "\n\n")
33
+ try:
34
+ info = self.option_manager.get_project_data()
35
+ folder = os.path.join(info['path'], info['name'])
36
+
37
+
38
+ self.train_process = Process(target=PSORunner.run_process, args=(metrics, folder))
39
+ self.train_process.daemon = True
40
+ self.train_process.start()
41
+ self.after(1000, watch_loop)
42
+ self.string_cache = ""
43
+ self.data_cache = ""
44
+
45
+ except Exception as e:
46
+ self.textbox.insert("0.0", "An exception occurred!\n Exception: " + str(e) + "\n\n")
47
+ self.textbox.insert("0.0", "Stack trace:\n")
48
+ self.textbox.insert("0.0", traceback.format_exc())
49
+ self.textbox.insert("0.0", "\n\n")
50
+ self.textbox.insert("0.0", "Calibration failed!")
51
+ self.progress_message_left.configure(text="")
52
+ self.progress_message_middle.configure(text="Calibration failed! See error log below.")
53
+ self.progress_message_right.configure(text="")
54
+ self.progress_bar.stop()
55
+ self.progress_bar.configure(mode="determinate")
56
+ self.progress_bar.set(0)
57
+
58
+ def stop():
59
+ print("Stopping...")
60
+ self.train_process.terminate()
61
+
62
+ info = self.option_manager.get_project_data()
63
+ folder = os.path.join(info['path'], info['name'])
64
+
65
+ if not os.path.exists(folder):
66
+ os.makedirs(folder)
67
+
68
+ # Stop the process
69
+ if (os.path.exists(os.path.join(folder, 'output.txt'))):
70
+ os.remove(os.path.join(folder, 'output.txt'))
71
+
72
+ if (os.path.exists(os.path.join(folder, 'error.txt'))):
73
+ os.remove(os.path.join(folder, 'error.txt'))
74
+
75
+ self.textbox.insert("0.0", "\nCalibration terminated!\n")
76
+ self.progress_bar.stop()
77
+ self.progress_bar.configure(mode="determinate")
78
+ self.progress_bar.set(0)
79
+ self.progress_message_left.configure(text="")
80
+ self.progress_message_middle.configure(text="Calibration stopped!")
81
+ self.progress_message_right.configure(text="")
82
+
83
+ def watch_loop():
84
+ # Check if file exists:
85
+
86
+ info = self.option_manager.get_project_data()
87
+ folder = os.path.join(info['path'], info['name'])
88
+
89
+ if not os.path.exists(folder):
90
+ os.makedirs(folder)
91
+
92
+ if (os.path.exists(os.path.join(folder, 'output.txt'))):
93
+ with open(os.path.join(folder, 'output.txt'), 'r') as f:
94
+ lines = f.readlines()
95
+ lines_string = "".join(lines)
96
+
97
+ new_characters = lines_string.replace(self.string_cache, "")
98
+ # Update the textbox with characters not in self.string_cache
99
+ self.textbox.insert('0.0', new_characters)
100
+ self.string_cache = lines_string
101
+ print(new_characters, end="")
102
+
103
+ try:
104
+ with open(os.path.join(folder, "output.txt"), "r") as f:
105
+ text = f.read()
106
+
107
+ calibrated_params_pattern = r"calibrated params: ({.*?})"
108
+ best_particle_values_pattern = r"best particle values: (\[.*?\])"
109
+ progress_pattern = r"Progress - best_round_cost:(.*?), rel_round_tol:(.*?), rtol:(.*?)\n"
110
+
111
+ calibrated_params = re.findall(calibrated_params_pattern, text)
112
+ best_particle_values = re.findall(best_particle_values_pattern, text)
113
+ progress_values = re.findall(progress_pattern, text)
114
+
115
+ for index, pp in enumerate(best_particle_values):
116
+ pp = pp.strip()
117
+ pp = pp.replace('[ ', '[')
118
+ pp = pp.replace(' ', ',')
119
+ pp = pp.replace(' ', ',')
120
+ best_particle_values[index] = pp
121
+
122
+ calibrated_params = [ast.literal_eval(i) for i in calibrated_params]
123
+ best_particle_values = [ast.literal_eval(i) for i in best_particle_values]
124
+ progress_values = [tuple(map(float, i)) for i in progress_values]
125
+
126
+ print(calibrated_params)
127
+
128
+ GraphGenerator.calibrated_params_by_round(self.running_config['steps'], calibrated_params, self.option_manager)
129
+ self.update_graph("")
130
+ except Exception as e:
131
+ # Print stack trace
132
+ traceback.print_exc()
133
+
134
+ print(e)
135
+
136
+ if (os.path.exists(os.path.join(folder, 'error.txt'))):
137
+ with open(os.path.join(folder, 'error.txt'), 'r') as f:
138
+ lines = f.readlines()
139
+ lines_string = "".join(lines)
140
+ self.data_cache = lines_string
141
+
142
+ pattern = r'(\d+)%\|.*\|(\d+)/(\d+)(?:,\sbest_cost=(\d+\.\d+))?' # The magic of AI
143
+ matches = re.findall(pattern, self.data_cache)
144
+ filtered_matches = [match for match in matches if match[3] != '']
145
+ matches = filtered_matches
146
+
147
+ if len(matches) > 0:
148
+ df = pd.DataFrame(matches, columns=['percent', 'completed_rounds', 'total_rounds', 'best_cost'], dtype=float)
149
+ df = df[df['best_cost'] != '']
150
+ df = df.dropna()
151
+ df = df.drop_duplicates()
152
+ df['round_step'] = (df['completed_rounds'].diff() < 0).cumsum()
153
+ df = df.drop_duplicates(subset=['completed_rounds', 'round_step'])
154
+
155
+ GraphGenerator.best_cost_stacked(self.running_config['steps'], df, self.option_manager)
156
+ GraphGenerator.best_cost_by_round(self.running_config['steps'], df, self.option_manager)
157
+ GraphGenerator.table(self.running_config['steps'], df, self.option_manager)
158
+ self.update_graph("")
159
+
160
+ match = matches[-1]
161
+ percent = int(match[0])
162
+ completed_rounds = int(match[1])
163
+ total_rounds = int(match[2])
164
+ best_cost = float(match[3]) if match[3] else None
165
+
166
+ if (percent > 0):
167
+ self.progress_bar.stop()
168
+ self.progress_bar.configure(mode="determinate")
169
+ self.progress_bar.set(percent/100)
170
+ self.progress_message_left.configure(text="Percent Complete: " + str(percent) + "%")
171
+ self.progress_message_middle.configure(text=str(completed_rounds) + "/" + str(total_rounds))
172
+ self.progress_message_right.configure(text="Best Cost: " + str(best_cost))
173
+ else:
174
+ self.progress_bar.configure(mode="indeterminate")
175
+ self.progress_bar.start()
176
+ self.progress_message_left.configure(text="")
177
+ self.progress_message_middle.configure(text="Starting new round...")
178
+ self.progress_message_right.configure(text="")
179
+
180
+
181
+
182
+ if self.train_process.is_alive():
183
+ self.after(1000, watch_loop)
184
+ else:
185
+ self.progress_bar.stop()
186
+ self.progress_bar.configure(mode="indeterminate")
187
+ self.progress_bar.start()
188
+ self.progress_message_left.configure(text="")
189
+ self.progress_message_middle.configure(text="Calibration finished!")
190
+ self.progress_message_right.configure(text="")
191
+ self.textbox.insert("0.0", "\nCalibration finished!\n")
192
+
193
+ # URL
194
+ tab.grid_columnconfigure(0, weight=1)
195
+ tab.grid_rowconfigure(0, weight=1)
196
+ tab.grid_rowconfigure(1, weight=1)
197
+ tab.grid_rowconfigure(2, weight=200)
198
+ self.url = customtkinter.CTkEntry(tab, textvariable=self.option_manager.get_arguments()['url'])
199
+ self.url.grid(row=0, column=0, columnspan=1, padx=(20, 20), pady=(20, 20), sticky="nsew")
200
+
201
+ self.run_button = customtkinter.CTkButton(tab, text="Run", command=run)
202
+ self.run_button.grid(row=0, column=1, padx=(20, 20), pady=(20, 20), sticky="nsew")
203
+ ctt(self.run_button, delay=0.5, message="Start calibration...")
204
+
205
+
206
+ self.stop_button = customtkinter.CTkButton(tab, text="Stop", command=stop)
207
+ self.stop_button.grid(row=0, column=2, padx=(20, 20), pady=(20, 20), sticky="nsew")
208
+ ctt(self.stop_button, delay=0.5, message="Stop calibration...")
209
+
210
+ self.progress_container = customtkinter.CTkFrame(tab)
211
+ self.progress_container.grid_columnconfigure(0, weight=1)
212
+ self.progress_container.grid_columnconfigure(1, weight=1)
213
+ self.progress_container.grid_columnconfigure(2, weight=1)
214
+ self.progress_container.grid(row=1, column=0, columnspan=3, padx=(20, 20), pady=(20, 20), sticky="nsew")
215
+
216
+ # Add progress bar to progress container
217
+ self.progress_message_left = customtkinter.CTkLabel(self.progress_container, text="")
218
+ self.progress_message_left.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="w")
219
+
220
+ self.progress_message_middle = customtkinter.CTkLabel(self.progress_container, text="Calibration not running...")
221
+ self.progress_message_middle.grid(row=0, column=1, padx=(10, 10), pady=(10, 10), sticky="ew")
222
+
223
+ self.progress_message_right = customtkinter.CTkLabel(self.progress_container, text="")
224
+ self.progress_message_right.grid(row=0, column=2, padx=(10, 10), pady=(10, 10), sticky="e")
225
+
226
+ self.progress_bar = customtkinter.CTkProgressBar(self.progress_container)
227
+ self.progress_bar.grid(row=1, column=0, columnspan=3, padx=(10, 10), pady=(10, 10), sticky="ew")
228
+ self.progress_bar.set(0)
229
+ ctt(self.progress_bar, delay=0.5, message="Current calibration progress")
230
+
231
+ self.textbox = customtkinter.CTkTextbox(tab)
232
+ self.textbox.grid(row=2, column=0, columnspan=3, padx=(20, 20), pady=(20, 20), sticky="nsew")
233
+ self.textbox.insert("0.0", "Welcome to the CSIP PSO Calibration Tool!\n\nUse the Calibration tab to define steps and calibration parameters. Use this tab to run and observe calibration progress. Once finished, use the Visualization tab to generate figures and graphs.")
234
+
File without changes