Skip to main content

A modular communication failure API for Multi-Agent Reinforcement Learning environments

Project description

failure-api

A modular failure injection API for Multi-Agent Reinforcement Learning (MARL) environments.
Built on top of PettingZoo, this package introduces wrappers that simulate communication failures and observation noise between agents — enabling robust training under partial observability and degraded communication.

Installation

pip install failure-api

Components

Wrappers

Wrapper Purpose
BaseWrapper Provides utility functions such as RNG seeding.
SharedObsWrapper Enables shared observations across agents; used internally.
CommunicationWrapper Dynamically masks agent observations/actions based on failures.
NoiseWrapper Injects noise into shared observations, excluding already masked values.

🔌 Communication Models

Model Description
ProbabilisticModel Drops communication links using Bernoulli sampling with fixed probability.
BaseMarkovModel Models temporally correlated failures with a Markov chain.
DistanceModel Drops communication based on exceeding a distance threshold.
DelayBasedModel Delays messages with probabilistic delivery and expiration.
SignalBasedModel Applies degradation using inverse-square signal loss and random drops.

🎙️ Noise Models

Model Description
GaussianNoiseModel Adds Gaussian noise: X + N(μ, σ²); useful for random sensor noise.
LaplacianNoiseModel Adds Laplacian noise: X + Laplace(μ, b); good for sparse spikes.
CustomNoise Accepts any callable function for custom distortion logic.

All models inherit from the NoiseModel base class and implement .apply().


Example Usage

from pettingzoo.mpe import simple_spread_v3
from failure_api.wrappers import CommunicationWrapper, NoiseWrapper
from failure_api.communication_models import ProbabilisticModel
from failure_api.noise_models import GaussianNoiseModel
from pettingzoo.utils import aec_to_parallel

# Base PettingZoo environment
env = simple_spread_v3.env(N=3, max_cycles=25)
agent_ids = env.possible_agents

# Apply communication failure model
model = ProbabilisticModel(agent_ids, failure_prob=0.3)
env = CommunicationWrapper(env, failure_models=[model])

# Add Gaussian noise to visible observations
env = NoiseWrapper(env, GaussianNoiseModel(std=0.5))

# Convert to parallel API
env = aec_to_parallel(env)

# Run one episode
observations = env.reset(seed=42)
for _ in range(10):
    actions = {agent: env.action_space(agent).sample() for agent in env.agents}
    observations, rewards, terminations, truncations, infos = env.step(actions)
    print("Comm matrix:\n", env.get_communication_state())

Custom Noise Example

from failure_api.noise_models import CustomNoise

def zero_every_other(obs, space=None):
    obs[::2] = 0
    return obs

noise = CustomNoise(noise_fn=zero_every_other)
env = NoiseWrapper(env, noise_model=noise)

Features

  • ✅ Pluggable communication failure and noise models
  • 🔁 Compatible with both AEC and Parallel API in PettingZoo
  • 🔒 Observation masking via active communication matrix
  • 🎯 Observation noise excludes zero-masked (unseen) values
  • 🤖 Supports MARL training frameworks (e.g. IQL, QMIX)
  • 🧩 Fully extensible for custom failure scenarios

API Highlights

CommunicationWrapper

  • Applies observation/action masking using ActiveCommunication
  • Works with any PettingZoo AEC environment
  • Internally uses SharedObsWrapper
  • Supports multi-model failure injection

NoiseWrapper

  • Adds noise only to visible observations
  • Maintains shape and structure of observation space
  • Customizable with user-defined noise logic

Requirements

  • Python 3.8+
  • pettingzoo
  • gymnasium
  • numpy
  • scipy
  • (Optional): matplotlib, tqdm, networkx

Testing

Use this to inspect the communication mask during runtime:

print(env.get_communication_state())  # Visualize active communication links

Extendability

You can define your own failure or noise model by subclassing:

from failure_api.communication_models import CommunicationModels

class MyFailureModel(CommunicationModels):
    def update_connectivity(self, comm_matrix):
        # Custom logic here
        return comm_matrix

Citation

If you use this in academic work, please cite:

@bachelorsthesis{adegun2025marlapi,
  author    = {Oluwadamilare Israel Adegun},
  title     = {Development of a Multi-Agent Reinforcement Learning API for Dynamic Observation and Action Spaces},
  school    = {University of Duisburg-Essen},
  year      = {2025},
  note      = {[Online; accessed 21-May-2025]}
}

🔗 Links


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

failure_api-0.1.5.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

failure_api-0.1.5-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file failure_api-0.1.5.tar.gz.

File metadata

  • Download URL: failure_api-0.1.5.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for failure_api-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9498adc702bc23a45dce50f99935b3914fbbf66b1193b1f05039ff3dc9b6c4e1
MD5 2f1303a84ea03b23548271a834d75a34
BLAKE2b-256 fe0171ef256c7af095ee94f561c73776a0ef741cc4f1fff867ec35fcdde7aa3c

See more details on using hashes here.

File details

Details for the file failure_api-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: failure_api-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for failure_api-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8b54fca03765ddb16948054d49d4f463275f216fb9936362e05e8d242b140adf
MD5 4e14d330193b1dc822b6b91bccdb6020
BLAKE2b-256 920475bd23b20e2ee623b584b09456b26e2bbb52152f9f48302264d353e9ebc2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page