Skip to main content

Agent-based modeling framework

Project description

Build Status Coverage Status

Dworp

Flexible framework for building agent-based modeling simulations.

Requirements

  • python 3

Installation

Install using pip (maybe be pip3 on some platforms):

pip install dworp

To install with the optional plotting capability:

pip install dworp[plot]

This will install dependencies required by dworp.plot (currently only matplotlib).

Using

Dworp defines basic interfaces for building simulations and provides some default components to support rapid creation of agent-based models.

Agent

An Agent updates its state in the step() function. The update may depend on the environment, its neighbors, past history, or other features.

An agent has two optional functions init() and complete(). The init() function is called when an agent is added to the simulation. The complete() function is called at the end of a time step.

class MyAgent(dworp.Agent):
    def step(self, now, env):
        # ToDo add example here
        pass

Visibility of Agent State

When agents are updating their state based on their neighbors' state, you may want to use a two stage update mechanism. In the first stage, the agents update their state privately so that their neighbors cannot see the new state. In the second stage, the agents make that state public to prepare for the next time step.

Environment

The Environment captures all simulation state that does not live in the agents. This includes serving as a container for network or spatial information for determining neighbors.

Time

Time drives the simulation and implements an iterator interface. It can be fixed in length or infinite. Time steps can be fixed in length or variable. Time can be integer or floating point.

Space

Agents can observe or interact with other agents based on neighborhoods. A neighborhood may be defined on a network using various graph frameworks like igraph or snap. A neighborhood can also be spatially defined on a grid or continuous space.

Terminator

To stop the simulation when some condition is met, use a Terminator.

Schedule

The order that agents update and which agents update is determined by the Scheduler. Some basic schedulers are provided for round robin updates in random order or uniformly sampling.

Observer

An Observer runs after each time step. It is designed for capturing data for further processing. It has access to the agents and the environment. Multiple observers can be chained together using ChainedObserver.

Simulation

The Simulation interface defines a single realization of an agent-based simulation. Basic implementations for single stage and double stage updates are provided. Usually, you will want to inherit from one of those to define your simulation.

Logging

Each component has its own logger:

    self.logger.info("Agent {} set activity to {}".format(self.agent_id, self.activity))

The logging level can be controlled at the framework level:

    logging.getLogger('dworp').setLevel(logging.WARN)

or at the individual component level:

    logging.getLogger('dworp.agent').setLevel(logging.DEBUG)

For more information on log levels or log configuration, read the python logging docs.

Examples

The best way to learn the framework is by looking at the example models and their documentation.

Testing

Install the test requirements:

pip install -r test_requirements.txt

Then to run the tests (while in the base directory):

nosetests

This will run all the tests. To skip the plotting unit tests which require matplotlib, do this:

nosetests -a '!plot'

To get a report on unit test coverage:

nosetests --with-coverage --cover-package=dworp

Development

To install in editable model so that changes to the framework are instantly reflected:

pip install -e .

The code mostly follows the PEP8 coding standard. If you are using PyCharm, it will highlight PEP8 issues. You can also manually run style checks with flake8 (pip install flake8):

flake8 dworp

The docstrings are using the Google standard.

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

dworp-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

dworp-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file dworp-0.1.0.tar.gz.

File metadata

  • Download URL: dworp-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dworp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5cf8d4dcecf0d44dbd848b5fde807d10b3d35df4a374863754926f18dfa0fead
MD5 8dc74eb0e033ef9e0ed803d90affd717
BLAKE2b-256 9e05faf87dc7c94d6e4cb1e6c6a479eb0c3072a98710832c8404dd9fb6e2a076

See more details on using hashes here.

File details

Details for the file dworp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dworp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d6feb937addd460c4750703006fa1d9b75f4d43acc868ab39aea0637f6e197e
MD5 fe868a27f2b54ae550a7493c443e0cce
BLAKE2b-256 2a4e510ca6ddddae8b0ea50917b62b630011d3a7a85610b67f002d91d7cf81e6

See more details on using hashes here.

Supported by

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