Skip to content

Commit ceb03c7

Browse files
authored
Include main examples readme in docs (#2448)
1 parent 1a29aa4 commit ceb03c7

File tree

5 files changed

+27
-40
lines changed

5 files changed

+27
-40
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
benchmarks/**/*.pickle
33

44
# exampledocs
5-
docs/examples/*.md
5+
docs/examples/*
6+
docs/example.md
67

78
# Byte-compiled / optimized / DLL files
89
__pycache__/

docs/conf.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,20 @@ def setup_examples_pages():
316316
# create md files for all examples
317317
# check what examples exist
318318
examples_folder = osp.abspath(osp.join(HERE, "..", "mesa", "examples"))
319-
basic_examples = [f.path for f in os.scandir(osp.join(examples_folder, "basic")) if f.is_dir() and not f.name.startswith("__") ]
320-
advanced_examples = [f.path for f in os.scandir(osp.join(examples_folder, "advanced")) if f.is_dir() and not f.name.startswith("__")]
319+
basic_examples = [("basic", f.path) for f in os.scandir(osp.join(examples_folder, "basic")) if f.is_dir() and not f.name.startswith("__") ]
320+
advanced_examples = [("advanced", f.path) for f in os.scandir(osp.join(examples_folder, "advanced")) if f.is_dir() and not f.name.startswith("__")]
321321
examples = basic_examples + advanced_examples
322322

323323
with open(os.path.join(HERE, "example_template.txt")) as fh:
324324
template = string.Template(fh.read())
325325

326-
pathlib.Path(os.path.join(HERE, "examples")).mkdir(parents=True, exist_ok=True)
326+
root_folder = pathlib.Path(os.path.join(HERE, "examples"))
327+
root_folder.mkdir(parents=True, exist_ok=True)
328+
pathlib.Path(os.path.join(root_folder, "basic")).mkdir(parents=True, exist_ok=True)
329+
pathlib.Path(os.path.join(root_folder, "advanced")).mkdir(parents=True, exist_ok=True)
327330

328331
examples_md = []
329-
for example in examples:
332+
for kind, example in examples:
330333
base_name = os.path.basename(os.path.normpath(example))
331334

332335
agent_filename = os.path.join(example, "agents.py")
@@ -337,17 +340,21 @@ def setup_examples_pages():
337340
md_filename = f"{base_name}.md"
338341
examples_md.append(base_name)
339342

340-
md_filepath = os.path.join(HERE, "examples", md_filename)
343+
md_filepath = os.path.join(HERE, "examples", kind, md_filename)
341344
write_example_md_file(agent_filename, model_filename, readme_filename, app_filename, md_filepath, template)
342345

343346
# create overview of examples.md
344347
with open(os.path.join(HERE, "examples_overview_template.txt")) as fh:
345348
template = string.Template(fh.read())
346349

350+
with open(os.path.join(examples_folder, "README.md")) as fh:
351+
readme_md = fh.read()
352+
347353
with open(os.path.join(HERE, "examples.md"), "w") as fh:
348354
content = template.substitute(
349355
dict(
350-
examples="\n".join([f"{' '.join(base_name.split('_'))} </examples/{base_name}>" for base_name in examples_md]),
356+
readme=readme_md,
357+
# examples="\n".join([f"{' '.join(base_name.split('_'))} </examples/{base_name}>" for base_name in examples_md]),
351358
)
352359
)
353360
fh.write(content)

docs/examples.md

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11

2-
# Examples
2+
$readme
33

4-
5-
```{toctree}
6-
:maxdepth: 1
7-
8-
$examples
9-
10-
```

mesa/examples/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
# Mesa core examples
2-
This folder contains a collection of example models built using Mesa. These core models are maintained by the Mesa team and are intended to demonstrate the capabilities of Mesa.
2+
These examples are a collection of classic agent based models built using Mesa. These core examples are maintained by the Mesa team and are intended to demonstrate the capabilities of Mesa.
33

44
More user examples and showcases can be found in the [mesa-examples](https://github.com/projectmesa/mesa-examples) repository.
55

66
## Basic Examples
77
The basic examples are relatively simple and only use stable Mesa features. They are good starting points for learning how to use Mesa.
88

9-
### [Boltzmann Wealth Model](basic/boltzmann_wealth_model)
9+
### [Boltzmann Wealth Model](examples/basic/boltzmann_wealth_model)
1010
Completed code to go along with the [tutorial](https://mesa.readthedocs.io/latest/tutorials/intro_tutorial.html) on making a simple model of how a highly-skewed wealth distribution can emerge from simple rules.
1111

12-
### [Boids Flockers Model](basic/boid_flockers)
12+
### [Boids Flockers Model](examples/basic/boid_flockers)
1313
[Boids](https://en.wikipedia.org/wiki/Boids)-style flocking model, demonstrating the use of agents moving through a continuous space following direction vectors.
1414

15-
### [Conway's Game of Life](basic/conways_game_of_life)
15+
### [Conway's Game of Life](examples/basic/conways_game_of_life)
1616
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.
1717

18-
### [Schelling Segregation Model](basic/schelling)
18+
### [Schelling Segregation Model](examples/basic/schelling)
1919
Mesa implementation of the classic [Schelling segregation](http://nifty.stanford.edu/2014/mccown-schelling-model-segregation/) model.
2020

21-
### [Virus on a Network Model](basic/virus_on_network)
21+
### [Virus on a Network Model](examples/basic/virus_on_network)
2222
This model is based on the NetLogo [Virus on a Network](https://ccl.northwestern.edu/netlogo/models/VirusonaNetwork) model.
2323

2424
## Advanced Examples
2525
The advanced examples are more complex and may use experimental Mesa features. They are good starting points for learning how to build more complex models.
2626

27-
### [Epstein Civil Violence Model](advanced/epstein_civil_violence)
28-
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.
27+
### [Epstein Civil Violence Model](examples/advanced/epstein_civil_violence)
28+
Joshua Epstein's [model](https://www.pnas.org/doi/10.1073/pnas.092080199) of how a decentralized uprising can be suppressed or reach a critical mass of support.
2929

30-
### [Demographic Prisoner's Dilemma on a Grid](advanced/pd_grid)
30+
### [Demographic Prisoner's Dilemma on a Grid](examples/advanced/pd_grid)
3131
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.
3232

33-
### [Sugarscape Model with Traders](advanced/sugarscape_g1mt)
33+
### [Sugarscape Model with Traders](examples/advanced/sugarscape_g1mt)
3434
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 how emergent price equilibrium can happen via decentralized dynamics.
3535

36-
### [Wolf-Sheep Predation Model](advanced/wolf_sheep)
36+
### [Wolf-Sheep Predation Model](examples/advanced/wolf_sheep)
3737
Implementation of an ecological model of predation and reproduction, based on the NetLogo [Wolf Sheep Predation](http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation) model.

0 commit comments

Comments
 (0)