Overview
Local simulation provides two execution modes:- Flower Simulation Engine: Run federated learning with the
flwr runcommand - Jupyter Notebooks: Interactive notebooks simulating multiple parties in a local SyftBox network
Benefits of Local Simulation
- Rapid Development: Test changes instantly without network delays
- Easy Debugging: All logs and data in one place
- Cost Effective: No need for multiple machines or cloud resources
- Learning Tool: Understand federated workflows by switching between party roles
- Reproducible: Consistent environment for testing and validation
Getting Started
Prerequisites
- Python >= 3.12
- uv package manager (or pip)
- Jupyter (for notebook-based simulation)
Choose Your Example
All Syft-Flwr examples support local simulation:Diabetes Prediction
Federated learning for binary classification
Federated Analytics
Privacy-preserving data analysis
FedRAG
Federated document retrieval for LLMs
Method 1: Flower Simulation Engine
The fastest way to run federated learning locally.Setup
- Clone an example project:
- Install dependencies:
- Run the simulation:
What Happens
Theflwr run command:
- Reads configuration from
pyproject.toml - Starts a virtual server (aggregator)
- Spawns multiple virtual clients (supernodes) in separate processes
- Runs the complete federated learning workflow
- Saves results to the local filesystem
Configuration
Editpyproject.toml to control the simulation:
num-supernodes: How many data owners to simulate (default: 2)num-server-rounds: How many federated learning rounds to run (default: 2)partition-id/num-partitions: Data partitioning configuration
Example Output
Method 2: Jupyter Notebooks
Interactive simulation with full visibility into each party’s perspective.Setup
- Clone an example project (same as above)
- Install dependencies:
- Start Jupyter:
Workflow
Each example includes notebooks in thelocal/ directory:
Step-by-Step Execution
Step 1: Data Owner 1 (local/do1.ipynb)
- Open
local/do1.ipynb - Run cells to:
- Set up local SyftBox datasite
- Load partition 0 of the dataset
- Initialize the Flower client
- Wait for jobs from data scientist
Step 2: Data Owner 2 (local/do2.ipynb)
- Open
local/do2.ipynbin a new browser tab - Run cells to:
- Set up second local datasite
- Load partition 1 of the dataset
- Initialize second Flower client
- Wait for jobs
Step 3: Data Scientist (local/ds.ipynb)
- Open
local/ds.ipynbin another browser tab - Run cells to:
- Connect to local SyftBox network
- Discover data owners
- Submit federated learning jobs
- Run aggregation server
- Collect results
Step 4: Approve Jobs (Back to Data Owners)
Switch back todo1.ipynb and do2.ipynb:
Step 5: Run Aggregation (Back to Data Scientist)
Switch back tods.ipynb:
Switching Between Notebooks
The notebooks include clear instructions about when to switch:Local SyftBox Network
Both simulation methods create a local SyftBox network:Directory Structure
Each participant gets their own datasite:Communication
Local communication happens through:- File System: Datasites write job requests and results to local directories
- Process Signals: Flower simulation uses inter-process communication
- Network Loopback: SyftBox client can use
localhostfor testing
Comparing Simulation Methods
| Feature | Flower Simulation | Jupyter Notebooks |
|---|---|---|
| Speed | Faster (automated) | Slower (manual steps) |
| Visibility | Server logs only | Full party visibility |
| Interactivity | Command-line | Rich notebook output |
| Learning | Quick testing | Deep understanding |
| Debugging | Standard logs | Interactive debugging |
| Customization | Config file | Live code changes |
Common Use Cases
Development and Testing
Algorithm Experimentation
Modify the aggregation strategy inserver_app.py:
Data Partitioning Experiments
Test different data distributions:Integration Testing
Validate the complete workflow before distributed deployment:- Run local simulation
- Verify outputs and metrics
- Test edge cases (client failures, unbalanced data)
- Confirm privacy properties (no data leakage)
Scaling Up
Simulate larger federations:Resource Configuration
Allocate resources per client:Transitioning to Distributed
Once your local simulation works, deploy to real distributed environments:Google Colab
Zero-setup distributed deployment using Google Colab notebooks.
SyftBox Network
Production deployment across real distributed nodes.
Troubleshooting
Issue: Port Already in Use
Issue: Out of Memory
Solution: Reduce number of supernodes or batch size:Issue: Data Not Found
Solution: Ensure datasets are downloaded:Next Steps
Try Diabetes Prediction
Run your first federated learning simulation.
Explore Federated Analytics
Simulate privacy-preserving data analysis.
Deploy to Google Colab
Move from local to distributed with zero setup.
SyftBox Deployment
Deploy to production distributed network.