Skip to content

Commit 88a6f7c

Browse files
committed
schelling: Switch to Jupyter viz
1 parent 8b2ee78 commit 88a6f7c

File tree

4 files changed

+58
-53
lines changed

4 files changed

+58
-53
lines changed

examples/schelling/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ To install the dependencies use pip and the requirements.txt in this directory.
1616

1717
## How to Run
1818

19-
To run the model interactively, run ``mesa runserver`` in this directory. e.g.
19+
To run the model interactively, in this directory, run the following command
2020

2121
```
22-
$ mesa runserver
22+
$ solara run app.py
2323
```
2424

25-
Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and press Reset, then Run.
25+
Then open your browser to [http://127.0.0.1:8765/](http://127.0.0.1:8765/) and click the Play button.
2626

2727
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/).
2828

@@ -32,10 +32,9 @@ To run the model with the grid displayed as an ASCII text, run `python run_ascii
3232

3333
## Files
3434

35-
* ``run.py``: Launches a model visualization server.
35+
* ``app.py``: Code for the interactive visualization.
3636
* ``run_ascii.py``: Run the model in text mode.
3737
* ``schelling.py``: Contains the agent class, and the overall model class.
38-
* ``server.py``: Defines classes for visualizing the model in the browser via Mesa's modular server, and instantiates a visualization server.
3938
* ``analysis.ipynb``: Notebook demonstrating how to run experiments and parameter sweeps on the model.
4039

4140
## Further Reading

examples/schelling/app.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from mesa_models.experimental import JupyterViz
2+
3+
from model import Schelling
4+
5+
6+
def get_happy_agents(model):
7+
"""
8+
Display a text count of how many happy agents there are.
9+
"""
10+
return f"Happy agents: {model.happy}"
11+
12+
13+
def agent_portrayal(agent):
14+
color = "tab:orange" if agent.type == 0 else "tab:blue"
15+
return {"color": color}
16+
17+
18+
model_params = {
19+
"density": {
20+
"type": "SliderFloat",
21+
"value": 0.8,
22+
"label": "Agent density",
23+
"min": 0.1,
24+
"max": 1.0,
25+
"step": 0.1,
26+
},
27+
"minority_pc": {
28+
"type": "SliderFloat",
29+
"value": 0.2,
30+
"label": "Fraction minority",
31+
"min": 0.0,
32+
"max": 1.0,
33+
"step": 0.05,
34+
},
35+
"homophily": {
36+
"type": "SliderInt",
37+
"value": 3,
38+
"label": "Homophily",
39+
"min": 0,
40+
"max": 8,
41+
"step": 1,
42+
},
43+
"width": 20,
44+
"height": 20,
45+
}
46+
47+
page = JupyterViz(
48+
Schelling,
49+
model_params,
50+
measures=["happy", get_happy_agents],
51+
name="Schelling",
52+
agent_portrayal=agent_portrayal,
53+
)
54+
page

examples/schelling/run.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/schelling/server.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)