-
Notifications
You must be signed in to change notification settings - Fork 1k
Include examples in readthedocs #2382
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
Closed
Closed
Changes from all commits
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
d90b0f7
further updates
quaquel 9586490
Update benchmarks/WolfSheep/__init__.py
quaquel 4aaa35d
Merge remote-tracking branch 'upstream/main'
quaquel d31478c
Merge remote-tracking branch 'upstream/main'
quaquel 6e4c72e
Merge remote-tracking branch 'upstream/main'
quaquel 70fbaf5
Merge remote-tracking branch 'upstream/main'
quaquel 724c8db
Merge remote-tracking branch 'upstream/main'
quaquel 45184a4
Merge remote-tracking branch 'upstream/main'
quaquel 3d75d30
Merge remote-tracking branch 'upstream/main'
quaquel 2759244
Update __init__.py
quaquel fc8aaea
Merge remote-tracking branch 'upstream/main'
quaquel 1ba465d
Merge remote-tracking branch 'upstream/main'
quaquel 2b5e822
Merge remote-tracking branch 'upstream/main'
quaquel 3847799
Merge remote-tracking branch 'upstream/main'
quaquel 301d80e
Merge remote-tracking branch 'upstream/main'
quaquel fe3d655
Merge remote-tracking branch 'upstream/main'
quaquel 7d18880
Merge remote-tracking branch 'upstream/main'
quaquel 6b49a3b
Merge remote-tracking branch 'upstream/main'
quaquel b9909e6
Merge remote-tracking branch 'upstream/main'
quaquel 8ce3d83
Merge remote-tracking branch 'upstream/main'
quaquel 88fbf74
Merge remote-tracking branch 'upstream/main'
quaquel 077aca5
Merge remote-tracking branch 'upstream/main'
quaquel c771e3b
Merge remote-tracking branch 'upstream/main'
quaquel 3fa0c27
Merge remote-tracking branch 'upstream/main'
quaquel 8fdcf5c
Merge remote-tracking branch 'upstream/main'
quaquel 475b060
Merge remote-tracking branch 'upstream/main'
quaquel fb93261
Merge remote-tracking branch 'upstream/main'
quaquel 86f2f0c
Merge remote-tracking branch 'upstream/main'
quaquel dc1d843
Merge remote-tracking branch 'upstream/main'
quaquel 9857ef1
Merge remote-tracking branch 'upstream/main'
quaquel afdd836
Merge remote-tracking branch 'upstream/main'
quaquel 46c3d13
Merge remote-tracking branch 'upstream/main'
quaquel a5205eb
Merge remote-tracking branch 'upstream/main'
quaquel 59a0413
Merge remote-tracking branch 'upstream/main'
quaquel 56f00af
Merge remote-tracking branch 'upstream/main'
quaquel 135c978
Merge remote-tracking branch 'upstream/main'
quaquel bd4ca35
Merge remote-tracking branch 'upstream/main'
quaquel 5a69aee
Merge remote-tracking branch 'upstream/main'
quaquel 98c4616
Merge remote-tracking branch 'upstream/main'
quaquel 2aa5326
Merge remote-tracking branch 'upstream/main'
quaquel 91e6c0f
Merge remote-tracking branch 'upstream/main'
quaquel 5976962
Merge remote-tracking branch 'upstream/main'
quaquel 95da9b7
Merge remote-tracking branch 'upstream/main'
quaquel 66b70eb
Merge remote-tracking branch 'upstream/main'
quaquel 2d1d391
first test of examples in docs
quaquel dc84b97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 25837e2
Update conf.py
quaquel 6c132d1
Update pyproject.toml
quaquel 1251297
Update conf.py
quaquel 6cb510d
filename updates
quaquel 8f41c33
Update conf.py
quaquel 8bbdb1d
fixes
quaquel 962e794
further updates
quaquel ee662b1
Update examples_overview_template.txt
quaquel fd4bfaa
Update example_template.txt
quaquel 3f0c3e6
add app.py into docs
quaquel 1515f29
Update app.py
quaquel 5759cb3
remove inits from api docs
quaquel f5070b7
updates
quaquel b65fa0a
hacky fix
quaquel 6ec9687
Update visualization_tutorial.ipynb
quaquel 4bbf000
cleanup
quaquel 962c0cc
updated files
quaquel 6ce1e0a
updates
quaquel 14f7104
automated detection of updates to example files
quaquel 2ef80f8
Update conf.py
quaquel ed764f8
Improve Mesa 3.0 beta 1 release notes (#2384)
EwoutH ed43d5c
refactor: Simplify Schelling code (#2353)
rht 962adce
trying to merge
quaquel 824459f
trying to merge
quaquel e0ac4ba
Update index.md
quaquel 8fa9f53
some typo fixes
quaquel 4be7dd2
allways create md files
quaquel f92b37c
Update conf.py
quaquel 5163352
Update conf.py
quaquel 6a34561
Merge branch 'main' into docs
quaquel 04e8763
Update conf.py
quaquel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
$readme_file | ||
|
||
## Agents | ||
|
||
```python | ||
$agent_file | ||
``` | ||
|
||
|
||
## Model | ||
|
||
```python | ||
$model_file | ||
``` | ||
|
||
|
||
## App | ||
|
||
```python | ||
$app_file | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
# Examples | ||
|
||
|
||
```{toctree} | ||
:maxdepth: 1 | ||
|
||
boid flockers </examples/boid_flockers> | ||
virus on network </examples/virus_on_network> | ||
conways game of life </examples/conways_game_of_life> | ||
schelling </examples/schelling> | ||
boltzmann wealth model </examples/boltzmann_wealth_model> | ||
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
# Examples | ||
|
||
|
||
```{toctree} | ||
:maxdepth: 1 | ||
|
||
$examples | ||
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import time | ||
|
||
import altair as alt | ||
import numpy as np | ||
import pandas as pd | ||
import streamlit as st | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still want to use streamlit or update to Solara? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in my view, we standardize all examples on solara |
||
from model import ConwaysGameOfLife | ||
|
||
model = st.title("Conway's Game of Life") | ||
num_ticks = st.slider("Select number of Steps", min_value=1, max_value=100, value=50) | ||
height = st.slider("Select Grid Height", min_value=10, max_value=100, step=10, value=15) | ||
width = st.slider("Select Grid Width", min_value=10, max_value=100, step=10, value=20) | ||
model = ConwaysGameOfLife(height, width) | ||
|
||
col1, col2, col3 = st.columns(3) | ||
status_text = st.empty() | ||
# step_mode = st.checkbox('Run Step-by-Step') | ||
run = st.button("Run Simulation") | ||
|
||
|
||
if run: | ||
tick = time.time() | ||
step = 0 | ||
# init grid | ||
df_grid = pd.DataFrame() | ||
agent_counts = np.zeros((model.grid.width, model.grid.height)) | ||
for x in range(width): | ||
for y in range(height): | ||
df_grid = pd.concat( | ||
[df_grid, pd.DataFrame({"x": [x], "y": [y], "state": [0]})], | ||
ignore_index=True, | ||
) | ||
|
||
heatmap = ( | ||
alt.Chart(df_grid) | ||
.mark_point(size=100) | ||
.encode(x="x", y="y", color=alt.Color("state")) | ||
.interactive() | ||
.properties(width=800, height=600) | ||
) | ||
|
||
# init progress bar | ||
my_bar = st.progress(0, text="Simulation Progress") # progress | ||
placeholder = st.empty() | ||
st.subheader("Agent Grid") | ||
chart = st.altair_chart(heatmap, use_container_width=True) | ||
color_scale = alt.Scale(domain=[0, 1], range=["red", "yellow"]) | ||
for i in range(num_ticks): | ||
model.step() | ||
my_bar.progress((i / num_ticks), text="Simulation progress") | ||
placeholder.text("Step = %d" % i) | ||
for contents, (x, y) in model.grid.coord_iter(): | ||
# print('x:',x,'y:',y, 'state:',contents) | ||
selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)] | ||
df_grid.loc[selected_row.index, "state"] = ( | ||
contents.state | ||
) # random.choice([1,2]) | ||
|
||
heatmap = ( | ||
alt.Chart(df_grid) | ||
.mark_circle(size=100) | ||
.encode(x="x", y="y", color=alt.Color("state", scale=color_scale)) | ||
.interactive() | ||
.properties(width=800, height=600) | ||
) | ||
chart.altair_chart(heatmap) | ||
|
||
time.sleep(0.1) | ||
|
||
tock = time.time() | ||
st.success(f"Simulation completed in {tock - tick:.2f} secs") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Schelling Segregation Model | ||
|
||
## Summary | ||
|
||
The Schelling segregation model is a classic agent-based model, demonstrating how even a mild preference for similar neighbors can lead to a much higher degree of segregation than we would intuitively expect. The model consists of agents on a square grid, where each grid cell can contain at most one agent. Agents come in two colors: red and blue. They are happy if a certain number of their eight possible neighbors are of the same color, and unhappy otherwise. Unhappy agents will pick a random empty cell to move to each step, until they are happy. The model keeps running until there are no unhappy agents. | ||
|
||
By default, the number of similar neighbors the agents need to be happy is set to 3. That means the agents would be perfectly happy with a majority of their neighbors being of a different color (e.g. a Blue agent would be happy with five Red neighbors and three Blue ones). Despite this, the model consistently leads to a high degree of segregation, with most agents ending up with no neighbors of a different color. | ||
|
||
## Installation | ||
|
||
To install the dependencies use pip and the requirements.txt in this directory. e.g. | ||
|
||
``` | ||
$ pip install -r requirements.txt | ||
``` | ||
|
||
## How to Run | ||
|
||
To run the model interactively, in this directory, run the following command | ||
|
||
``` | ||
$ solara run app.py | ||
``` | ||
|
||
Then open your browser to [http://127.0.0.1:8765/](http://127.0.0.1:8765/) and click the Play button. | ||
|
||
To view and run some example model analyses, launch the IPython Notebook and open ``analysis.ipynb``. Visualizing the analysis also requires [matplotlib](http://matplotlib.org/). | ||
|
||
## How to Run without the GUI | ||
|
||
To run the model with the grid displayed as an ASCII text, run `python run_ascii.py` in this directory. | ||
|
||
## Files | ||
|
||
* ``app.py``: Code for the interactive visualization. | ||
* ``schelling.py``: Contains the agent class, and the overall model class. | ||
* ``analysis.ipynb``: Notebook demonstrating how to run experiments and parameter sweeps on the model. | ||
|
||
## Further Reading | ||
|
||
Schelling's original paper describing the model: | ||
|
||
[Schelling, Thomas C. Dynamic Models of Segregation. Journal of Mathematical Sociology. 1971, Vol. 1, pp 143-186.](https://www.stat.berkeley.edu/~aldous/157/Papers/Schelling_Seg_Models.pdf) | ||
|
||
An interactive, browser-based explanation and implementation: | ||
|
||
[Parable of the Polygons](http://ncase.me/polygons/), by Vi Hart and Nicky Case. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.