Skip to main content

Tools for translating PyPRAM's Probabilistic Relational Agent-Based Models to Mesa's Agent-Based Models

Project description

pram2mesa

Tools for translating PyPRAM's Probabilistic Relational Agent-Based Models to Mesa's Agent-Based Models

pram2mesa is a tool allowing a Probabilistic Relational Agent-Based Model (PRAM) to be translated into an Agent-Based Model (ABM). There are a few tradeoffs here:

  • PRAMs work at a group level, while ABMs work at an individual agent level
  • PRAMs have a more formal grammar, while ABMs are open-ended
  • PRAMs are often much faster than ABMs, especially on very large populations

Core to this project, however, is a more theoretical purpose - demonstrating the interconnectedness of the two frameworks. While they are not the same, they are similar in many ways, allowing a tool like pram2mesa to exist. For more on comparing these frameworks, see the Media section.

Installation

Dependencies (For Translation)

Dependencies (For Running Translated ABMs)

Setup

To install pram2mesa and its dependencies (except PyPRAM) simply use pip:

pip install pram2mesa

PyPRAM must be installed separately. See PyPRAM's Setup for details or just use:

pip install git+https://github.com/momacs/pram.git

Bear in mind that any computer running a translated ABM will (of course) need Mesa, but also dill.

Also, note that many of the samples require further dependencies to run, although most should be covered by installing PyPRAM.

Usage

Translating the PRAM

To translate a PRAM, first create the PRAM in a Python file or interpreter. Make sure that you do not run the PRAM. If you do, your new ABM will be setup with the ending configuration of the PRAM, not the beginning.

my_pram = (Simulation().
    add(...)
)

Ensure you have imported pram2mesa:

from pram2mesa import pram2mesa

Then simply supply your PRAM simulation and a nice file-safe name for your new files:

pram2mesa(my_pram, 'MyNewABM')

By default, pram2mesa will automatically clean the outputted Python files in an attempt to make them PEP8-compliant. To disable this, simply set autopep to False:

pram2mesa(my_pram, 'MyNewABM', autopep=False)

This will create a new directory called MyNewABM (or MyNewABM_1 if MyNewABM already exists; or MyNewABM_2 etc...) containing three Python files and three JSON files:

MyNewABM
+-- MyNewABMAgent.py
+-- MyNewABMGroups.json
+-- MyNewABMModel.py
+-- MyNewABMRules.json
+-- MyNewABMSites.json
+-- make_python_identifier.py

Running the ABM

Once you've created the files, you can instantiate your new model and run it as you normally would in Mesa. Make sure to keep all the files together; the Agent and Model classes need the JSON files during their initialization and use make_python_identifier.py as well.

from MyNewABMModel import MyNewABMModel

model = MyNewABMModel()

You will want to be sure to add a datacollector to the model to measure and graph outputs.

model.datacollector = DataCollector(...)

The Models that pram2mesa generates do not override run_model(). If you want, you can override it yourself in the Model class, or just use step():

for i in range(num_runs):
    model.step()

Then, you can extract graphs or other data from your datacollector. If you are unfamiliar with Mesa, you can look at their documentation which includes some well-written tutorials. The files named run_abm.py in each folder of this project's Samples directory may also be useful.

Acknowledgements

Thank you to my research mentors, Drs. Paul Cohen and Tomek Loboda, for their support on this project.

This project is supported by the Brackenridge Fellowship at the University of Pittsburgh Honors College.

License

This project is licensed under the MIT License.

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

pram2mesa-0.2.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

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

pram2mesa-0.2.0-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file pram2mesa-0.2.0.tar.gz.

File metadata

  • Download URL: pram2mesa-0.2.0.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for pram2mesa-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1ef5f69b4122ac177d9981cb5600dfb65ada934430e61cc95b4f60dbc6855c13
MD5 81a991e2587db8c7218c421398f86e38
BLAKE2b-256 fe34ff1f0e4f85a62146dfe9ed440d97f75493b4eaaa9d4767b7ba68067fb438

See more details on using hashes here.

File details

Details for the file pram2mesa-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pram2mesa-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for pram2mesa-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8e76d9c451c93b073fd4077644eefbb2b2b2455c439dfa38ad0df0f3791ab23
MD5 d03bb0a651f7989c0286befa1161f10c
BLAKE2b-256 7db3b07f1989535a791cdce1dca20daba0decacb799c6fdc87a41b831e1fa3c8

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