Aggregate computing for Python
Program the collective, not the device¶
phyelds is a lightweight, Pythonic toolkit for aggregate computing. You write one function for a whole collective (a swarm of robots, a sensor network, a fleet of devices) and every device runs it in asynchronous rounds, exchanging values only with its immediate neighbors.
pip install phyelds
Python 3.12 or later. To run programs in simulation, see the simulator.

In the playground, a distance gradient repairs itself as its source is dragged across the network.
Why phyelds¶
-
One program, a whole collective
Describe the global behavior once, as a Python function: every device runs the same code on its own sensors and its neighbors' messages.
-
Self-healing by construction
Every round recomputes the field from fresh inputs, so it repairs itself when devices move, fail or join.
-
Just Python
Ordinary functions, loops, dictionaries and dataclasses:
@aggregatekeeps the messages of the devices aligned. -
Extensive standard library
Ready-made building blocks for information propagation, data aggregation, consensus, leader election, collective processes, and time-based reactive logic.
A taste of phyelds¶
from phyelds.calculus import aggregate, exchange
@aggregate
def hop_gradient(source: bool) -> float:
_, distances, send_distance = exchange(float("inf"))
through_neighbors = distances + 1
nearest = min(through_neighbors.exclude_self().values(), default=float("inf"))
return send_distance(0 if source else nearest)

Every device runs these four lines: it exchanges its distance estimate with its neighbors, and keeps the smallest neighbor estimate plus one hop. Together, the devices compute how many hops separate each of them from the nearest source (above, on a line of ten devices), and they recompute it when sources move or links change.
The tutorial builds it step by step; the animation at the top is the
library version, distance_to, with real distances.
Learning path¶
Start here, in order: each step builds on the previous one. The 3D walkthrough is apart, on its own full-screen page.
-
Fields, rounds (Sense → Compute → Act), and the local and global reading of a program.
-
Build the gradient from scratch, watch it self-heal, and compose blocks into a channel.
-
Write a program and watch it run on a network in 3D, in your browser: watch any expression on every device.
-
Apart, full screen: a field, neighbors, a gradient, a channel and a branch, round by round, in 3D.
Then go deeper:
-
remember,neighborsandexchange, alignment with@aggregate, and the common pitfalls. -
Spreading, collection and gossip, leader election and processes, time and logic.
-
Experiments with animations and CSV export, VMAS, and your own runtime.
-
Every module, function and class, generated from the docstrings.
Heritage & acknowledgments¶
phyelds builds upon over a decade of research and open-source tools in spatial and aggregate computing, bringing ideas from Proto, Protelis, ScaFi, FCPP, and Collektive into a pragmatic, Python-native library.
- Main contributors: Gianluca Aguzzi and Davide Domini.
- Acknowledgments: special thanks to Mirko Viroli, Ferruccio Damiani, Danilo Pianini, Roberto Casadei, and Giorgio Audrito for the insightful discussions and foundational work that made this project possible.