Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/adamamer20/mesa-frames into…
Browse files Browse the repository at this point in the history
… 65-sugarscape-instantaneous-growback-polars-with-loops
  • Loading branch information
adamamer20 committed Aug 28, 2024
2 parents e0bb12c + 329eb16 commit bdc322c
Show file tree
Hide file tree
Showing 44 changed files with 1,916 additions and 616 deletions.
39 changes: 29 additions & 10 deletions .github/workflows/docs-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
name: Publish docs via GitHub Pages
name: Build and Deploy Documentation

on:
push:
branches:
- main

jobs:
build:
name: Deploy docs
build-and-deploy-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for .git-restore-mtime to work correctly

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[docs]
- name: Build MkDocs site (general documentation)
run: mkdocs build --config-file mkdocs.yml --site-dir ./site

- name: Build Sphinx docs (api documentation)
run: |
sphinx-build -b html docs/api site/api
- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REQUIREMENTS: docs/requirements.txt
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
force_orphan: true
3 changes: 2 additions & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"MD013": false
"MD013": false,
"MD046": false
}
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# mesa-frames
# mesa-frames 🚀

mesa-frames is an extension of the [mesa](https://github.com/projectmesa/mesa) framework, designed for complex simulations with thousands of agents. By storing agents in a DataFrame, mesa-frames significantly enhances the performance and scalability of mesa, while maintaining a similar syntax. mesa-frames allows for the use of [vectorized functions](https://vegibit.com/what-is-a-vectorized-operation-in-pandas/) whenever simultaneous activation of agents is possible.
mesa-frames is an extension of the [mesa](https://github.com/projectmesa/mesa) framework, designed for complex simulations with thousands of agents. By storing agents in a DataFrame, mesa-frames significantly enhances the performance and scalability of mesa, while maintaining a similar syntax. mesa-frames allows for the use of [vectorized functions](https://stackoverflow.com/a/1422198) which significantly speeds up operations whenever simultaneous activation of agents is possible.

## Why DataFrames?
## Why DataFrames? 📊

DataFrames are optimized for simultaneous operations through [SIMD processing](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data). At the moment, mesa-frames supports the use of two main libraries: pandas and Polars.

Expand All @@ -11,11 +11,11 @@ DataFrames are optimized for simultaneous operations through [SIMD processing](h

The following is a performance graph showing execution time using mesa and mesa-frames for the [Boltzmann Wealth model](https://mesa.readthedocs.io/en/stable/tutorials/intro_tutorial.html).

![Performance Graph](https://github.com/adamamer20/mesa_frames/blob/main/docs/images/readme_plot_0.png)
![Performance Graph with Mesa](https://github.com/adamamer20/mesa_frames/blob/main/examples/boltzmann_wealth/boltzmann_with_mesa.png)

![Performance Graph without Mesa](https://github.com/adamamer20/mesa_frames/blob/main/docs/images/readme_plot_1.png)
![Performance Graph without Mesa](https://github.com/adamamer20/mesa_frames/blob/main/examples/boltzmann_wealth/boltzmann_no_mesa.png)

(The script used to generate the graph can be found [here](https://github.com/adamamer20/mesa_frames/blob/main/docs/scripts/readme_plot.py), but if you want to additionally compare vs Mesa, you have to uncomment `mesa_implementation` and its label)
(The script used to generate the graph can be found [here](https://github.com/adamamer20/mesa_frames/blob/main/examples/boltzmann_wealth/performance_plot.py), but if you want to additionally compare vs Mesa, you have to uncomment `mesa_implementation` and its label)

## Installation

Expand Down Expand Up @@ -45,10 +45,7 @@ conda activate myenv
Then, to install mesa-frames itself:

```bash
# For pandas backend
pip install -e .[pandas]
# Alternatively, for Polars backend
pip install -e .[polars]
pip install -e .
```

### Installing in a Python Virtual Environment
Expand All @@ -69,10 +66,7 @@ source myenv/bin/activate # On Windows, use `myenv\Scripts\activate`
Then, to install mesa-frames itself:

```bash
# For pandas backend
pip install -e .[pandas]
# Alternatively, for Polars backend
pip install -e .[polars]
pip install -e .
```

## Usage
Expand Down Expand Up @@ -141,11 +135,11 @@ class MoneyModelDF(ModelDF):
self.step()
```

## What's Next?
## What's Next? 🔮

- Refine the API to make it more understandable for someone who is already familiar with the mesa package. The goal is to provide a seamless experience for users transitioning to or incorporating mesa-frames.
- Adding support for default mesa functions to ensure that the standard mesa functionality is preserved.
- Adding GPU functionality (cuDF and Rapids).
- Adding GPU functionality (cuDF and Dask-cuDF).
- Creating a decorator that will automatically vectorize an existing mesa model. This feature will allow users to easily tap into the performance enhancements that mesa-frames offers without significant code alterations.
- Creating a unique class for AgentSet, independent of the backend implementation.

Expand Down
20 changes: 20 additions & 0 deletions docs/api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
77 changes: 77 additions & 0 deletions docs/api/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os

# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here.
import sys
from pathlib import Path

sys.path.insert(0, str(Path("..").resolve()))

# -- Project information -----------------------------------------------------
project = "mesa-frames"
author = "Adam Amer"
copyright = f"2023, {author}"

# -- General configuration ---------------------------------------------------
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
"numpydoc",
"sphinx_copybutton",
"sphinx_design",
"autodocsumm",
]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# -- Options for HTML output -------------------------------------------------
html_theme = "pydata_sphinx_theme"
html_static_path = ["_static"]
html_show_sourcelink = False

# -- Extension settings ------------------------------------------------------
# intersphinx mapping
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pandas": ("https://pandas.pydata.org/docs/", None),
"polars": ("https://pola-rs.github.io/polars/py-polars/html/", None),
}

# numpydoc settings
numpydoc_show_class_members = False

# Copybutton settings
copybutton_prompt_text = r">>> |\.\.\. "
copybutton_prompt_is_regexp = True

# -- Custom configurations ---------------------------------------------------
autoclass_content = "class"
autodoc_member_order = "bysource"
autodoc_default_options = {"special-members": True, "exclude-members": "__weakref__"}

# -- GitHub link and user guide settings -------------------------------------
github_root = "https://github.com/adamamer20/mesa-frames"
web_root = "https://adamamer20.github.io/mesa-frames"

html_theme_options = {
"external_links": [
{
"name": "User guide",
"url": f"{web_root}/user-guide/",
},
],
"icon_links": [
{
"name": "GitHub",
"url": github_root,
"icon": "fa-brands fa-github",
},
],
"navbar_end": ["navbar-icon-links"],
}
27 changes: 27 additions & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
mesa-frames API
===============

This page provides a high-level overview of all public mesa-frames objects, functions, and methods. All classes and functions exposed in the ``mesa_frames.*`` namespace are public.

.. grid::

.. grid-item-card::

.. toctree::
:maxdepth: 2

reference/agents/index

.. grid-item-card::

.. toctree::
:maxdepth: 1

reference/model

.. grid-item-card::

.. toctree::
:maxdepth: 3

reference/space/index
35 changes: 35 additions & 0 deletions docs/api/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
17 changes: 17 additions & 0 deletions docs/api/reference/agents/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AgentSetDF
==========

.. currentmodule:: mesa_frames

.. autoclass:: AgentSetPandas
:members:
:inherited-members:
:autosummary:
:autosummary-nosignatures:

.. autoclass:: AgentSetPolars
:members:
:inherited-members:
:autosummary:
:autosummary-nosignatures:

10 changes: 10 additions & 0 deletions docs/api/reference/model.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ModelDF
=======

.. currentmodule:: mesa_frames

.. autoclass:: ModelDF
:members:
:inherited-members:
:autosummary:
:autosummary-nosignatures:
16 changes: 16 additions & 0 deletions docs/api/reference/space/grid/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
GridDF
======

.. currentmodule:: mesa_frames

.. autoclass:: GridPandas
:members:
:inherited-members:
:autosummary:
:autosummary-nosignatures:

.. autoclass:: GridPolars
:members:
:inherited-members:
:autosummary:
:autosummary-nosignatures:
8 changes: 8 additions & 0 deletions docs/api/reference/space/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Space
=====
This page provides a high-level overview of possible space objects for mesa-frames models.

.. toctree::
:maxdepth: 2

grid/index
4 changes: 4 additions & 0 deletions docs/general/development/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Development Guidelines

!!! warning
This page is in construction, check it again soon.
Loading

0 comments on commit bdc322c

Please sign in to comment.