Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: Adding Sugarscape IG - polars with numba vectorized loop #91

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4f5c6f9
adding numba to project.toml
adamamer20 Aug 28, 2024
1095dca
splitting agent_type
adamamer20 Aug 28, 2024
29e995b
splitting antpolars and antpolarsloop
adamamer20 Aug 28, 2024
da6d27e
adding py-spy to dev tools
adamamer20 Sep 1, 2024
f236b54
splitting between numba, loop with DF and loop non vectorized impleme…
adamamer20 Sep 1, 2024
9947bf0
performance comparison between loop and numba
adamamer20 Sep 1, 2024
1d90c20
fix: cuda target, not gpu
adamamer20 Sep 1, 2024
77d6699
adding polars comparison
adamamer20 Sep 1, 2024
ca9a7f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2024
3ceb1ef
Merge branch 'main' into 67-sugarscape-instantaneous-growback-polars-…
adamamer20 Sep 20, 2024
01663c6
correcting dtypes
adamamer20 Sep 20, 2024
1dff9bb
adding writable_args (see https://numba.readthedocs.io/en/stable/user…
adamamer20 Sep 20, 2024
ec2437b
processed_agents is of type bool
adamamer20 Sep 20, 2024
845aa61
fix: occupied cells sorted by agent_order, assertion to verify best m…
adamamer20 Sep 20, 2024
ced1d16
adding fixed initial positions (to assert equality between simulations)
adamamer20 Sep 20, 2024
b4f187f
Merge branch 'main' of https://github.com/projectmesa/mesa-frames int…
adamamer20 Sep 22, 2024
67b2803
adding complete reproducibility via seed
adamamer20 Sep 22, 2024
5d65345
fix: taking into account potential (max) sugar when creating the neig…
adamamer20 Sep 22, 2024
862caa2
fix: considering priority (if there are previous order agents that mi…
adamamer20 Sep 22, 2024
feb8c6f
fix: formatting
adamamer20 Sep 22, 2024
a93a84d
clarifying with comments
adamamer20 Sep 22, 2024
801a98c
updating actual sugar before executing the step (NOTE: might be unnce…
adamamer20 Sep 22, 2024
dff31aa
whitespace fixes
adamamer20 Sep 22, 2024
bea9770
adding initial_positions and seed to mesa model
adamamer20 Oct 1, 2024
82b4df7
renaming grid to space for mesa_models
adamamer20 Oct 1, 2024
ac52026
fix: best_moves only uses neighborhood and not agent_order
adamamer20 Oct 1, 2024
0bed775
adding documentation and type hints
adamamer20 Oct 1, 2024
e86bb33
fix: logic for the priority condition (right order of parentheses)
adamamer20 Oct 1, 2024
e40b83c
removing assertion (testing purposes only)
adamamer20 Oct 1, 2024
79698bd
adding equality_check on model state
adamamer20 Oct 1, 2024
2dedbec
changing n_range to reflect million of agents
adamamer20 Oct 1, 2024
ef664ae
fix: changing callable to typing.Callable
adamamer20 Oct 1, 2024
cbc14b3
removing extra requirement
adamamer20 Oct 1, 2024
284163b
removing flame_graph (it was just a one-off, we can add memory-profil…
adamamer20 Oct 1, 2024
2806466
fix: comparing DFs
adamamer20 Oct 1, 2024
511f08d
removing outdated picture
adamamer20 Oct 1, 2024
6644381
adding mesa_comparison.png
adamamer20 Oct 2, 2024
7dade71
adding polars_cocmparison.png
adamamer20 Oct 2, 2024
fe74814
updating kernels for comparison
adamamer20 Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The following is a performance graph showing execution time using mesa and mesa-
## Installation

### Install from PyPI

```bash
pip install mesa-frames
```
Expand Down
83 changes: 75 additions & 8 deletions examples/sugarscape_ig/performance_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
import matplotlib.pyplot as plt
import numpy as np
import perfplot
import seaborn as sns
from ss_mesa.model import SugarscapeMesa
from ss_pandas.model import SugarscapePandas
from ss_polars.agents import (
AntPolarsLoopDF,
AntPolarsLoopNoVec,
AntPolarsNumbaCPU,
AntPolarsNumbaGPU,
AntPolarsNumbaParallel,
)
from ss_polars.model import SugarscapePolars


Expand Down Expand Up @@ -34,9 +42,58 @@ def mesa_frames_pandas_concise(setup: SugarScapeSetup):
).run_model(100)


def mesa_frames_polars_concise(setup: SugarScapeSetup):
def mesa_frames_polars_loop_DF(setup: SugarScapeSetup):
return SugarscapePolars(
setup.n, setup.sugar_grid, setup.initial_sugar, setup.metabolism, setup.vision
AntPolarsLoopDF,
setup.n,
setup.sugar_grid,
setup.initial_sugar,
setup.metabolism,
setup.vision,
).run_model(100)


def mesa_frames_polars_loop_no_vec(setup: SugarScapeSetup):
return SugarscapePolars(
AntPolarsLoopNoVec,
setup.n,
setup.sugar_grid,
setup.initial_sugar,
setup.metabolism,
setup.vision,
).run_model(100)


def mesa_frames_polars_numba_cpu(setup: SugarScapeSetup):
return SugarscapePolars(
AntPolarsNumbaCPU,
setup.n,
setup.sugar_grid,
setup.initial_sugar,
setup.metabolism,
setup.vision,
).run_model(100)


def mesa_frames_polars_numba_gpu(setup: SugarScapeSetup):
return SugarscapePolars(
AntPolarsNumbaGPU,
setup.n,
setup.sugar_grid,
setup.initial_sugar,
setup.metabolism,
setup.vision,
).run_model(100)


def mesa_frames_polars_numba_parallel(setup: SugarScapeSetup):
return SugarscapePolars(
AntPolarsNumbaParallel,
setup.n,
setup.sugar_grid,
setup.initial_sugar,
setup.metabolism,
setup.vision,
).run_model(100)


Expand All @@ -61,9 +118,9 @@ def plot_and_print_benchmark(labels, kernels, n_range, title, image_path):


def main():
"""# Mesa comparison
# Mesa comparison
sns.set_theme(style="whitegrid")
labels_0 = [
"""labels_0 = [
"mesa",
# "mesa-frames (pd concise)",
"mesa-frames (pl concise)",
Expand All @@ -81,15 +138,25 @@ def main():
# FLAME2-GPU comparison
labels_1 = [
# "mesa-frames (pd concise)",
"mesa-frames (pl concise)",
"mesa-frames (pl loop DF)",
"mesa-frames (pl loop no vec)",
"mesa-frames (pl numba CPU)",
"mesa-frames (pl numba parallel)",
# "mesa-frames (pl numba GPU)",
]
# Polars best_moves (non-vectorized loop vs DF loop vs numba loop)
kernels_1 = [
# mesa_frames_pandas_concise,
mesa_frames_polars_concise,
mesa_frames_polars_loop_DF,
mesa_frames_polars_loop_no_vec,
mesa_frames_polars_numba_cpu,
mesa_frames_polars_numba_parallel,
# mesa_frames_polars_numba_gpu,
]
n_range_1 = [k for k in range(1, 3 * 10**6 + 2, 10**6)]
n_range_1 = [k for k in range(1, 2 * 10**6 + 2, 10**6)]
# n_range_1 = [k for k in range(10000, 100002, 10000)]
title_1 = "100 steps of the SugarScape IG model:\n" + " vs ".join(labels_1)
image_path_1 = "benchmark_plot_1.png"
image_path_1 = "polars_comparison.png"
plot_and_print_benchmark(labels_1, kernels_1, n_range_1, title_1, image_path_1)


Expand Down
Binary file added examples/sugarscape_ig/polars_comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading