Overview
Therun function executes a bootstrapped Syft-Flwr project in simulation mode, allowing you to test your federated learning workflow locally using mock datasets before deploying to real datasites.
Function Signature
Parameters
Path to the bootstrapped Syft-Flwr project directory. Must contain
main.py and pyproject.toml.List of paths to mock datasets for each datasite. The number of paths must match the number of datasites configured during bootstrap.
Returns
Returns
True if simulation succeeded, False otherwise. Used when running in scripts or standard Python environments.Returns a task handle if running in an async environment (e.g., Jupyter). Callers can await this task.
What It Does
- Validates the project - Ensures the project was bootstrapped correctly
- Sets up mock RDS clients - Creates simulated SyftBox network in a temporary directory
- Bootstraps encryption keys - Generates E2E encryption keys for all participants (if enabled)
- Runs simulation - Executes server and client code concurrently:
- DS (Data Scientist) runs the server/aggregator code
- Each DO (Data Owner) runs client code on their mock dataset
- Collects logs - Saves execution logs to
{project_dir}/simulation_logs/ - Cleans up - Removes temporary network directory and encryption keys
Usage Example
Fromnotebooks/fl-diabetes-prediction/local/ds.ipynb:323-326:
Simulation Logs
Logs for each participant are saved to:Environment Variables
Set to
"false" to disable end-to-end encryption during simulation.Set to
"true" to skip module validation (useful for parallel testing).Automatically set for each client to point to their mock dataset path.
Automatically set for each client to point to their simulated config.
Execution Flow
Exceptions
FileNotFoundError
Raised if project directory,
main.py, or pyproject.toml doesn’t exist.NotADirectoryError
Raised if the project path is not a directory.
ValueError
Raised if any mock dataset path doesn’t exist.
Notes
- Simulation runs in a temporary directory under
/tmp/{project_name} - The server task completes first, then client tasks are automatically cancelled
- All temporary files and encryption keys are cleaned up after simulation
- In Jupyter environments, the function returns a task that can be awaited
- DS logs are printed to stdout after the server completes