Skip to main content

Agent-based Modeling with Blazingly Efficient Records

Project description

AMBER (Agent-based Modeling with Blazingly Efficient Records)

CI codecov Python 3.9+ License: BSD-3-Clause

AMBER is a Python framework for agent-based modeling that uses Polars for efficient data handling and analysis. AMBER provides a clean, robust API for creating parallel, high-performance simulations in Python.

🚀 Performance

AMBER achieves high performance through its columnar memory layout (SoA), KD-Trees, and SIMD-vectorized operations.

Benchmark vs Other Frameworks (5,000 Agents, 100 Steps)

Framework Language Architecture Speed Rank
Agents.jl Julia Vectorized 🥇 1st (0.02s - 0.9s)
AMBER Python Vectorized 🥈 2nd (0.1s - 2.3s)
SimPy (Dense) Python Process/DES 🥉 3rd (0.3s - 4.3s)
Melodie Python Hybrid 4th (0.4s - 20s)
AgentPy Python Object 5th (2s - 30s)
Mesa Python Object 6th (50s - 30s)

*SimPy is exceptionally fast for sparse models (like SIR) due to its event-driven nature, but AMBER is faster for dense/movement-heavy models.

AMBER is the state-of-the-art for dense simulation in Python, while SimPy offers an alternative for event-driven logic.

Comparison Chart

🚀 Quick Start

import ambr as am

# Define a custom agent
class MyAgent(am.Agent):
    def setup(self):
        self.value = self.p.initial_value
        
    def step(self):
        self.value += self.model.random.randint(-1, 2)
        self.record('value', self.value)

# Define a model
class MyModel(am.Model):
    def setup(self):
        self.agents = am.AgentList(self, self.p.agents, MyAgent)
        
    def step(self):
        self.agents.call('step')
        
    def update(self):
        super().update()
        self.agents.record('value')

# Run a simulation
parameters = {
    'agents': 10,
    'initial_value': 5,
    'steps': 100
}

model = MyModel(parameters)
results = model.run()

⚡ Advanced: Vectorized Updates

For maximum performance, access the underlying Population manager to perform SIMD-vectorized state updates, bypassing Python loop overhead:

def step(self):
    # Create a batch update context
    with self.population.create_batch_context() as batch:
        # Queue updates logic (executed in Rust/Polars)
        batch.add_update(target_ids, 'wealth', 1)
        batch.add_update(source_ids, 'wealth', -1)
    
    # State is applied atomically here

🔬 Optimization

AMBER includes powerful optimization capabilities for parameter tuning:

from ambr.optimization import ParameterSpace, grid_search

# Define parameter space
parameter_space = ParameterSpace({
    'agents': [10, 50, 100],
    'initial_value': [1, 5, 10],
    'steps': 100
})

# Run optimization
results = grid_search(MyModel, parameter_space, 'some_metric')
best_params = results[0]['parameters']

📦 Installation

pip install ambr

🏗️ Features

  • Simple API: Intuitive interface for agent-based modeling
  • High Performance: Efficient data handling with Polars DataFrames
  • Optimization: Built-in parameter optimization with grid search, random search, and Bayesian optimization
  • Environments: Support for grid, network, and continuous space environments
  • Experiments: Run multiple simulations with parameter sampling
  • Random Number Generation: Reproducible simulations with controlled randomness

📚 Examples

Working examples are available in the examples/ directory:

  • Wealth Transfer Model: Economic inequality simulation
  • Virus Spread Model: Epidemiological SIR model
  • Flocking Simulation: Boids flocking behavior
  • Forest Fire Model: Cellular automata fire spread
  • Network Simulations: Graph-based agent interactions

📖 Documentation

📝 How to cite?

If you use AMBER in your research, please cite our paper:

@article{pham2026amber,
  title={AMBER: A Columnar Architecture for High-Performance Agent-Based Modeling in Python},
  author={Pham, Anh-Duy},
  journal={arXiv preprint arXiv:2601.16292},
  year={2026}
}

🤝 Contributing

We welcome contributions! Please see our contributing guidelines for more information.

📄 License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

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

ambr-0.1.5.tar.gz (254.3 kB view details)

Uploaded Source

Built Distribution

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

ambr-0.1.5-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ambr-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d54ae5e3b89824cf4566c920fb36905fb4e31f2a2bd7555199eb03f429332dc4
MD5 2754d8002f0ad7fe361e3c9910220e4b
BLAKE2b-256 942ed475cd0d273e052491cef1f64a644f30f541b7e4aefba90b96e17b3d3a2b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ambr-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 48a1f4db23ff0e10a3e40bbf0006f58dade30da91e3009328ada6c3a27672e43
MD5 cbf1b58b0b1805ecb71501db013a0661
BLAKE2b-256 258c12fddef4247384c97782c48df7ccebf3855a68cd8976f21f8f3987372c45

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