How oskarcarl/btfl-simulator works
Purpose and execution
This repository simulates and evaluates gossip-based machine learning organized with BitTorrent-like peer exchanges. It is a Python batch simulator, not a network service. The primary entry point is main.py, which runs one or more experiment “plays” defined as CSV inputs such as evaluation/scenario_1.csv.
Experiment orchestration
main.py accepts simulation hyperparameters and play files, then coordinates a run and writes timestamped logs/done markers. Play definitions describe the experiment workload and are supplied from plays/ or evaluation/.
Paths: main.py, simulator/play.py, evaluation/scenario_1.csv
Simulation model and dataset layer
The simulator package owns global configuration, dataset handling, the learning/model representation, and run-level statistics. This is the boundary between experiment definitions and peer behavior: plays are interpreted into model-training/evaluation work, while statistics capture outcomes for logs and later analysis.
Paths: simulator/config.py, simulator/dataset.py, simulator/model.py, simulator/statistics.py
Peer learning and gossip behavior
Each simulated participant is represented by the peer subsystem. It maintains peer-specific structures and decides which model or neighbor to select, including randomized ordering for equal model ages. This is the core policy boundary for alternate gossip/BitTorrent strategies.
Paths: peer/peer.py, peer/pick_strategy.py, peer/structs.py
Swarm tracking and coordination
The tracker subsystem models swarm-level knowledge and peer coordination. It mediates the view of available peers/models used by individual peer selection, separating decentralized peer logic from shared simulation tracking.
Paths: tracker/tracker.py, tracker/swarm.py
Data/control flow
A run flows from CSV play input into main.py, which initializes simulator configuration, datasets, model state, peer/swarm state, and repeatedly executes play actions. Peers train or retrain models, exchange/select model information through tracker-managed swarm state, and report measurements to simulator statistics. Results are emitted as log CSV-compatible data for comparison against reference runs.
Paths: main.py, simulator/play.py, peer/peer.py, tracker/tracker.py
Evaluation and analysis
Reference and scenario CSVs under evaluation/ preserve paper experiment inputs/results. scripts/scatterplot.py compares a scenario log with a reference log, calculates statistics, and generates PDF/interactive visual analysis. Dataset/play generation and topology exploration are separate offline scripts.
Paths: scripts/scatterplot.py, scripts/generator.py, scripts/islands.py
Runtime and infrastructure
The runtime is Python with dependencies declared in pyproject.toml and requirements.txt; analysis uses NumPy and Matplotlib. The Makefile provides Docker-backed CPU/GPU batch execution and environment setup. No external online service is indicated; BitTorrent is a simulated organizational model rather than a required network dependency.
Paths: Makefile, pyproject.toml, requirements.txt
Main entry points: peer.py Simulated peer · main.py Batch entry point · play.py Play interpreter · scenario_1.csv Scenario CSV
Components 18
Experiment Runs
- Scenario CSV · Defines an evaluation workload.
evaluation/scenario_1.csv - Batch entry point · Runs one or more simulation plays.
main.py - Play interpreter
simulator/play.py - Run logs · Timestamped measurements and completion markers.
Simulation Core
- Global config
simulator/config.py - Dataset layer
simulator/dataset.py - Learning model · Represents training and evaluation state.
simulator/model.py - Run statistics · Captures outcomes for logs and comparison.
simulator/statistics.py
Peer and Swarm
- Simulated peer · Trains, retrains, and exchanges model information.
peer/peer.py - Selection policy · Chooses models or neighbors, including equal-age ordering.
peer/pick_strategy.py - Peer state structures
peer/structs.py - Tracker · Mediates shared peer and model visibility.
tracker/tracker.py - Swarm state
tracker/swarm.py
Evaluation and Tooling
- Scenario comparison · Compares logs with references and produces visual output.
scripts/scatterplot.py - Dataset/play generator
scripts/generator.py - Topology explorer
scripts/islands.py - Python environment · Provides simulator and NumPy/Matplotlib analysis dependencies.
pyproject.toml - Docker batch runner · Provides CPU/GPU batch execution and setup.
Makefile
Connections 21
- Scenario CSV → Batch entry point: supplies play
- Batch entry point → Play interpreter: executes
- Batch entry point → Global config: initializes
- Play interpreter → Dataset layer: requests workload data
- Play interpreter → Simulated peer: drives actions
- Dataset layer → Learning model: provides training data
- Simulated peer → Learning model: trains or retrains
- Simulated peer → Selection policy: uses
- Simulated peer → Peer state structures: maintains
- Simulated peer → Tracker: queries and reports
- Selection policy → Tracker: uses swarm view
- Tracker → Swarm state: manages
- Simulated peer → Run statistics: reports measurements
- Run statistics → Run logs: emits
- Run logs → Scenario comparison: scenario log
- Scenario CSV → Scenario comparison: reference/scenario input
- Dataset/play generator → Scenario CSV: can generate plays
- Topology explorer → Swarm state: explores topology
- Docker batch runner → Batch entry point: runs batches
- Python environment → Batch entry point: provides runtime
- Python environment → Scenario comparison: provides analysis libraries