Skip to content
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 serial num of msg #546

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions federatedscope/core/fed_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self,
config.ready_for_run()
self.cfg = config
self.client_cfgs = client_configs
self.serial_num_for_msg = 0

self.mode = self.cfg.federate.mode.lower()
self.gpu_manager = GPUManager(gpu_available=self.cfg.use_gpu,
Expand Down Expand Up @@ -471,6 +472,8 @@ def _run_simulation(self):
# For the server, move the received message to a
# cache for reordering the messages according to
# the timestamps
msg.serial_num = self.serial_num_for_msg
self.serial_num_for_msg += 1
heapq.heappush(server_msg_cache, msg)
else:
self._handle_msg(msg)
Expand Down
8 changes: 6 additions & 2 deletions federatedscope/core/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ def __init__(self,
state=0,
content='None',
timestamp=0,
strategy=None):
strategy=None,
serial_num=0):
self._msg_type = msg_type
self._sender = sender
self._receiver = receiver
self._state = state
self._content = content
self._timestamp = timestamp
self._strategy = strategy
self.serial_num = serial_num

@property
def msg_type(self):
Expand Down Expand Up @@ -93,8 +95,10 @@ def strategy(self, value):
def __lt__(self, other):
if self.timestamp != other.timestamp:
return self.timestamp < other.timestamp
else:
elif self.state != other.state:
return self.state < other.state
else:
return self.serial_num < other.serial_num

def transform_to_list(self, x):
if isinstance(x, list) or isinstance(x, tuple):
Expand Down