Skip to content

Commit

Permalink
refactor(framework) Remove num-supernodes requirement from simulati…
Browse files Browse the repository at this point in the history
…on exec plugin (#4486)
  • Loading branch information
jafermarq authored Nov 13, 2024
1 parent 6d6f272 commit 34b2bd6
Showing 1 changed file with 8 additions and 45 deletions.
53 changes: 8 additions & 45 deletions src/py/flwr/superexec/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,11 @@


class SimulationEngine(Executor):
"""Simulation engine executor.
Parameters
----------
num_supernodes: Opitonal[str] (default: None)
Total number of nodes to involve in the simulation.
"""
"""Simulation engine executor."""

def __init__(
self,
num_supernodes: Optional[int] = None,
verbose: Optional[bool] = False,
) -> None:
self.num_supernodes = num_supernodes
self.verbose = verbose
self.linkstate_factory: Optional[LinkStateFactory] = None
self.ffs_factory: Optional[FfsFactory] = None

Expand Down Expand Up @@ -78,40 +68,7 @@ def set_config(
self,
config: UserConfig,
) -> None:
"""Set executor config arguments.
Parameters
----------
config : UserConfig
A dictionary for configuration values.
Supported configuration key/value pairs:
- "num-supernodes": int
Number of nodes to register for the simulation.
- "verbose": bool
Set verbosity of logs.
"""
if num_supernodes := config.get("num-supernodes"):
if not isinstance(num_supernodes, int):
raise ValueError("The `num-supernodes` value should be of type `int`.")
self.num_supernodes = num_supernodes
elif self.num_supernodes is None:
log(
ERROR,
"To start a run with the simulation plugin, please specify "
"the number of SuperNodes. This can be done by using the "
"`--executor-config` argument when launching the SuperExec.",
)
raise ValueError(
"`num-supernodes` must not be `None`, it must be a valid "
"positive integer."
)

if verbose := config.get("verbose"):
if not isinstance(verbose, bool):
raise ValueError(
"The `verbose` value must be a string `true` or `false`."
)
self.verbose = verbose
"""Set executor config arguments."""

# pylint: disable=too-many-locals
@override
Expand All @@ -123,6 +80,12 @@ def start_run(
) -> Optional[int]:
"""Start run using the Flower Simulation Engine."""
try:
# Check that num-supernodes is set
if "num-supernodes" not in federation_options:
raise ValueError(
"Federation options doesn't contain key `num-supernodes`."
)

# Create run
fab = Fab(hashlib.sha256(fab_file).hexdigest(), fab_file)
fab_hash = self.ffs.put(fab.content, {})
Expand Down

0 comments on commit 34b2bd6

Please sign in to comment.