Skip to content

phyelds

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.

A distance gradient, in 3D, repairing itself as its source is dragged across the network A distance gradient, in 3D, repairing itself as its source is dragged across the network

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: @aggregate keeps 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)

The hop-count gradient spreading along a line of ten devices The hop-count gradient spreading along a line of ten devices

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.

  • 1. Thinking in fields


    Fields, rounds (Sense → Compute → Act), and the local and global reading of a program.

  • 2. Step-by-step tutorial


    Build the gradient from scratch, watch it self-heal, and compose blocks into a channel.

  • 3. Browser playground


    Write a program and watch it run on a network in 3D, in your browser: watch any expression on every device.

  • Interactive 3D walkthrough


    Apart, full screen: a field, neighbors, a gradient, a channel and a branch, round by round, in 3D.

Then go deeper:

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.