-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add checks for completeness of msg_handler #388
Changes from 4 commits
cec7651
fbbc37a
0cc6169
1eb8b24
ac1f816
53330d3
e48ae8d
66155eb
7df38c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,10 @@ def __init__(self, | |
self.resource_info = get_resource_info( | ||
config.federate.resource_info_file) | ||
|
||
# Check the completeness of msg_handler. | ||
self.check() | ||
|
||
def setup(self): | ||
if self.mode == 'standalone': | ||
self.shared_comm_queue = deque() | ||
self._setup_for_standalone() | ||
|
@@ -184,6 +188,7 @@ def run(self): | |
For the standalone mode, a shared message queue will be set up to | ||
simulate ``receiving message``. | ||
""" | ||
self.setup() | ||
if self.mode == 'standalone': | ||
# trigger the FL course | ||
for each_client in self.client: | ||
|
@@ -427,3 +432,62 @@ def _handle_msg(self, msg, rcv=-1): | |
self.client[each_receiver].msg_handlers[msg.msg_type](msg) | ||
self.client[each_receiver]._monitor.track_download_bytes( | ||
download_bytes) | ||
|
||
def check(self): | ||
""" | ||
Check the completeness of Server and Client. | ||
|
||
Returns: | ||
|
||
""" | ||
if self.cfg.check_completeness: | ||
try: | ||
import os | ||
import networkx as nx | ||
import matplotlib.pyplot as plt | ||
# Build check graph | ||
G = nx.DiGraph() | ||
flags = {0: 'Client', 1: 'Server'} | ||
msg_handler_dicts = [ | ||
self.client_class.get_msg_handler_dict(), | ||
self.server_class.get_msg_handler_dict() | ||
] | ||
for flag, msg_handler_dict in zip(flags.keys(), | ||
msg_handler_dicts): | ||
role, oppo = flags[flag], flags[(flag + 1) % 2] | ||
for msg_in, (handler, msgs_out) in \ | ||
msg_handler_dict.items(): | ||
for msg_out in msgs_out: | ||
msg_in_key = f'{oppo}_{msg_in}' | ||
handler_key = f'{role}_{handler}' | ||
msg_out_key = f'{role}_{msg_out}' | ||
G.add_node(msg_in_key, subset=1) | ||
G.add_node(handler_key, subset=0 if flag else 2) | ||
G.add_node(msg_out_key, subset=1) | ||
G.add_edge(msg_in_key, handler_key) | ||
G.add_edge(handler_key, msg_out_key) | ||
pos = nx.multipartite_layout(G) | ||
plt.figure(figsize=(20, 15)) | ||
nx.draw(G, | ||
pos, | ||
with_labels=True, | ||
node_color='white', | ||
node_size=800) | ||
fig_path = os.path.join(self.cfg.outdir, 'msg_handler.png') | ||
plt.savefig(fig_path) | ||
if nx.has_path(G, 'Client_join_in', 'Server_finish'): | ||
if nx.is_weakly_connected(G): | ||
logger.info(f'Completeness check passes! Save check ' | ||
f'results in {fig_path}.') | ||
else: | ||
logger.warning( | ||
f'Completeness check raises warning for ' | ||
f'some handlers not in FL process! Save ' | ||
f'check results in {fig_path}.') | ||
else: | ||
logger.error(f'Completeness check fails for there is no' | ||
f'path from `join_in` to `finish`! Save ' | ||
f'check results in {fig_path}.') | ||
except Exception as error: | ||
logger.warning(f'Completeness check failed for {error}!') | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the reason is that we cannot say yes or not about the correctness/completeness, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the document shows, the correctness/completeness checks only check the message-handler pairs and raise three types of logs (info, warning, and error). If something goes wrong with Python code, we'd better keep the exception stack as it is. So the return value is meaningless. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is necessary to indent such a huge block of code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update accordingly.