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

refactor(framework) Remove num-supernodes requirement from simulation exec plugin #4486

Merged
merged 5 commits into from
Nov 13, 2024
Merged
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
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