mg-pso-gui 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ import csip
2
+ import cosu
3
+ import sys
4
+ import multiprocessing
5
+ import threading
6
+ import time
7
+ import os
8
+
9
+ from cosu.pso import global_best
10
+
11
+ def run_process(data, queue):
12
+ steps = data['steps']
13
+ args = data['arguments']
14
+ calib = data['calibration_parameters']
15
+
16
+ calibration_map = {}
17
+ for param in calib:
18
+ param_name = param['name']
19
+ param_value = param['value']
20
+ calibration_map[param_name] = param_value
21
+
22
+ if (os.path.exists('output.txt')):
23
+ os.remove('output.txt')
24
+
25
+ if (os.path.exists('error.txt')):
26
+ os.remove('error.txt')
27
+
28
+ sys.stdout = open('output.txt', 'w')
29
+ sys.stderr = open('error.txt', 'w')
30
+
31
+ options = {}
32
+ oh_strategy = {}
33
+
34
+ for key in calibration_map.keys():
35
+ if "options_" in key:
36
+ options[key.replace("options_", "")] = float(calibration_map[key])
37
+ if "strategy_" in key:
38
+ oh_strategy[key.replace("strategy_", "")] = calibration_map[key]
39
+
40
+ print("\n")
41
+ print(calibration_map)
42
+ print("\n")
43
+ print(options)
44
+ print("\n")
45
+ print(oh_strategy)
46
+ print("\n")
47
+
48
+ optimizer, trace = global_best(steps, # step definition
49
+ rounds=(int(calibration_map['min_rounds']), int(calibration_map['max_rounds'])), # min/max number of rounds
50
+ args=args, # static arguments
51
+ n_particles=int(calibration_map['n_particles']), # number of particle candidates for each param
52
+ iters=int(calibration_map['iters']), # max # of iterations
53
+ n_threads=int(calibration_map['n_threads']), # number of threads to use
54
+ # ftol=0.00000001, # min cost function delta for convergence
55
+ options=options, # hyperparameter
56
+ oh_strategy=oh_strategy, # adaptive hyperparameter adjustments based on current and max # of iterations
57
+ conf={
58
+ 'service_timeout': int(calibration_map['service_timeout']),
59
+ 'http_retry': int(calibration_map['http_retry']),
60
+ 'http_allow_redirects': True if calibration_map['allow_redirects'] == "True" else False,
61
+ 'async_call': True if calibration_map['async_call'] == "True" else False,
62
+ 'http_conn_timeout': int(calibration_map['conn_timeout']),
63
+ 'http_read_timeout': int(calibration_map['read_timeout']),
64
+ 'particles_fail': int(calibration_map['particles_fail'])
65
+ },
66
+ result_queue=queue
67
+ )
68
+
@@ -0,0 +1,61 @@
1
+ from customtkinter import CTkScrollableFrame
2
+ from customtkinter import CTkFrame
3
+ from customtkinter import CTkLabel
4
+ from customtkinter import CTkButton
5
+ from customtkinter import CTkEntry
6
+ import tkinter as tk
7
+
8
+ global option_manager
9
+
10
+ class StaticParameterView(CTkScrollableFrame):
11
+ def __init__(self, *args,
12
+ option_manager: None,
13
+ **kwargs):
14
+ super().__init__(*args, **kwargs)
15
+
16
+ self.option_manager = option_manager
17
+ self.key_values = option_manager.get_arguments()['param']
18
+ self.edit_mode = False
19
+
20
+ self.render()
21
+
22
+ def clear(self):
23
+ self.containerFrame.destroy()
24
+
25
+ def toggle_edit_mode(self):
26
+ self.clear()
27
+ self.edit_mode = not self.edit_mode
28
+ self.render()
29
+
30
+ def render(self):
31
+ row = 0
32
+ index = 0
33
+
34
+ self.containerFrame = CTkFrame(self)
35
+ self.containerFrame.grid(row=0, column=0, padx=(5, 5), pady=(5, 5), sticky="nsew")
36
+ self.containerFrame.grid_columnconfigure((0, 1), weight=1)
37
+
38
+ CTkLabel(self.containerFrame, text="Name:").grid(row=row, column=0, columnspan=1, padx=5, pady=5, sticky="")
39
+ CTkLabel(self.containerFrame, text="Value:").grid(row=row, column=1, columnspan=1, padx=5, pady=5, sticky="")
40
+ row += 1
41
+
42
+ for key_value_pair in self.key_values:
43
+ CTkEntry(self.containerFrame, textvariable=self.key_values[index]["name"]).grid(row=row, column=0, padx=(5, 5), pady=(5, 5), sticky="ew")
44
+
45
+ if self.edit_mode:
46
+ return_func = lambda index=index: (self.clear(), self.option_manager.remove_argument(index), self.render())
47
+ CTkButton(self.containerFrame, text="Remove", command=return_func).grid(row=row, column=1, padx=(5, 5), pady=(5, 5), sticky="ew")
48
+ else:
49
+ bb = CTkEntry(self.containerFrame)
50
+ bb.grid(row=row, column=1, padx=(5, 5), pady=(5, 5), sticky="ew")
51
+ bb.configure(textvariable=self.key_values[index]["value"])
52
+ row += 1
53
+ index += 1
54
+
55
+ if self.edit_mode:
56
+ CTkButton(self.containerFrame, text="Exit", command=self.toggle_edit_mode).grid(row=row, column=0, padx=(5, 5), pady=(5, 5), sticky="ew")
57
+ else:
58
+ CTkButton(self.containerFrame, text="Edit", command=self.toggle_edit_mode).grid(row=row, column=0, padx=(5, 5), pady=(5, 5), sticky="ew")
59
+
60
+ add_key_func = lambda: (self.clear(), self.option_manager.add_argument("name", "value"), self.render())
61
+ CTkButton(self.containerFrame, text="Add Parameter", command=add_key_func).grid(row=row, column=1, padx=(5, 5), pady=(5, 5), sticky="ew")
mg-pso-gui/StepView.py ADDED
@@ -0,0 +1,118 @@
1
+ from customtkinter import CTkScrollableFrame
2
+ from customtkinter import CTkFrame
3
+ from customtkinter import CTkLabel
4
+ from customtkinter import CTkButton
5
+ from customtkinter import CTkEntry
6
+ from customtkinter import CTkTextbox
7
+ from customtkinter import CTkImage
8
+ from PIL import Image
9
+ import os
10
+
11
+ import BoundsList
12
+ import FunctionsList
13
+
14
+
15
+ class StepView(CTkScrollableFrame):
16
+ def __init__(self, *args,
17
+ option_manager: None,
18
+ **kwargs):
19
+ super().__init__(*args, **kwargs)
20
+
21
+ self.option_manager = option_manager
22
+
23
+ self.render()
24
+
25
+ def clear(self):
26
+ self.containerFrame.destroy()
27
+
28
+ def create_new_step(self):
29
+
30
+ self.clear()
31
+ example_step = [{ # step 1
32
+ 'param': [
33
+ {
34
+ 'name': 'soilOutLPS',
35
+ 'bounds': (0.0, 2.0)
36
+ },
37
+ {
38
+ 'name': 'lagInterflow',
39
+ 'bounds': (10.0, 80.0)
40
+ }
41
+ ],
42
+ 'objfunc': [
43
+ {
44
+ 'name': 'ns',
45
+ 'of': 'ns',
46
+ 'data': ('obs_data02_14.csv/obs/orun[1]',
47
+ 'output/csip_run/out/Outlet.csv/output/catchmentSimRunoff')
48
+ }
49
+ ],
50
+ 'open': True
51
+ }]
52
+ self.option_manager.add_steps(example_step)
53
+
54
+ self.render()
55
+
56
+ def render(self):
57
+
58
+ row = 0
59
+ index = 0
60
+
61
+ self.containerFrame = CTkFrame(self)
62
+ self.containerFrame.grid(row=0, column=0, padx=(
63
+ 10, 10), pady=(10, 10), sticky="nsew")
64
+ self.containerFrame.grid_columnconfigure((0, 1), weight=1)
65
+
66
+ self.steps = self.option_manager.get_steps()
67
+
68
+ for step in self.steps:
69
+
70
+ up_image = CTkImage(Image.open(os.path.join("./images", "up.png")), size=(20, 20))
71
+ down_image = CTkImage(Image.open(os.path.join("./images", "down.png")), size=(20, 20))
72
+ trash_image = CTkImage(Image.open(os.path.join("./images", "trash.png")), size=(20, 20))
73
+ expand_image = CTkImage(Image.open(os.path.join("./images", "expand.png")), size=(20, 20))
74
+ collapse_image = CTkImage(Image.open(os.path.join("./images", "collapse.png")), size=(20, 20))
75
+
76
+
77
+ expand_func = lambda index=index: (self.clear(), self.option_manager.toggle_step_open(index), self.render())
78
+ up_func = lambda index=index: (self.clear(), self.option_manager.move_step_up(index), self.render())
79
+ down_func = lambda index=index: (self.clear(), self.option_manager.move_step_down(index), self.render())
80
+ remove_func = lambda index=index: (self.clear(), self.option_manager.remove_step(index), self.render())
81
+
82
+ #CTkLabel(self.containerFrame, text="Step:").grid(row=row, column=0, padx=10, pady=5, sticky="nsew")
83
+
84
+ button_container = CTkFrame(self.containerFrame, width=200)
85
+ button_container.grid(row=row, column=1, sticky="nse", padx=(10, 10), pady=(10, 10))
86
+ button_container.grid_rowconfigure(0, weight=1)
87
+ button_container.grid_columnconfigure(0, weight=1)
88
+
89
+ CTkEntry(self.containerFrame, textvariable=step['name'], width=500).grid(row=row, column=0, padx=(20, 20), pady=(20, 20), sticky="nsw")
90
+ #CTkLabel(self.containerFrame, textvariable=step['message']).grid(row=row, column=1, padx=(20, 20), pady=(20, 20), sticky="nsew")
91
+ CTkButton(button_container, width=30, text=None, image=expand_image if not step['open'] else collapse_image, command=expand_func).grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="nsew")
92
+ CTkButton(button_container, width=30, text=None, image=up_image, state="disabled" if index==0 else "normal", fg_color="gray" if index==0 else None, command=up_func).grid(row=0, column=1, padx=(10, 10), pady=(10, 10), sticky="nsew")
93
+ CTkButton(button_container, width=30, text=None, image=down_image, state="disabled" if index==(len(self.steps)-1) else "normal", fg_color="gray" if index==(len(self.steps)-1) else None, command=down_func).grid(row=0, column=2, padx=(10, 10), pady=(10, 10), sticky="nsew")
94
+ CTkButton(button_container, width=30, text=None, image=trash_image, command=remove_func).grid(row=0, column=3, padx=(10, 10), pady=(10, 10), sticky="nsew")
95
+
96
+ row += 1
97
+
98
+ if step['open']:
99
+ bounds = BoundsList.BoundsList(
100
+ self.containerFrame, option_manager=self.option_manager, step_index=index)
101
+ bounds.grid(row=row, column=0, padx=(10, 10),
102
+ pady=(10, 10), sticky="nsew")
103
+ bounds.grid_columnconfigure(0, weight=1)
104
+ bounds.grid_rowconfigure(0, weight=1)
105
+
106
+ funcs = FunctionsList.FunctionsList(
107
+ self.containerFrame, option_manager=self.option_manager, step_index=index)
108
+ funcs.grid(row=row, column=1, padx=(10, 10),
109
+ pady=(10, 10), sticky="nsew")
110
+ funcs.grid_columnconfigure(0, weight=1)
111
+ funcs.grid_rowconfigure(0, weight=1)
112
+
113
+ row += 1
114
+ index += 1
115
+
116
+ # Create an "Add step button that is centered
117
+ CTkButton(self.containerFrame, text="Add Step", command=self.create_new_step).grid(
118
+ row=row, columnspan=2, column=0, padx=(10, 10), pady=(10, 10), sticky="ew")
mg-pso-gui/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from main import start