π Dapy: Simulating Distributed Algorithms in Python
Dapy is a lightweight Python framework for prototyping, simulating, and visualizing distributed algorithms in a controlled environment. Perfect for education, research, and experimentation with distributed computing concepts.
What is Dapy?
Dapy provides:
- Simple Algorithm Definition: Specify algorithms using a clean, intuitive API
- Simulation Engine: Execute algorithms in a deterministic, repeatable environment
- Execution Traces: Detailed logs of all events (sends, receives, local operations)
- Visual Debugging: Dapyview GUI for interactive visualization of traces with time-space diagrams
Whether youβre teaching distributed computing or exploring new algorithms, Dapy streamlines the prototyping process.
Two Components
Dapy is split into two independent parts:
- dapy library - The core framework for defining and simulating algorithms.
- dapyview - An optional GUI trace viewer for visualizing execution traces.
π― Quick Start
Installation
Dapy is currently under active development and not yet published on PyPI.
Recommended: Use the Template Repository
The fastest way to get started is using our project template:
- Get the template:
- Download the template or copy it from the dapy repository
- It includes pre-configured project structure, example algorithm, and ready-to-use setup
- Install dependencies:
cd my-algorithm-project uv sync - Run the example:
uv run run-bcast dapyview # Opens file selector, or: dapyview traces/broadcast_trace.pkl
See the template README for complete instructions.
Alternative: Install dapy as a dependency
For existing projects, install dapy directly from GitHub:
# Using uv (recommended)
uv add "dapy @ git+https://github.com/xdefago/dapy.git"
# Or using pip
pip install "git+https://github.com/xdefago/dapy.git"
This installs:
- The
dapylibrary for writing and simulating distributed algorithms - The
dapyviewGUI viewer (included automatically)
For dapy developers who want to modify dapy itself:
See the Developer Documentation for setup with editable install.
Your First Algorithm
from dapy.core import Algorithm, State, Message, Pid
from dataclasses import dataclass
@dataclass(frozen=True)
class MyState(State):
received: bool = False
class SimpleAlgorithm(Algorithm):
def get_initial_state(self, pid: Pid, **kwargs) -> MyState:
return MyState(received=False)
def on_init(self, state, pid, topology, message_pool):
if pid == 0:
message_pool.add_message(message=str("hello"), sender=0, receiver=1)
def on_message(self, state, msg, sender):
return state.__class__(received=True)
Visualize Your Trace
- Run your algorithm and save a trace
- Open the trace with Dapyview:
dapyview # Opens file selector dapyview trace.pkl # Opens specific file - Explore message flows, causality relationships, and timing
π Documentation
For Users
- Dapyview User Guide - Complete guide to the GUI trace viewer
- Installation and setup
- User interface tutorial
- Color scheme explanation
- Tips and best practices
For Developers
- Sample Algorithm - Learn how to define an algorithm
- State definition
- Message and signal types
- Algorithm implementation
- Sample Execution - Learn how to run simulations
- Setting up topologies
- Running executions
- Saving and loading traces
- API Reference - Complete API documentation
- Generated from source code docstrings
- All public classes and functions
π¨ Dapyview: Visual Trace Viewer
Dapyview is an interactive GUI for visualizing execution traces of distributed algorithms.
Key Features
- Time-Space Diagrams: Visualize process timelines and message exchanges
- Dual Clock System: Switch between physical time and logical (Lamport) time
- Causality Highlighting: Click events to highlight causal past/future
- Interactive Controls: Zoom, pan, add measurement rulers
- Minimap: Overview widget for large traces
Getting Started with Dapyview
# Run dapyview with a trace file
dapyview examples/sample_trace.json
# Or start without a file (open via menu)
dapyview
See the Dapyview User Guide for detailed documentation.
ποΈ Project Structure
dapy/
βββ src/
β βββ dapy/ # Main framework
β β βββ core/ # Core abstractions (Algorithm, State, Message, etc.)
β β βββ sim/ # Simulation engine
β β βββ algo/ # Example algorithms
β βββ dapyview/ # GUI trace viewer (optional)
βββ examples/ # Example algorithms and traces
βββ tests/ # Test suite
βββ docs/ # This documentation
βββ pyproject.toml # Project configuration
π Features at a Glance
| Feature | Description |
|---|---|
| Algorithm Abstraction | Simple API for defining distributed algorithms |
| Deterministic Simulation | Repeatable execution for consistent debugging |
| Message Traces | Complete records of all communication and events |
| Causality Analysis | Vector clock-based causal relationships |
| Interactive Visualization | Dapyview GUI with time-space diagrams |
| Educational Focus | Designed for teaching distributed computing |
π‘ Use Cases
- Education: Teach distributed algorithms in a hands-on, visual way
- Research: Prototype and test new algorithm designs
- Experimentation: Explore algorithm behavior under different conditions
- Visualization: Understand complex message flows and timing
π More Information
- Homepage: GitHub Repository
- License: MIT
π€ Contributing
Interested in contributing? We welcome:
- Bug reports and feature requests
- Documentation improvements
- Algorithm examples
- Performance enhancements
Check the repository for contribution guidelines.
Start simulating your distributed algorithms today!