mg-pso-gui 0.1.12__tar.gz → 0.1.36__tar.gz

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