-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresimulation.py
More file actions
1690 lines (1504 loc) · 73.6 KB
/
presimulation.py
File metadata and controls
1690 lines (1504 loc) · 73.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import json
import subprocess
import random
from PyQt5.QtWidgets import (
QApplication, QWidget, QFrame, QVBoxLayout, QLabel, QPushButton, QSpinBox,
QCheckBox, QGroupBox, QFormLayout, QHBoxLayout, QGridLayout,
QComboBox, QScrollArea, QStyle, QMessageBox, QSlider,
QDialog, QDialogButtonBox
)
from PyQt5.QtCore import Qt, QSize
from recap_simulation import RecapSimulationPage
from PyQt5.QtGui import QPixmap, QFont
# ------------------------------------------------------------------------------------------
# Dialog window for the "Client Selector" parameters
# ------------------------------------------------------------------------------------------
class ClientSelectorDialog(QDialog):
def __init__(self, existing_params=None):
super().__init__()
self.setWindowTitle("AP4Fed")
self.resize(400, 300)
self.existing_params = existing_params or {}
layout = QVBoxLayout(self)
layout.setAlignment(Qt.AlignTop)
self.strategy_label = QLabel("Selection Strategy:")
self.strategy_combo = QComboBox()
self.strategy_combo.addItem("Resource-Based")
self.strategy_combo.addItem("SSIM-Based")
self.strategy_combo.addItem("Data-Based")
self.strategy_combo.addItem("Performance-based")
self.strategy_combo.model().item(2).setEnabled(False)
self.strategy_combo.model().item(3).setEnabled(False)
layout.addWidget(self.strategy_label)
layout.addWidget(self.strategy_combo)
# Selection Criteria
self.criteria_label = QLabel("Selection Criteria:")
self.criteria_combo = QComboBox()
layout.addWidget(self.criteria_label)
layout.addWidget(self.criteria_combo)
self.strategy_combo.currentIndexChanged.connect(self.update_criteria_options)
# Selection Value
self.value_label = QLabel("Minimum Value:")
self.value_spinbox = QSpinBox()
self.value_spinbox.setRange(1, 128)
self.value_spinbox.setValue(4)
layout.addWidget(self.value_label)
layout.addWidget(self.value_spinbox)
self.explanation_label = QLabel("The client should have at least a minimum value CPU or RAM based on the selected criteria.")
self.explanation_label.setWordWrap(True)
self.explanation_label.setStyleSheet("font-size: 12px; color: gray;")
layout.addWidget(self.explanation_label)
# Explainer Type (for SSIM-based)
self.explainer_label = QLabel("Explainer Type:")
self.explainer_combo = QComboBox()
self.explainer_combo.addItems([
"GradCAM", "HiResCAM", "ScoreCAM", "GradCAMPlusPlus",
"AblationCAM", "XGradCAM", "EigenCAM", "FullGrad", "All"
])
layout.addWidget(self.explainer_label)
layout.addWidget(self.explainer_combo)
self.explainer_label.hide()
self.explainer_combo.hide()
if "selection_strategy" in self.existing_params:
self.strategy_combo.setCurrentText(self.existing_params["selection_strategy"])
self.update_criteria_options()
if "selection_criteria" in self.existing_params:
self.criteria_combo.setCurrentText(self.existing_params["selection_criteria"])
if "explainer_type" in self.existing_params:
self.explainer_combo.setCurrentText(self.existing_params["explainer_type"])
if "selection_value" in self.existing_params:
self.value_spinbox.setValue(self.existing_params["selection_value"])
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
layout.addWidget(button_box)
def update_criteria_options(self):
strategy = self.strategy_combo.currentText()
self.criteria_combo.clear()
if strategy == "SSIM-Based":
self.criteria_combo.addItems(["Min","Mid","Max"])
self.value_label.hide()
self.value_spinbox.hide()
self.explanation_label.hide()
self.explainer_label.show()
self.explainer_combo.show()
else:
self.explainer_label.hide()
self.explainer_combo.hide()
self.value_label.show()
self.value_spinbox.show()
self.explanation_label.show()
if strategy == "Resource-Based":
self.criteria_combo.addItems(["CPU", "RAM"])
elif strategy == "Data-Based":
self.criteria_combo.addItems(["IID", "non-IID"])
elif strategy == "Performance-based":
self.criteria_combo.addItems(["Accuracy", "Latency"])
def on_back(self):
self.close()
self.home_page_callback()
def get_params(self):
params = {
"selection_strategy": self.strategy_combo.currentText(),
"selection_criteria": self.criteria_combo.currentText(),
"selection_value": self.value_spinbox.value()
}
if self.strategy_combo.currentText() == "SSIM-Based":
params["explainer_type"] = self.explainer_combo.currentText()
return params
# ------------------------------------------------------------------------------------------
# Dialog window for the "Client Cluster" parameters
# ------------------------------------------------------------------------------------------
class ClientClusterDialog(QDialog):
def __init__(self, existing_params=None):
super().__init__()
self.setWindowTitle("Configure Client Cluster")
self.resize(400, 300)
self.existing_params = existing_params or {}
layout = QVBoxLayout(self)
layout.setAlignment(Qt.AlignTop)
# Clustering Strategy
self.strategy_label = QLabel("Clustering Strategy:")
self.strategy_combo = QComboBox()
self.strategy_combo.addItem("Resource-Based")
self.strategy_combo.addItem("Data-Based")
self.strategy_combo.addItem("Network-Based")
self.strategy_combo.model().item(2).setEnabled(False)
layout.addWidget(self.strategy_label)
layout.addWidget(self.strategy_combo)
self.criteria_label = QLabel("Clustering Criteria:")
self.criteria_combo = QComboBox()
layout.addWidget(self.criteria_label)
layout.addWidget(self.criteria_combo)
self.strategy_combo.currentIndexChanged.connect(self.update_criteria_options)
self.value_label = QLabel("Minimum Value:")
self.value_spinbox = QSpinBox()
self.value_spinbox.setRange(1, 128)
self.value_spinbox.setValue(1)
layout.addWidget(self.value_label)
layout.addWidget(self.value_spinbox)
self.explanation_label = QLabel("The clients will be clustered based on the selected criteria and a minimum [VALUE] if applicable.")
self.explanation_label.setWordWrap(True)
self.explanation_label.setStyleSheet("font-size: 12px; color: gray;")
layout.addWidget(self.explanation_label)
if "clustering_strategy" in self.existing_params:
self.strategy_combo.setCurrentText(self.existing_params["clustering_strategy"])
self.update_criteria_options()
if "clustering_criteria" in self.existing_params:
self.criteria_combo.setCurrentText(self.existing_params["clustering_criteria"])
if "clustering_value" in self.existing_params:
self.value_spinbox.setValue(self.existing_params["clustering_value"])
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
layout.addWidget(button_box)
def update_criteria_options(self):
strategy = self.strategy_combo.currentText()
self.criteria_combo.clear()
if strategy == "Resource-Based":
self.criteria_combo.addItems(["CPU", "RAM"])
elif strategy == "Data-Based":
self.criteria_combo.addItems(["IID", "non-IID"])
elif strategy == "Network-Based":
self.criteria_combo.addItems(["Latency", "Bandwidth"])
def get_params(self):
return {
"clustering_strategy": self.strategy_combo.currentText(),
"clustering_criteria": self.criteria_combo.currentText(),
"clustering_value": self.value_spinbox.value()
}
# ------------------------------------------------------------------------------------------
# Dialog window for the "Multi-Task Model Trainer" parameters
# ------------------------------------------------------------------------------------------
class MultiTaskModelTrainerDialog(QDialog):
def __init__(self, existing_params=None):
super().__init__()
self.setWindowTitle("Configure Multi-Task Model Trainer")
self.resize(400, 200)
self.existing_params = existing_params or {}
layout = QVBoxLayout(self)
layout.setAlignment(Qt.AlignTop)
self.m1_label = QLabel("Select Model M1:")
self.m1_combo = QComboBox()
self.m1_combo.addItems(["CIFAR-10", "CIFAR-100", "MNIST", "FashionMNIST", "KMNIST", "ImageNet100"])
layout.addWidget(self.m1_label)
layout.addWidget(self.m1_combo)
self.m2_label = QLabel("Select Model M2:")
self.m2_combo = QComboBox()
self.m2_combo.addItems(["CIFAR-10", "CIFAR-100", "MNIST", "FashionMNIST", "KMNIST", "ImageNet100"])
layout.addWidget(self.m2_label)
layout.addWidget(self.m2_combo)
if "model1" in self.existing_params:
self.m1_combo.setCurrentText(self.existing_params["model1"])
if "model2" in self.existing_params:
self.m2_combo.setCurrentText(self.existing_params["model2"])
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
layout.addWidget(button_box)
def accept(self):
if self.m1_combo.currentText() == self.m2_combo.currentText():
QMessageBox.warning(self, "Configuration Error",
"Model1 and Model2 cannot be the same.")
return
super().accept()
def get_params(self):
return {
"model1": self.m1_combo.currentText(),
"model2": self.m2_combo.currentText()
}
# ------------------------------------------------------------------------------------------
# Generic Dialog Window
# ------------------------------------------------------------------------------------------
class GenericPatternDialog(QDialog):
def __init__(self, pattern_name, existing_params=None):
super().__init__()
self.setWindowTitle(f"Configure {pattern_name}")
self.resize(400, 200)
self.pattern_name = pattern_name
self.existing_params = existing_params or {}
layout = QVBoxLayout(self)
layout.setAlignment(Qt.AlignTop)
self.var1_label = QLabel("Variable1:")
self.var1_input = QSpinBox()
self.var1_input.setRange(0, 999)
self.var1_input.setValue(self.existing_params.get("variable1", 0))
self.var2_label = QLabel("Variable2:")
self.var2_input = QComboBox()
self.var2_input.addItems(["OptionA", "OptionB", "OptionC"])
if "variable2" in self.existing_params:
self.var2_input.setCurrentText(self.existing_params["variable2"])
layout.addWidget(self.var1_label)
layout.addWidget(self.var1_input)
layout.addWidget(self.var2_label)
layout.addWidget(self.var2_input)
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
layout.addWidget(button_box)
def get_params(self):
return {
"variable1": self.var1_input.value(),
"variable2": self.var2_input.currentText()
}
# ------------------------------------------------------------------------------------------
# Main Class PreSimulationPage
# ------------------------------------------------------------------------------------------
class PreSimulationPage(QWidget):
def __init__(self, user_choices, home_page_callback):
super().__init__()
back_btn = QPushButton()
back_btn.setIcon(self.style().standardIcon(QStyle.SP_ArrowBack))
back_btn.setCursor(Qt.PointingHandCursor)
back_btn.setIconSize(QSize(24, 24))
back_btn.setFixedSize(36, 36)
back_btn.setCursor(Qt.PointingHandCursor)
back_btn.setStyleSheet("""
QPushButton {
background-color: transparent;
border: none;
}
QPushButton:hover {
background-color: #e0e0e0;
border-radius: 18px;
}
""")
back_btn.clicked.connect(self.on_back)
self.pattern_data = {
"Client Registry": {
"category": "Client Management Category",
"image": "img/patterns/clientregistry.png",
"description": "Maintains information about all participating client devices for client management.",
"benefits": "Centralized tracking of client states; easier organization.",
"drawbacks": "Requires overhead for maintaining the registry."
},
"Client Selector": {
"category": "Client Management Category",
"image": "img/patterns/clientselector.png",
"description": "Actively selects client devices for a specific training round based on predefined criteria to enhance model performance and system efficiency.",
"benefits": "Ensures only the most relevant clients train each round, potentially improving performance.",
"drawbacks": "May exclude important data from non-selected clients."
},
"Client Cluster": {
"category": "Client Management Category",
"image": "img/patterns/clientcluster.png",
"description": "Groups client devices based on their similarity in certain characteristics (e.g., resources, data distribution) to improve model performance and training efficiency.",
"benefits": "Allows specialized training; can handle different groups more effectively.",
"drawbacks": "Additional overhead to manage cluster membership."
},
"Message Compressor": {
"category": "Model Management Category",
"image": "img/patterns/messagecompressor.png",
"description": "Compresses and reduces the size of message data before each model exchange round to improve communication efficiency.",
"benefits": "Reduces bandwidth usage; can speed up communication rounds.",
"drawbacks": "Compression/decompression overhead might offset gains for large data."
},
"Model co-Versioning Registry": {
"category": "Model Management Category",
"image": "img/patterns/modelversioningregistry.png",
"description": "It is designed to store both the current model version trained by each client device and the aggregated model version stored on the server in a Federated Learning process.",
"benefits": "Enables reproducibility and consistent version tracking.",
"drawbacks": "Extra storage cost is incurred to store all the local and global models."
},
"Model Replacement Trigger": {
"category": "Model Management Category",
"image": "",
"description": "This Architectural Pattern is not yet implemented",
"benefits": "",
"drawbacks": ""
},
"Deployment Selector": {
"category": "Model Management Category",
"image": "",
"description": "This Architectural Pattern is not yet implemented",
"benefits": "",
"drawbacks": ""
},
"Multi-Task Model Trainer": {
"category": "Model Training Category",
"image": "img/patterns/multitaskmodeltrainer.png",
"description": "Utilizes data from related models on local devices to enhance efficiency.",
"benefits": "Potential knowledge sharing among similar tasks; improved training.",
"drawbacks": "Training logic may become more complex to handle multiple tasks."
},
"Heterogeneous Data Handler": {
"category": "Model Training Category",
"image": "img/patterns/heterogeneousdatahandler.png",
"description": "Addresses issues with non-IID and skewed data while maintaining data privacy.",
"benefits": "Better management of varied data distributions.",
"drawbacks": "Requires more sophisticated data partitioning and handling logic."
},
"Incentive Registry": {
"category": "Model Training Category",
"image": "",
"description": "This Architectural Pattern is not yet implemented",
"benefits": "",
"drawbacks": ""
},
"Asynchronous Aggregator": {
"category": "Model Aggregation Category",
"image": "",
"description": "This Architectural Pattern is not yet implemented",
"benefits": "",
"drawbacks": ""
},
"Decentralised Aggregator": {
"category": "Model Aggregation Category",
"image": "",
"description": "This Architectural Pattern is not yet implemented",
"benefits": "",
"drawbacks": ""
},
"Hierarchical Aggregator": {
"category": "Model Aggregation Category",
"image": "",
"description": "This Architectural Pattern is not yet implemented",
"benefits": "",
"drawbacks": ""
},
"Secure Aggregator": {
"category": "Model Aggregation Category",
"image": "",
"description": "This Architectural Pattern is not yet implemented",
"benefits": "",
"drawbacks": ""
}
}
super().__init__()
self.user_choices = user_choices
self.home_page_callback = home_page_callback
self.temp_pattern_config = {}
self.setWindowTitle("AP4Fed")
self.resize(800, 600)
self.setStyleSheet("""
QWidget {
background-color: white;
color: black;
}
QLabel {
color: black;
}
QPushButton {
background-color: green;
color: white;
border-radius: 5px;
font-size: 14px;
}
QPushButton:hover {
background-color: #00b300;
}
QPushButton:pressed {
background-color: #008000;
}
""")
main_layout = QVBoxLayout()
main_layout.setAlignment(Qt.AlignTop)
self.setLayout(main_layout)
choice_label = QLabel(f"Input Parameters Setup")
choice_label.setStyleSheet("color: black; font-size: 24px; font-weight: bold;")
choice_label.setAlignment(Qt.AlignCenter)
header_layout = QHBoxLayout()
header_layout.setContentsMargins(0, 0, 0, 10)
header_layout.addWidget(back_btn, alignment=Qt.AlignLeft)
header_layout.addWidget(choice_label, stretch=1)
main_layout.insertLayout(0, header_layout)
general_settings_group = QGroupBox("General Settings")
general_settings_group.setStyleSheet(
"QGroupBox::title { font-weight: bold; }"
)
general_settings_group.setStyleSheet("""
QGroupBox {
background-color: white;
border: 1px solid lightgray;
border-radius: 5px;
margin-top: 10px;
}
QGroupBox:title {
subcontrol-origin: margin;
subcontrol-position: top center;
padding: 0 3px;
color: black;
font-size: 14px;
font-weight: bold;
}
""")
g_layout = QGridLayout()
g_layout.setHorizontalSpacing(24)
g_layout.setVerticalSpacing(14)
bold_font = QFont()
bold_font.setBold(True)
rounds_label = QLabel("Number of Rounds:")
rounds_label.setFont(bold_font)
self.rounds_input = QSpinBox()
self.rounds_input.setRange(1, 100)
self.rounds_input.setValue(2)
clients_label = QLabel("Number of Clients:")
clients_label.setFont(bold_font)
self.clients_input = QSpinBox()
self.clients_input.setRange(1, 128)
self.clients_input.setValue(2)
clients_per_round_label = QLabel("Clients per Round:")
clients_per_round_label.setFont(bold_font)
self.clients_per_round_input = QSpinBox()
self.clients_per_round_input.setRange(1, 128)
self.clients_per_round_input.setValue(2)
self.clients_input.valueChanged.connect(self._sync_clients_per_round_range)
self._sync_clients_per_round_range(self.clients_input.value())
simulation_label = QLabel("Type of Simulation:")
font = simulation_label.font()
font.setBold(True)
simulation_label.setFont(font)
self.sim_type_combo = QComboBox()
self.sim_type_combo.addItems(["Local","Docker"])
self.sim_type_combo.setMinimumWidth(160)
adaptation_label = QLabel("Type of Adaptation:")
font = adaptation_label.font()
font.setBold(True)
adaptation_label.setFont(font)
self.adaptation_combo = QComboBox()
self.adaptation_combo.addItems(["None","Random","Expert-Driven","Single AI-Agent (Zero-Shot)","Single AI-Agent (Few-Shot)","Multiple AI-Agents (Voting-Based)","Multiple AI-Agents (Role-Based)","Multiple AI-Agents (Debate-Based)"])
self.adaptation_combo.setMinimumWidth(280)
self.llm_label = QLabel("LLM")
self.llm_label.setFont(bold_font)
self.llm_combo = QComboBox()
self.llm_combo.addItems(["llama3.2:3b","deepseek-r1:8b","gpt-oss:20b"])
self.llm_combo.setMinimumWidth(180)
self.llm_label.hide()
self.llm_combo.hide()
def _toggle_llm_selector(text):
vis = "single" in str(text).lower()
self.llm_label.setVisible(vis)
self.llm_combo.setVisible(vis)
def add_setting(row, col, setting_label, setting_widget):
field = QWidget()
field_layout = QVBoxLayout(field)
field_layout.setContentsMargins(0, 0, 0, 0)
field_layout.setSpacing(6)
field_layout.addWidget(setting_label)
field_layout.addWidget(setting_widget)
g_layout.addWidget(field, row, col)
add_setting(0, 0, rounds_label, self.rounds_input)
add_setting(0, 1, clients_label, self.clients_input)
add_setting(0, 2, clients_per_round_label, self.clients_per_round_input)
add_setting(1, 0, simulation_label, self.sim_type_combo)
add_setting(1, 1, adaptation_label, self.adaptation_combo)
add_setting(1, 2, self.llm_label, self.llm_combo)
self.adaptation_combo.currentTextChanged.connect(_toggle_llm_selector)
_toggle_llm_selector(self.adaptation_combo.currentText())
docker_status_label = QLabel("Docker Status:")
font = docker_status_label.font()
font.setBold(True)
docker_status_label.setFont(font)
self.docker_status_label = QLabel()
update_btn = QPushButton()
update_btn.setIcon(self.style().standardIcon(QStyle.SP_BrowserReload))
update_btn.setCursor(Qt.PointingHandCursor)
update_btn.clicked.connect(self.check_docker_status)
update_btn.setStyleSheet("""
QPushButton {
background-color: white;
}
""")
for w in (docker_status_label, self.docker_status_label, update_btn):
w.setVisible(False)
row = QHBoxLayout()
row.addWidget(docker_status_label)
row.addWidget(self.docker_status_label)
row.addWidget(update_btn)
row.addStretch()
docker_status_row = QWidget()
docker_status_row.setLayout(row)
g_layout.addWidget(docker_status_row, 2, 0, 1, 3)
def on_type_changed(text):
show = (text == "Docker")
for w in (docker_status_label, self.docker_status_label, update_btn):
w.setVisible(show)
if show:
self.check_docker_status()
self.sim_type_combo.currentTextChanged.connect(on_type_changed)
general_settings_group.setLayout(g_layout)
main_layout.addWidget(general_settings_group)
patterns_label = QLabel("Select Architectural Patterns to be applied:")
patterns_label.setAlignment(Qt.AlignLeft)
patterns_label.setStyleSheet("font-size: 14px; color: black; margin-top: 10px;")
main_layout.addWidget(patterns_label)
patterns_grid = QGridLayout()
patterns_grid.setSpacing(10)
self.pattern_checkboxes = {}
macrotopics = [
("Client Management Category", [
"Client Registry: Maintains information about all participating client devices for client management.",
"Client Selector: Actively selects client devices for a specific training round based on predefined criteria to enhance model performance and system efficiency.",
"Client Cluster: Groups client devices based on their similarity in certain characteristics (e.g., resources, data distribution) to improve model performance and training efficiency."
]),
("Model Management Category", [
"Message Compressor: Compresses and reduces the size of message data before each model exchange round to improve communication efficiency.",
"Model co-Versioning Registry: Stores and aligns local models with the global model versions for tracking purposes.",
"Model Replacement Trigger: Triggers model replacement when performance degradation is detected.",
"Deployment Selector: Matches converging global models with suitable clients for task optimization."
]),
("Model Training Category", [
"Heterogeneous Data Handler: Addresses issues with non-IID and skewed data while maintaining data privacy.",
"Multi-Task Model Trainer: Utilizes data from related models on local devices to enhance efficiency.",
"Incentive Registry: Measures and records client contributions and provides incentives."
]),
("Model Aggregation Category", [
"Asynchronous Aggregator: Aggregates asynchronously to reduce latency.",
"Decentralised Aggregator: Removes the central server to prevent single-point failures.",
"Hierarchical Aggregator: Adds an edge layer for partial aggregation to improve efficiency.",
"Secure Aggregator: Ensures security during aggregation."
])
]
row, col = 0, 0
enabled_patterns = [
"Client Registry",
"Client Selector",
"Client Cluster",
"Message Compressor",
"Model co-Versioning Registry",
#"Multi-Task Model Trainer",
"Heterogeneous Data Handler",
]
for topic, patterns_list in macrotopics:
topic_group = QGroupBox(topic)
topic_group.setStyleSheet("""
QGroupBox {
background-color: white;
border: 1px solid lightgray;
border-radius: 5px;
margin-top: 5px;
}
QGroupBox:title {
subcontrol-origin: margin;
subcontrol-position: top center;
padding: 0 5px;
color: black;
font-size: 13px;
font-weight: bold;
}
""")
topic_layout = QVBoxLayout()
topic_layout.setSpacing(5)
for pattern_entry in patterns_list:
pattern_name = pattern_entry.split(":")[0].strip()
pattern_desc = pattern_entry.split(":")[1].strip()
hl = QHBoxLayout()
hl.setSpacing(6)
info_button = QPushButton()
info_button.setCursor(Qt.PointingHandCursor)
info_icon = self.style().standardIcon(QStyle.SP_MessageBoxInformation)
info_button.setIcon(info_icon)
info_button.setFixedSize(24, 24)
info_button.setStyleSheet("""
QPushButton {
background-color: transparent;
border: none;
padding: 0px;
margin: 0px;
}
QPushButton:hover {
background-color: #e0e0e0;
}
""")
def info_clicked(checked, p=pattern_name):
if p in self.pattern_data:
data = self.pattern_data[p]
cat_ = data["category"]
img_ = data["image"]
desc_ = data["description"]
ben_ = data["benefits"]
dr_ = data["drawbacks"]
self.show_pattern_info(p, cat_, img_, desc_, ben_, dr_)
else:
self.show_pattern_info(p, topic, "img/fittizio.png", pattern_desc,
"No custom benefits", "No custom drawbacks")
info_button.clicked.connect(info_clicked)
checkbox = QCheckBox(pattern_name)
if pattern_name == "Model co-Versioning Registry":
checkbox.setToolTip(pattern_desc)
checkbox.setStyleSheet("QCheckBox { color: black; font-size: 12px; }")
if pattern_name not in enabled_patterns:
checkbox.setEnabled(False)
checkbox.setStyleSheet("QCheckBox { color: darkgray; font-size: 12px; }")
if pattern_name == "Client Registry":
checkbox.setText("Client Registry (Active by Default)")
checkbox.setChecked(True)
def prevent_uncheck(state):
if state != Qt.Checked:
checkbox.blockSignals(True)
checkbox.setChecked(True)
checkbox.blockSignals(False)
checkbox.stateChanged.connect(prevent_uncheck)
if pattern_name in ["Message Compressor", "Heterogeneous Data Handler", "Model co-Versioning Registry"]:
configure_button = None
elif pattern_name in ["Client Selector", "Client Cluster", "Multi-Task Model Trainer"]:
configure_button = QPushButton("Configure")
configure_button.setCursor(Qt.PointingHandCursor)
configure_button.setStyleSheet("""
QPushButton {
background-color: #ffc107;
color: white;
font-size: 10px;
padding: 8px 16px;
border-radius: 5px;
text-align: left;
}
QPushButton:hover {
background-color: #e0a800;
}
QPushButton:pressed {
background-color: #c69500;
}
""")
configure_button.setVisible(False)
configure_button.setFixedWidth(80)
configure_button.clicked.connect(lambda _, p=pattern_name: open_config(p))
else:
configure_button = None
def on_checkbox_state_changed(state, btn, p=pattern_name):
if p == "Multi-Task Model Trainer" and state == Qt.Checked:
if self.clients_input.value() < 4:
msg_box = QMessageBox(self)
msg_box.setWindowTitle("Configuration Error")
msg_box.setText("Multi-Task Model Trainer requires at least 4 clients.")
msg_box.setIcon(QMessageBox.Warning)
ok_button = msg_box.addButton("OK", QMessageBox.AcceptRole)
ok_button.setCursor(Qt.PointingHandCursor)
ok_button.setStyleSheet("""
QPushButton {
background-color: green;
color: white;
font-size: 10px;
padding: 8px 16px;
border-radius: 5px;
}
QPushButton:hover {
background-color: #00b300;
}
QPushButton:pressed {
background-color: #008000;
}
""")
msg_box.exec_()
checkbox.blockSignals(True)
checkbox.setChecked(False)
checkbox.blockSignals(False)
return
if btn is not None:
btn.setVisible(state == Qt.Checked)
if state == Qt.Checked:
if p not in self.temp_pattern_config:
self.temp_pattern_config[p] = {
"enabled": True,
"params": {}
}
else:
if p in self.temp_pattern_config:
self.temp_pattern_config[p]["enabled"] = False
checkbox.stateChanged.connect(
lambda state, btn=configure_button, p=pattern_name:
on_checkbox_state_changed(state, btn, p)
)
def open_config(p_name):
if p_name == "Client Selector":
existing_params = self.temp_pattern_config.get(p_name, {}).get("params", {})
dlg = ClientSelectorDialog(existing_params)
if dlg.exec_() == QDialog.Accepted:
new_params = dlg.get_params()
self.temp_pattern_config[p_name] = {
"enabled": True,
"params": new_params
}
elif p_name == "Client Cluster":
existing_params = self.temp_pattern_config.get(p_name, {}).get("params", {})
dlg = ClientClusterDialog(existing_params)
if dlg.exec_() == QDialog.Accepted:
new_params = dlg.get_params()
self.temp_pattern_config[p_name] = {
"enabled": True,
"params": new_params
}
elif p_name == "Multi-Task Model Trainer":
existing_params = self.temp_pattern_config.get(p_name, {}).get("params", {})
dlg = MultiTaskModelTrainerDialog(existing_params)
if dlg.exec_() == QDialog.Accepted:
new_params = dlg.get_params()
self.temp_pattern_config[p_name] = {
"enabled": True,
"params": new_params
}
else:
QMessageBox.information(self, "Not Implemented", f"The configuration for {p_name} is not implemented yet.")
hl.addWidget(info_button)
hl.addWidget(checkbox)
if configure_button is not None:
hl.addWidget(configure_button)
topic_layout.addLayout(hl)
self.pattern_checkboxes[pattern_name] = checkbox
topic_group.setLayout(topic_layout)
patterns_grid.addWidget(topic_group, row, col)
col += 1
if col > 1:
col = 0
row += 1
main_layout.addLayout(patterns_grid)
save_button = QPushButton("Save and Continue")
save_button.setCursor(Qt.PointingHandCursor)
save_button.setStyleSheet("""
QPushButton {
background-color: green;
color: white;
font-size: 14px;
padding: 10px;
border-radius: 5px;
}
QPushButton:hover {
background-color: #00b300;
}
QPushButton:pressed {
background-color: #008000;
}
""")
save_button.clicked.connect(self.save_preferences_and_open_client_config)
main_layout.addWidget(save_button)
def check_docker_status(self):
try:
subprocess.check_output(['docker', 'info'], stderr=subprocess.STDOUT)
self.docker_status_label.setText("Active")
self.docker_status_label.setStyleSheet("color: green; font-size: 12px;")
except subprocess.CalledProcessError:
self.docker_status_label.setText("Not Active")
self.docker_status_label.setStyleSheet("color: red; font-size: 12px;")
except FileNotFoundError:
self.docker_status_label.setText("Not Installed")
self.docker_status_label.setStyleSheet("color: red; font-size: 12px;")
def update_docker_status(self):
self.check_docker_status()
def on_back(self):
self.close()
self.home_page_callback()
def show_pattern_info(self, pattern_name, pattern_category, image_path, description, benefits, drawbacks):
dialog = QDialog(self)
dialog.setWindowTitle(f"{pattern_name} - {pattern_category}")
dialog.resize(500, 400)
layout = QVBoxLayout(dialog)
layout.setAlignment(Qt.AlignTop)
title_label = QLabel(f"{pattern_name}")
title_label.setStyleSheet("color: black; font-size: 16px; font-weight: bold; margin-bottom: 10px;")
layout.addWidget(title_label, alignment=Qt.AlignCenter)
base_dir = os.path.dirname(os.path.abspath(__file__))
full_path = os.path.join(base_dir, image_path)
image_label = QLabel()
if os.path.exists(full_path):
pixmap = QPixmap(full_path)
pixmap = pixmap.scaled(200, 200, Qt.KeepAspectRatio, Qt.SmoothTransformation)
image_label.setPixmap(pixmap)
image_label.setAlignment(Qt.AlignCenter)
else:
image_label.setText("Architectural Pattern not Implemented!")
image_label.setStyleSheet("color: red;")
image_label.setAlignment(Qt.AlignCenter)
layout.addWidget(image_label)
desc_label = QLabel(description)
desc_label.setWordWrap(True)
desc_label.setStyleSheet("color: black; font-size: 13px; margin-top: 5px;")
layout.addWidget(desc_label)
benefits_label = QLabel(f"Benefits: {benefits}")
benefits_label.setWordWrap(True)
benefits_label.setStyleSheet("color: green; font-size: 12px; margin-top: 10px;")
layout.addWidget(benefits_label)
drawbacks_label = QLabel(f"Drawbacks: {drawbacks}")
drawbacks_label.setWordWrap(True)
drawbacks_label.setStyleSheet("color: red; font-size: 12px; margin-top: 5px;")
layout.addWidget(drawbacks_label)
button_box = QDialogButtonBox(QDialogButtonBox.Close)
button_box.setCursor(Qt.PointingHandCursor)
button_box.setStyleSheet("""
QPushButton {
background-color: green;
color: white;
font-size: 10px;
padding: 8px 16px;
border-radius: 5px;
text-align: left;
}
QPushButton:hover {
background-color: #e0a800;
}
QPushButton:pressed {
background-color: #c69500;
}
""")
button_box.rejected.connect(dialog.reject)
layout.addWidget(button_box, alignment=Qt.AlignCenter)
dialog.exec_()
def save_preferences_and_open_client_config(self):
config_needed_patterns = ["Client Selector", "Client Cluster", "Multi-Task Model Trainer"]
for p_name in config_needed_patterns:
if p_name in self.pattern_checkboxes and self.pattern_checkboxes[p_name].isChecked():
if p_name not in self.temp_pattern_config or not self.temp_pattern_config[p_name]["params"]:
msg_box = QMessageBox(self)
msg_box.setWindowTitle("Configuration Needed")
msg_box.setIcon(QMessageBox.Warning)
msg_box.setText(f"Please configure '{p_name}' before continuing.")
ok_button = msg_box.addButton("OK", QMessageBox.AcceptRole)
ok_button.setCursor(Qt.PointingHandCursor)
ok_button.setStyleSheet("""
QPushButton {
background-color: green;
color: white;
font-size: 10px;
padding: 8px 16px;
border-radius: 5px;
text-align: left;
}
QPushButton:hover {
background-color: #e0a800;
}
QPushButton:pressed {
background-color: #c69500;
}
""")
msg_box.exec_()
return
patterns_data = {}
relevant_patterns = [
"Client Registry",
"Client Selector",
"Client Cluster",
"Message Compressor",
"Model co-Versioning Registry",
"Multi-Task Model Trainer",
"Heterogeneous Data Handler",
]
for pat_name in relevant_patterns:
cb_checked = (self.pattern_checkboxes[pat_name].isChecked()
if pat_name in self.pattern_checkboxes else False)
if pat_name in self.temp_pattern_config:
existing = self.temp_pattern_config[pat_name]
existing["enabled"] = cb_checked
patterns_data[pat_name.lower().replace(" ", "_")] = existing
else:
patterns_data[pat_name.lower().replace(" ", "_")] = {
"enabled": cb_checked,
"params": {}
}
simulation_config = {
"simulation_type": self.sim_type_combo.currentText(),
"rounds": self.rounds_input.value(),
"clients": self.clients_input.value(),
"clients_per_round": min(self.clients_per_round_input.value(), self.clients_input.value()),
"adaptation": self.adaptation_combo.currentText(),
"LLM": self.llm_combo.currentText(),