forked from projectmesa/mesa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a simple cookiecutter for new mesa projects
closes projectmesa#521 closes projectmesa#520 Update the mesa cli - rename `mesa run` to `mesa runserver` - add `mesa startproject` to bootstrap a new project
- Loading branch information
1 parent
eb631f3
commit 947a79d
Showing
28 changed files
with
211 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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,8 @@ | ||
{ | ||
"project": "Example Project", | ||
"snake": "{{ cookiecutter.project.lower().replace(' ', '_') }}", | ||
"camel": "{{ cookiecutter.project.title().replace(' ', '') }}", | ||
"agent": "{{ cookiecutter.camel + 'Agent'}}", | ||
"model": "{{ cookiecutter.camel + 'Model'}}", | ||
"description": "Example short description of the project" | ||
} |
This file contains 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,4 @@ | ||
{{cookiecutter.project}} | ||
======================== | ||
|
||
{{cookiecutter.description}} |
This file contains 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,3 @@ | ||
from {{cookiecutter.snake}}.server import server # noqa | ||
|
||
server.launch() |
This file contains 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 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
from setuptools import setup, find_packages | ||
|
||
requires = [ | ||
'mesa' | ||
] | ||
|
||
setup( | ||
name='{{cookiecutter.snake}}', | ||
version='0.0.1', | ||
packages=find_packages(), | ||
install_requires=requires | ||
) |
Empty file.
65 changes: 65 additions & 0 deletions
65
mesa/cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}/model.py
This file contains 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,65 @@ | ||
import random | ||
|
||
from mesa import Agent, Model | ||
from mesa.time import RandomActivation | ||
from mesa.space import MultiGrid | ||
from mesa.datacollection import DataCollector | ||
|
||
|
||
class {{cookiecutter.agent}}(Agent): # noqa | ||
""" | ||
An agent | ||
""" | ||
|
||
def __init__(self, unique_id, model): | ||
""" | ||
Customize the agent | ||
""" | ||
self.unique_id = unique_id | ||
super().__init__(unique_id, model) | ||
|
||
def step(self): | ||
""" | ||
Modify this method to change what an individual agent will do during each step. | ||
Can include logic based on neighbors states. | ||
""" | ||
pass | ||
|
||
|
||
class {{cookiecutter.model}}(Model): | ||
""" | ||
The model class holds the model-level attributes, manages the agents, and generally handles | ||
the global level of our model. | ||
There is only one model-level parameter: how many agents the model contains. When a new model | ||
is started, we want it to populate itself with the given number of agents. | ||
The scheduler is a special model component which controls the order in which agents are activated. | ||
""" | ||
|
||
def __init__(self, num_agents, width, height): | ||
super().__init__() | ||
self.num_agents = num_agents | ||
self.schedule = RandomActivation(self) | ||
self.grid = MultiGrid(width=width, height=height, torus=True) | ||
|
||
for i in range(self.num_agents): | ||
agent = {{cookiecutter.agent}}(i, self) | ||
self.schedule.add(agent) | ||
|
||
x = random.randrange(self.grid.width) | ||
y = random.randrange(self.grid.height) | ||
self.grid.place_agent(agent, (x, y)) | ||
|
||
# example data collector | ||
self.datacollector = DataCollector() | ||
|
||
self.running = True | ||
self.datacollector.collect(self) | ||
|
||
def step(self): | ||
""" | ||
A model step. Used for collecting data and advancing the schedule | ||
""" | ||
self.datacollector.collect(self) | ||
self.schedule.step() |
31 changes: 31 additions & 0 deletions
31
mesa/cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}/server.py
This file contains 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,31 @@ | ||
""" | ||
Configure visualization elements and instantiate a server | ||
""" | ||
|
||
from .model import {{ cookiecutter.model }}, {{ cookiecutter.agent }} # noqa | ||
|
||
from mesa.visualization.ModularVisualization import ModularServer | ||
from mesa.visualization.modules import CanvasGrid, ChartModule | ||
|
||
|
||
def circle_portrayal_example(agent): | ||
if agent is None: | ||
return | ||
|
||
portrayal = {"Shape": "circle", | ||
"Filled": "true", | ||
"Layer": 0, | ||
"r": 0.5, | ||
"Color": "Pink"} | ||
return portrayal | ||
|
||
|
||
canvas_element = CanvasGrid(circle_portrayal_example, 20, 20, 500, 500) | ||
chart_element = ChartModule([{"Label": "{{ cookiecutter.camel }}", "Color": "Pink"}]) | ||
|
||
model_kwargs = {"num_agents": 10, | ||
"width": 10, | ||
"height": 10} | ||
|
||
server = ModularServer({{ cookiecutter.model }}, [canvas_element, chart_element], # noqa | ||
"{{ cookiecutter.camel }}", model_kwargs) |
Oops, something went wrong.