Skip to content

Mesa implementation of Ising Model #138

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

Open
wants to merge 83 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
2925aac
created ising model
vitorfrois Jul 13, 2024
ec724b3
created ising model
vitorfrois Jul 13, 2024
ff3b7fa
final fixes
vitorfrois Jul 13, 2024
d60038e
fix portrayal
vitorfrois Jul 14, 2024
df3b9e0
categorize example models into groups
wang-boyu Jul 16, 2024
e137a60
Make batch_run pytestable by adding main() functions (#143)
EwoutH Jul 22, 2024
b5ad740
Readme: Name mesa-2.x branch for example for Mesa 2.x
EwoutH Aug 2, 2024
72cfb9e
CI: Don't test stable builds (until Mesa 3.0 is released)
EwoutH Aug 2, 2024
fe7f71e
[pre-commit.ci] pre-commit autoupdate (#149)
pre-commit-ci[bot] Aug 6, 2024
17c65ce
merge README files into top level README
wang-boyu Jul 21, 2024
68b6d31
Address duplicate position warning (#122)
rht Aug 10, 2024
352ac32
CI: Increase pytest verbosity
EwoutH Aug 10, 2024
ebb7976
CI: Let pytest generate summary report
EwoutH Aug 10, 2024
78b8a36
Use SolaraViz instead of JupyterViz in examples
EwoutH Aug 11, 2024
cc65481
sugerscape_g1mt: Refactor using AgentSet functionality
EwoutH Aug 10, 2024
923a83e
charts: Don't pass pos
EwoutH Aug 10, 2024
fbf80af
shape: Don't pass pos
EwoutH Aug 10, 2024
4dac7dc
wolf_sheep: Replace custom scheduler with AgentSet functionality
EwoutH Aug 10, 2024
487561d
bank_reserves: Don't pass pos
EwoutH Aug 10, 2024
86cdf99
CI: Let pytest treat warnings as errors
EwoutH Aug 10, 2024
3e0d16f
sugerscape_g1mt: Use model.get_agents_of_type instead of .select()
EwoutH Aug 11, 2024
274a1bc
schelling_experimental: Fix SolaraViz import
EwoutH Aug 18, 2024
bd17361
Replace model.schedule.agents with model.agents AgentSet
EwoutH Aug 17, 2024
642a9ad
Replace RandomActivation scheduler with AgentSet
EwoutH Aug 17, 2024
8e0ccf6
Replace SimultaneousActivation scheduler by AgentSet
EwoutH Aug 17, 2024
dbedf6f
Remove adding agents to schedulers
EwoutH Aug 17, 2024
4b66a64
Custom schedule replacements
EwoutH Aug 17, 2024
c0ea5a2
Restore Sugerscape and Wolf-sheep schedulers
EwoutH Aug 17, 2024
1fa7a25
Final fixes
EwoutH Aug 17, 2024
0c6366c
bank_reserves/charts: Don't make Bank an Agent
EwoutH Aug 17, 2024
0ebc4d1
Add docstring note that Bank is a regular class, not an Agent
EwoutH Aug 18, 2024
43622b9
Revert PR #161: Replace schedulers with AgentSet functionality (#170)
EwoutH Aug 22, 2024
2b944ff
Ant Colony Optimization (#157)
zjost Aug 24, 2024
2fd8945
gis: Use relative imports in all models
EwoutH Aug 25, 2024
7ecbb93
Create script to test GIS examples
EwoutH Aug 25, 2024
eed4f7d
CI: Modernize examples test script
EwoutH Aug 25, 2024
c2f4a73
CI: Add workflow to test gis models
EwoutH Aug 25, 2024
efffb67
Define optional gis dependencies in pyproject.toml
EwoutH Aug 25, 2024
49342ea
Update optional dependencies and CI
EwoutH Aug 25, 2024
4fe5c71
Add super().__init__() to Mesa model initalization (#175)
EwoutH Aug 25, 2024
bbf5ad2
Fix 3 data path imports in gis models (#176)
EwoutH Aug 25, 2024
269ff1a
Fix data paths and model passing in GIS examples (#177)
EwoutH Aug 26, 2024
3c71ea9
fixing comments
vitorfrois Aug 27, 2024
6e59b9a
Fix marker function name
vitorfrois Aug 28, 2024
1d67252
Ensure grasspatches info is only collected if gras is true (#181)
quaquel Aug 28, 2024
2bc3a2d
Update SugarscapeG1mt for automatic time advancement
EwoutH Aug 29, 2024
3e5ebd1
schelling_experimental: Remove temporary _advance_time() method (#162)
EwoutH Aug 29, 2024
2ece0cf
GoL_fast: Add fast PropertyLayer implementation of Game of Life
EwoutH Aug 29, 2024
541b004
GoL_fast: Add minimal Solara visualisation
EwoutH Aug 29, 2024
aee22c1
GoL_fast: Add metrics, datacollector and measure viz
EwoutH Aug 29, 2024
a0d50a8
GoL_fast: Add Readme
EwoutH Aug 29, 2024
875110a
Add scipy to test dependencies
EwoutH Aug 29, 2024
eb66dae
pytest: Don't raise FutureWarning to Error
EwoutH Aug 29, 2024
be57796
Readme: Add Conway's Game Of "Life" Model (Fast)
EwoutH Aug 29, 2024
fc18ece
GoL_fast: Remove advance_time()
EwoutH Aug 30, 2024
0fd7f82
Reinstate PR #161: Replace schedulers with AgentSet functionality
EwoutH Aug 30, 2024
3d29e4c
test_examples: assert model.steps == 10
EwoutH Aug 30, 2024
dee6363
gis: Use gzip.open opener in RasterLayer.from_file (#184)
EwoutH Sep 2, 2024
89f9379
gis: Pass model to RasterLayer.from_file (#186)
EwoutH Sep 2, 2024
6312ebe
add model default params for agents-networks gis example
wang-boyu Sep 2, 2024
f24626e
fix unhashable type error in agents-networks gis example
wang-boyu Sep 2, 2024
679b677
set output_dir parameter for agents-networks gis example
wang-boyu Sep 3, 2024
330b4d9
[pre-commit.ci] pre-commit autoupdate (#188)
pre-commit-ci[bot] Sep 3, 2024
aca30a2
gis: fix user warning when testing geo schelling example
wang-boyu Sep 3, 2024
e7345de
Replace `get_agents_of_type` method with `agents_by_type` property (#…
EwoutH Sep 3, 2024
831be82
Readme: Add note about Mesa-Geo version compatiblity
EwoutH Sep 3, 2024
c4b4c75
Add seeding RL examples folder (#178)
harshmahesheka Sep 4, 2024
ec07d89
aoc_tsp: Replace scheduler with AgentSet functionality (#191)
EwoutH Sep 4, 2024
660102f
Remove unique_id and model.next_id (#194)
quaquel Sep 5, 2024
d79f74e
update boltzmann-wealth update to use new solaraviz api
Corvince Sep 5, 2024
2b43544
Add visualization element explanation
Corvince Sep 5, 2024
9c30387
update examples to use new SolaraViz API (#193)
Corvince Sep 17, 2024
31537d8
GoL_fast: Make datacollection import explicit (#199)
EwoutH Sep 20, 2024
9a5396f
Use performance optimized shuffle_do() method (#201)
EwoutH Sep 21, 2024
8d0c722
Replace the remaining schedulers with AgentSet functionality (#202)
EwoutH Sep 21, 2024
ed6f910
updated file name, using only pertinent parameters
vitorfrois Sep 23, 2024
561f1f1
updating ising
vitorfrois Sep 23, 2024
ecb8aab
updating ising
vitorfrois Sep 23, 2024
44a3ed5
solara viz
vitorfrois Sep 23, 2024
7d75683
last fixes
vitorfrois Sep 23, 2024
1a01780
update var name
vitorfrois Sep 23, 2024
cd2eb61
Merge branch 'ising'
vitorfrois Sep 24, 2024
0704d13
fix tests warnings
vitorfrois Sep 24, 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
68 changes: 0 additions & 68 deletions .github/workflows/build_lint.yml

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/test_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Test example models

on:
push:
paths:
- 'examples/**/*.py' # If an example model is modified
- 'test_examples.py' # If the test script is modified
- '.github/workflows/test_examples.yml' # If this workflow is modified
pull_request:
paths:
- 'examples/**/*.py'
- 'test_examples.py'
- '.github/workflows/test_examples.yml'
workflow_dispatch:
schedule:
- cron: '0 6 * * 1' # Monday at 6:00 UTC

jobs:
# build-stable:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: "3.12"
# - name: Install dependencies
# run: pip install mesa pytest
# - name: Test with pytest
# run: pytest -rA -Werror test_examples.py

build-pre:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
pip install mesa --pre
pip install .[test]
- name: Test with pytest
run: pytest -rA -Werror -Wdefault::FutureWarning test_examples.py

build-main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
pip install .[test]
pip install -U git+https://github.com/projectmesa/mesa@main#egg=mesa
- name: Test with pytest
run: pytest -rA -Werror -Wdefault::FutureWarning test_examples.py
60 changes: 60 additions & 0 deletions .github/workflows/test_gis_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Test GIS models

on:
push:
paths:
- 'gis/**/*.py' # If a gis model is modified
- 'test_gis_examples.py' # If the gis test script is modified
- '.github/workflows/test_gis_examples.yml' # If this workflow is modified
pull_request:
paths:
- 'gis/**/*.py'
- 'test_gis_examples.py'
- '.github/workflows/test_gis_examples.yml'
workflow_dispatch:
schedule:
- cron: '0 6 * * 1' # Monday at 6:00 UTC

jobs:
# build-stable:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: "3.12"
# - name: Install dependencies
# run: pip install mesa pytest
# - name: Test with pytest
# run: pytest -rA -Werror test_examples.py

build-pre:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
pip install mesa-geo --pre
pip install .[test_gis]
- name: Test with pytest
run: pytest -rA -Werror test_gis_examples.py

build-main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
pip install -U git+https://github.com/projectmesa/mesa-geo@main#egg=mesa-geo
pip install .[test_gis]
- name: Test with pytest
run: pytest -rA -Werror test_gis_examples.py
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
rev: v0.6.3
hooks:
# Run the linter.
# TODO fix the lint issues for the Jupyter notebooks
Expand All @@ -14,7 +14,7 @@ repos:
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand Down
148 changes: 146 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# mesa-examples
# Mesa Examples

This repository contains examples that work with Mesa and illustrate different features of Mesa.
This repository contains examples that work with Mesa and illustrate different features of Mesa. For more information on each model, see its own Readme and documentation.

- Mesa examples that work on the Mesa and Mesa-Geo main development branches are available here on the [`main`](https://github.com/projectmesa/mesa-examples) branch.
- Mesa examples that work with Mesa 2.x releases and Mesa-Geo 0.8.x releases are available here on the [`mesa-2.x`](https://github.com/projectmesa/mesa-examples/tree/mesa-2.x) branch.

To contribute to this repository, see [CONTRIBUTING.rst](https://github.com/projectmesa/mesa-examples/blob/main/CONTRIBUTING.rst).

Expand All @@ -9,7 +12,148 @@ This repo also contains a package that readily lets you import and run some of t
$ # This will install the "mesa_models" package
$ pip install -U -e git+https://github.com/projectmesa/mesa-examples#egg=mesa-models
```
For Mesa 2.x examples, install:
```console
$ # This will install the "mesa_models" package
$ pip install -U -e git+https://github.com/projectmesa/mesa-examples@mesa-2.x#egg=mesa-models
```
```python
from mesa_models.boltzmann_wealth_model.model import BoltzmannWealthModel

```
You can see the available models at [setup.cfg](https://github.com/projectmesa/mesa-examples/blob/main/setup.cfg).

Table of Contents
=================

* [Grid Spacce Examples](#grid-space-examples)
* [Continuous Space Examples](#continuous-space-examples)
* [Network Examples](#network-examples)
* [Visualization Examples](#visualization-examples)
* [GIS Examples](#gis-examples)
* [Other Examples](#other-examples)

## Grid Space Examples

### [Bank Reserves Model](https://github.com/projectmesa/mesa-examples/blob/main/examples/bank_reserves)

A highly abstracted, simplified model of an economy, with only one type of agent and a single bank representing all banks in an economy.

### [Boltzmann Wealth Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/boltzmann_wealth_model)

Completed code to go along with the [tutorial](https://mesa.readthedocs.io/en/latest/tutorials/intro_tutorial.html) on making a simple model of how a highly-skewed wealth distribution can emerge from simple rules.

### [Color Patches Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/color_patches)

A cellular automaton model where agents opinions are influenced by that of their neighbors. As the model evolves, color patches representing the prevailing opinion in a given area expand, contract, and sometimes disappear.

### [Conway's Game Of "Life" Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/conways_game_of_life)

Implementation of [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life), a cellular automata where simple rules can give rise to complex patterns.

### [Conway's Game Of "Life" Model (Fast)](https://github.com/projectmesa/mesa-examples/tree/main/examples/conways_game_of_life_fast)

A very fast performance optimized version of Conway's Game of Life using the Mesa [`PropertyLayer`](https://github.com/projectmesa/mesa/pull/1898). About 100x as fast as the regular versions, but limited visualisation (for [now](https://github.com/projectmesa/mesa/issues/2138)).

### [Conway's Game Of "Life" Model on a Hexagonal Grid](https://github.com/projectmesa/mesa-examples/tree/main/examples/hex_snowflake)

Conway's game of life on a hexagonal grid.

### [Demographic Prisoner's Dilemma on a Grid](https://github.com/projectmesa/mesa-examples/tree/main/examples/pd_grid)

Grid-based demographic prisoner's dilemma model, demonstrating how simple rules can lead to the emergence of widespread cooperation -- and how a model activation regime can change its outcome.

### [Epstein Civil Violence Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/epstein_civil_violence)

Joshua Epstein's [model](http://www.uvm.edu/~pdodds/files/papers/others/2002/epstein2002a.pdf) of how a decentralized uprising can be suppressed or reach a critical mass of support.

### [Forest Fire Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/forest_fire)

Simple cellular automata of a fire spreading through a forest of cells on a grid, based on the NetLogo [Fire](http://ccl.northwestern.edu/netlogo/models/Fire) model.

### [Hotelling's Law Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/hotelling_law)

This project is an agent-based model implemented using the Mesa framework in Python. It simulates market dynamics based on Hotelling's Law, exploring the behavior of stores in a competitive market environment. Stores adjust their prices and locations if it's increases market share to maximize revenue, providing insights into the effects of competition and customer behavior on market outcomes.

### [Schelling Segregation Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/schelling)

Mesa implementation of the classic [Schelling segregation](http://nifty.stanford.edu/2014/mccown-schelling-model-segregation/) model.

### [Sugarscape Constant Growback Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/sugarscape_cg)

This is Epstein & Axtell's Sugarscape Constant Growback model, with a detailed description in the Chapter Two of *Growing Artificial Societies: Social Science from the Bottom Up*. It is based on the Netlogo
[Sugarscape 2 Constant Growback](http://ccl.northwestern.edu/netlogo/models/Sugarscape2ConstantGrowback) model.

### [Sugarscape Constant Growback Model with Traders](https://github.com/projectmesa/mesa-examples/tree/main/examples/sugarscape_g1mt)

This is Epstein & Axtell's Sugarscape model with Traders, a detailed description is in Chapter four of *Growing Artificial Societies: Social Science from the Bottom Up (1996)*. The model shows an emergent price equilibrium can happen via a decentralized dynamics.

### [Wolf-Sheep Predation Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/wolf_sheep)

Implementation of an ecological model of predation and reproduction, based on the NetLogo [Wolf Sheep Predation](http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation) model.

## Continuous Space Examples

### [Boids Flockers Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/boid_flockers)

[Boids](https://en.wikipedia.org/wiki/Boids)-style flocking model, demonstrating the use of agents moving through a continuous space following direction vectors.

## Network Examples

### [Boltzmann Wealth Model with Network](https://github.com/projectmesa/mesa-examples/tree/main/examples/boltzmann_wealth_model_network)

This is the same [Boltzmann Wealth](https://github.com/projectmesa/mesa-examples/tree/main/examples/boltzmann_wealth_model) Model, but with a network grid implementation.

### [Virus on a Network Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/virus_on_network)

This model is based on the NetLogo [Virus on a Network](https://ccl.northwestern.edu/netlogo/models/VirusonaNetwork) model.

### [Ant System for Traveling Salesman Problem](https://github.com/projectmesa/mesa-examples/tree/main/examples/aco_tsp)

This is based on Dorigo's Ant System "Swarm Intelligence" algorithm for generating solutions for the Traveling Salesman Problem.

## Visualization Examples

### [Boltzmann Wealth Model (Experimental)](https://github.com/projectmesa/mesa-examples/tree/main/examples/boltzmann_wealth_model_experimental)

Boltzmann Wealth model with the experimental Juptyer notebook visualization feature.

### [Charts Example](https://github.com/projectmesa/mesa-examples/tree/main/examples/charts)

A modified version of the [Bank Reserves](https://github.com/projectmesa/mesa-examples/tree/main/examples/bank_reserves) example made to provide examples of Mesa's charting tools.

### [Schelling Segregation Model (Experimental)](https://github.com/projectmesa/mesa-examples/tree/main/examples/schelling_experimental)

Schelling segregation model with the experimental Juptyer notebook visualization feature.

### [Shape Example](https://github.com/projectmesa/mesa-examples/tree/main/examples/shape_example)

Example of grid display and direction showing agents in the form of arrow-head shape.

## GIS Examples

### Vector Data

- [GeoSchelling Model (Polygons)](https://github.com/projectmesa/mesa-examples/tree/main/gis/geo_schelling)
- [GeoSchelling Model (Points & Polygons)](https://github.com/projectmesa/mesa-examples/tree/main/gis/geo_schelling_points)
- [GeoSIR Epidemics Model](https://github.com/projectmesa/mesa-examples/tree/main/gis/geo_sir)
- [Agents and Networks Model](https://github.com/projectmesa/mesa-examples/tree/main/gis/agents_and_networks)

### Raster Data

- [Rainfall Model](https://github.com/projectmesa/mesa-examples/tree/main/gis/rainfall)
- [Urban Growth Model](https://github.com/projectmesa/mesa-examples/tree/main/gis/urban_growth)

### Raster and Vector Data Overlay

- [Population Model](https://github.com/projectmesa/mesa-examples/tree/main/gis/population)

## Other Examples

### [El Farol Model](https://github.com/projectmesa/mesa-examples/tree/main/examples/el_farol)

This folder contains an implementation of El Farol restaurant model. Agents (restaurant customers) decide whether to go to the restaurant or not based on their memory and reward from previous trials. Implications from the model have been used to explain how individual decision-making affects overall performance and fluctuation.

### [Schelling Model with Caching and Replay](https://github.com/projectmesa/mesa-examples/tree/main/examples/caching_and_replay)

This example applies caching on the Mesa [Schelling](https://github.com/projectmesa/mesa-examples/tree/main/examples/schelling) example. It enables a simulation run to be "cached" or in other words recorded. The recorded simulation run is persisted on the local file system and can be replayed at any later point.
Loading
Loading