Skip to content

Commit

Permalink
Merge pull request #335 from leondavi/removeWorker
Browse files Browse the repository at this point in the history
Remove worker
  • Loading branch information
leondavi authored May 17, 2024
2 parents a7797f1 + b3d32fc commit 14febf3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"d8df752e0a2e8f01de8f66e9cec941cdbc65d144ecf90ab7713e69d65e7e82aa": {
"modelType": "0",
"_doc_modelType": " nn:0 | approximation:1 | classification:2 | forecasting:3 | image-classification:4 | text-classification:5 | text-generation:6 | auto-association:7 | autoencoder:8 | ae-classifier:9 |",
"modelArgs": "",
"layersSizes": "5,10,5,3,3",
"_doc_layersSizes": "List of postive integers [L0, L1, ..., LN]",
"layerTypesList": "1,3,3,3,5",
Expand Down
11 changes: 11 additions & 0 deletions src_py/nerlPlanner/Handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ def workers_handler(window, event, values):
else:
sg.popup_ok(f"Cannot add - Parameters Issue!", keep_on_top=True, title="Adding New Worker Issue")

if event == KEY_WORKERS_BUTTON_REMOVE:
if (worker_name_selection in json_dc_inst.get_workers_dict()):
json_dc_inst.remove_worker(worker_name_selection)
client_of_worker = json_dc_inst.get_client_by_worker(worker_name_selection)
client_of_worker.remove_worker(worker_name_selection)
last_workers_list_state_not_occupied = [x for x in last_workers_list_state if x not in json_dc_inst.get_clients_workers()]
window[KEY_CLIENTS_WORKERS_LIST_COMBO_BOX].update("", last_workers_list_state_not_occupied)
window[KEY_WORKERS_LIST_BOX].update(json_dc_inst.get_workers_names_list())
window[KEY_WORKERS_INFO_BAR].update(f'{worker_name_selection} removed')
else:
sg.popup_ok(f"Cannot remove - Worker not found!", keep_on_top=True, title="Removing Worker Issue")

if event == KEY_WORKERS_LIST_BOX:
if values[KEY_WORKERS_LIST_BOX]:
Expand Down
15 changes: 14 additions & 1 deletion src_py/nerlPlanner/JsonDistributedConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,15 @@ def remove_client(self, client_name : str):
del(self.main_dict[KEY_CLIENTS][client_name])
self.remove_entity_from_device(client_name)


def get_clients_names(self):
return list(self.main_dict[KEY_CLIENTS].keys())

def get_client_by_worker(self, worker_name : str):
for client_inst , client in self.main_dict[KEY_CLIENTS].items():
if worker_name in client.get_workers_names():
return client
return None

def get_owned_workers_by_clients_dict(self) -> list:
owned_workers_dict = {}
for client_name , client in self.main_dict[KEY_CLIENTS].items():
Expand Down Expand Up @@ -283,6 +288,14 @@ def add_worker(self, worker : Worker):
self.main_dict[KEY_MODEL_SHA][worker_sha].append(worker_name)
return True

def remove_worker(self, worker_name : str):
if worker_name in self.get_workers_names_list():
worker_sha = self.main_dict[KEY_WORKERS][worker_name].get_sha()
del self.main_dict[KEY_WORKERS][worker_name]
self.main_dict[KEY_MODEL_SHA][worker_sha].remove(worker_name)
if len(self.main_dict[KEY_MODEL_SHA][worker_sha]) == 0:
del self.main_dict[KEY_MODEL_SHA][worker_sha]

def get_worker(self, worker_name : str) -> Worker:
return self.main_dict[KEY_WORKERS][worker_name]

Expand Down

0 comments on commit 14febf3

Please sign in to comment.