Skip to content

Commit

Permalink
Unify ID generation (#2313)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljanes authored Sep 7, 2023
1 parent 3db7849 commit 7eee251
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/source/ref-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- **General updates to baselines** ([#2301](https:/adap/flower/pull/2301).[#2305](https:/adap/flower/pull/2305), [#2307](https:/adap/flower/pull/2307))

- **General improvements** ([#2309](https:/adap/flower/pull/2309), [#2310](https:/adap/flower/pull/2310))
- **General improvements** ([#2309](https:/adap/flower/pull/2309), [#2310](https:/adap/flower/pull/2310), [2313](https:/adap/flower/pull/2313))

Flower received many improvements under the hood, too many to list here.

Expand Down
6 changes: 4 additions & 2 deletions src/py/flwr/server/state/in_memory_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""In-memory State implementation."""


import os
import random
from datetime import datetime, timedelta
from logging import ERROR
from typing import Dict, List, Optional, Set
Expand Down Expand Up @@ -209,7 +209,9 @@ def get_nodes(self, workload_id: str) -> Set[int]:
def create_workload(self) -> str:
"""Create one workload."""
# String representation of random integer from 0 to 9223372036854775807
workload_id = str(int.from_bytes(os.urandom(8), "little") >> 1)
random_workload_id: int = random.randrange(9223372036854775808)
workload_id = str(random_workload_id)

if workload_id not in self.workload_ids:
self.workload_ids.add(workload_id)
return workload_id
Expand Down
6 changes: 4 additions & 2 deletions src/py/flwr/server/state/sqlite_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""SQLite based implemenation of server state."""


import os
import random
import re
import sqlite3
from datetime import datetime, timedelta
Expand Down Expand Up @@ -501,7 +501,9 @@ def get_nodes(self, workload_id: str) -> Set[int]:
def create_workload(self) -> str:
"""Create one workload and store it in state."""
# String representation of random integer from 0 to 9223372036854775807
workload_id = str(int.from_bytes(os.urandom(8), "little") >> 1)
random_workload_id: int = random.randrange(9223372036854775808)
workload_id = str(random_workload_id)

# Check conflicts
query = "SELECT COUNT(*) FROM workload WHERE workload_id = ?;"
# If workload_id does not exist
Expand Down

0 comments on commit 7eee251

Please sign in to comment.