Skip to main content

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.

Metadata

Release files for pram2mesa 0.2.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 pram2mesa 0.2.0
File Size Uploaded
pram2mesa-0.2.0.tar.gz 29.0 kB Details

Built distribution (wheel)

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

Total release size: 57.5 kB

Release files / pram2mesa-0.2.0.tar.gz

Download URL pram2mesa-0.2.0.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1ef5f69b4122ac177d9981cb5600dfb65ada934430e61cc95b4f60dbc6855c13
BLAKE2b-256 checksum
How to use checksums
fe34ff1f0e4f85a62146dfe9ed440d97f75493b4eaaa9d4767b7ba68067fb438
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pram2mesa-0.2.0-py3-none-any.whl

Download URL pram2mesa-0.2.0-py3-none-any.whl
Size 28.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8e76d9c451c93b073fd4077644eefbb2b2b2455c439dfa38ad0df0f3791ab23
BLAKE2b-256 checksum
How to use checksums
7db3b07f1989535a791cdce1dca20daba0decacb799c6fdc87a41b831e1fa3c8
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.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