Skip to main content

Phyelds

Lightweight, pythonic aggregate computing & field calculus toolkit for building, simulating, and experimenting with decentralized adaptive systems.

PyPI version Python versions License Last commit


Table of Contents


Why phyelds?

You write one program describing global behaviour; all devices run it, exchanging only neighbor information. The library stays minimal so you can read the code and experiment quickly.

Features

  • Core primitives: @aggregate, remember, neighbors.
  • NeighborhoodField abstraction (arithmetic & iteration) for neighbor values.
  • Pluggable discrete‑event simulator for experiments.
  • Extra libraries (spreading, collection, gossip, leader election) built on the same core.

Installation

pip install phyelds        # from PyPI
# or
poetry add phyelds

VMAS support is provided by a separate package:

pip install phyelds-vmas

Use the generic simulator from phyelds.simulator and VMAS integration from phyelds.vmas:

from phyelds.simulator import Simulator
from phyelds.simulator.runner import schedule_program_for_all
from phyelds.vmas import VmasEnvironment, vmas_runner

From source:

git clone https://github.com/phyelds/phyelds.git
cd phyelds
pip install -e .

Requires Python 3.12+ (see pyproject.toml).

Core Concepts

Phyelds is rooted in the aggregate computing paradigm, where the main idea is based on the concept of computational fields: a distributed data structure representing values spread over space and time. This data cannot be directly manipulated from a single device, but is instead constructed through local interactions and repeated interpretation of the same program by all devices in the system.

For more details, please refer to the main paper on aggregate computing.

Most current incarnations of aggregate computing follow a functional programming style, where the operators are stateless and side-effect free. Phyelds tries to be more pragmatic and Pythonic, allowing some controlled mutability and side effects while still keeping the core ideas of aggregate computing.

Main Ideas

To build spatio-temporal (global) programs in Phyelds, you only need a few simple ideas:

Any function can be marked as part of the aggregate computation with the @aggregate decorator, which ensures that the temporal and spatial aspects of the computation are handled correctly.

Specifically, local persistent state is managed with remember(...) (similar to what other languages call rep or evolve), and devices exchange values with neighbors to form NeighborhoodFields using neighbors(...).

In the next section, we'll explore these core concepts in more detail with practical examples.

1. Local State (remember)

Since aggregates follow a self-organizing computational model where nodes repeatedly execute the same program, it is often necessary to maintain some local state across rounds of execution. To do so, Phyelds provides the remember primitive, which allows a device to store and update a value that persists across rounds:

from phyelds.calculus import aggregate, remember

@aggregate
def counter():
    # Starts at 0 the first round, then increments each subsequent round
    update_counter, counter_value = remember(0)
    update_counter(counter_value + 1)
    return counter_value

remember(initial_value) returns a tuple:

  1. A function to update the stored value.
  2. The current value stored.

In this example, each device maintains a local counter that increments by 1 on each execution round.

2. Neighborhood Values (neighbors)

Another important aspect of aggregate computing is the ability to interact with neighboring devices. The neighbors(value) primitive allows a device to send a value to its neighbors and receive their values in return. This is a kind of bidirectional communication that forms a NeighborhoodField:

from phyelds.calculus import aggregate, neighbors

@aggregate
def neighbor_sum():
    # Every device advertises the constant 1; result = number of (neighbors + self)
    nbr = neighbors(1)
    return sum(nbr)

Doing so creates a NeighborhoodField containing the values received from all neighboring devices (and itself). Calling sum(nbr) then computes the total number of devices in the neighborhood (including itself).

With fields, you can perform arithmetic operations directly, as they are overloaded to work element-wise. Therefore, you can, for instance, compute the average temperature in the neighborhood by exchanging temperature readings:

from phyelds.calculus import aggregate, neighbors

@aggregate
def average_temperature(current_temp):
    nbr_temps = neighbors(current_temp)
    return sum(nbr_temps) / sum(neighbors(1))

3. Combining State + Neighborhood

The previous operators do not really unlock the full potential of aggregate computing. While exchanging values with neighbors is powerful, combining it with local persistent state allows for more complex and adaptive behaviors—in particular, behaviors that emerge over time and space collectively.

For instance, we can compute the minimum value seen in the neighborhood over time:

from phyelds.calculus import aggregate, remember, neighbors

@aggregate
def min_over_time(value):
    update_min, local_min = remember(value)
    nbr_mins = neighbors(local_min)
    new_min = min(min(nbr_mins), local_min)
    update_min(new_min)
    return local_min

Each device keeps track of the minimum value it has seen so far (local_min), exchanges this value with its neighbors (nbr_mins), and updates its local minimum if a smaller value is found in the neighborhood. This way, over time, the minimum value propagates through the network of devices.

Therefore, the function min_over_time(value) has a global interpretation: it creates a spatio-temporal field where each device eventually converges to the minimum value present in the entire network, despite only having local interactions and state.

This is the essence of aggregate computing: reasoning about global functions without considering the transient local states and interactions of individual devices.

Development

git clone https://github.com/phyelds/phyelds.git
cd phyelds
poetry install
poetry run pytest
poetry run pylint src/

Contributing

  1. Open an issue for non‑trivial changes.
  2. Keep PRs focused with tests.
  3. Run linters & tests before submitting.

License

Apache License 2.0 – see LICENSE.


Running a Minimal Simulation

A runnable example is provided in src/minimal_simulation.py.

Run it:

poetry run python src/minimal_simulation.py

It creates 5 nodes in a line, each advertising 1, and prints how many devices each node sees (neighbors + itself). Interior nodes report 3; endpoints report 2.


Happy field building! ✨

Metadata

Release files for phyelds 7.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phyelds 7.1.0
File Size Uploaded
phyelds-7.1.0.tar.gz 29.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for phyelds 7.1.0
File Interpreter ABI Platform
phyelds-7.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 67.5 kB

Release files / phyelds-7.1.0.tar.gz

Download URL phyelds-7.1.0.tar.gz
Size 29.3 kB
Tags Source
SHA-256 checksum
How to use checksums
451d348008d91c2d37d6defff3cce9c2d973add8c208d836a99444586e567a3b
BLAKE2b-256 checksum
How to use checksums
e5ffba5ea1b5625c9b29f465bc4888080fe2e15fdfffd8ebcbf20f6ac353bf75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.13.14 Linux/6.17.0-1020-azure

Release files / phyelds-7.1.0-py3-none-any.whl

Download URL phyelds-7.1.0-py3-none-any.whl
Size 38.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22d16164e6d20551fd154f61f6e560e3276b7cb3a9cd20967cd6f4c03f6161bd
BLAKE2b-256 checksum
How to use checksums
47726cb15f9868e454e0587a61a50ef19f9f71fdc98e66bc6b1dffc8aceeb9b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.13.14 Linux/6.17.0-1020-azure

Release history Release notifications | RSS feed

7.2.0

2 release files

7.1.8

2 release files

7.1.7

2 release files

7.1.6

2 release files

7.1.5

2 release files

7.1.4

2 release files

7.1.3

2 release files

7.1.2

2 release files

7.1.1

2 release files

This release

7.1.0 This release

2 release files

7.0.0

2 release files

6.0.0

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.3.1

2 release files

4.3.0

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page