Skip to content
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

Enforce google docstrings #2294

Merged
merged 52 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d90b0f7
further updates
quaquel Jan 21, 2024
9586490
Update benchmarks/WolfSheep/__init__.py
quaquel Jan 21, 2024
4aaa35d
Merge remote-tracking branch 'upstream/main'
quaquel Feb 21, 2024
d31478c
Merge remote-tracking branch 'upstream/main'
quaquel Apr 22, 2024
6e4c72e
Merge remote-tracking branch 'upstream/main'
quaquel Aug 14, 2024
70fbaf5
Merge remote-tracking branch 'upstream/main'
quaquel Aug 18, 2024
724c8db
Merge remote-tracking branch 'upstream/main'
quaquel Aug 21, 2024
45184a4
Merge remote-tracking branch 'upstream/main'
quaquel Aug 22, 2024
3d75d30
Merge remote-tracking branch 'upstream/main'
quaquel Aug 27, 2024
2759244
Update __init__.py
quaquel Aug 27, 2024
fc8aaea
Merge remote-tracking branch 'upstream/main'
quaquel Aug 28, 2024
1ba465d
Merge remote-tracking branch 'upstream/main'
quaquel Aug 30, 2024
2b5e822
Merge remote-tracking branch 'upstream/main'
quaquel Sep 2, 2024
3847799
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
301d80e
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
fe3d655
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
7d18880
Merge remote-tracking branch 'upstream/main'
quaquel Sep 5, 2024
6b49a3b
Merge remote-tracking branch 'upstream/main'
quaquel Sep 5, 2024
b9909e6
Merge remote-tracking branch 'upstream/main'
quaquel Sep 9, 2024
8ce3d83
Merge remote-tracking branch 'upstream/main'
quaquel Sep 10, 2024
88fbf74
Merge remote-tracking branch 'upstream/main'
quaquel Sep 13, 2024
077aca5
Merge remote-tracking branch 'upstream/main'
quaquel Sep 16, 2024
b93703c
remove methods from class docstrings and make attributes bulleted lists
quaquel Sep 13, 2024
57ea944
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 13, 2024
3a35c98
Update model.py
quaquel Sep 13, 2024
5799214
enforce google docstring
quaquel Sep 16, 2024
10ef7a3
first pass for fixing all ruff issues with enforced google benchmarks
quaquel Sep 16, 2024
e0ef5dc
fix space.py for google docstring standard
quaquel Sep 16, 2024
0fbe32d
ongoing fixes
quaquel Sep 16, 2024
3fd7998
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2024
c6f4f93
fixes to model.py and time.py
quaquel Sep 16, 2024
8224969
further fixes
quaquel Sep 16, 2024
ac06edf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2024
a383ae6
fixes for cellspaces
quaquel Sep 16, 2024
a5e0a7a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2024
a6aec9e
Update utils.py
quaquel Sep 16, 2024
8788b68
Update conf.py
quaquel Sep 16, 2024
6382b94
minor fixes
quaquel Sep 16, 2024
7ae2efc
last outstanding fixes in mesa source code
quaquel Sep 17, 2024
eafed7b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2024
8378a10
start of fixing docstrings in tests
quaquel Sep 17, 2024
6ec4061
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2024
9586b43
remaining test fixes
quaquel Sep 17, 2024
84e2e42
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2024
4766cfe
Update test_batch_run.py
quaquel Sep 17, 2024
29ee1e1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2024
a90367e
fixes for typos
quaquel Sep 17, 2024
209105f
made noqa's more explicit
quaquel Sep 17, 2024
e3b85e0
Update fetch_unlabeled_prs.py
quaquel Sep 17, 2024
b1e6d83
Update wolf_sheep.py
quaquel Sep 17, 2024
42b0a37
fixed all noqa directives
quaquel Sep 17, 2024
d90f648
Update conf.py
quaquel Sep 17, 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
1 change: 1 addition & 0 deletions benchmarks/BoltzmannWealth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""init file for BoltzmannWealth module."""
40 changes: 38 additions & 2 deletions benchmarks/BoltzmannWealth/boltzmann_wealth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# https://github.com/projectmesa/mesa-examples/blob/main/examples/boltzmann_wealth_model_experimental/model.py
"""boltmann wealth model for performance benchmarking.

https://github.com/projectmesa/mesa-examples/blob/main/examples/boltzmann_wealth_model_experimental/model.py
"""

import mesa


def compute_gini(model):
"""Calculate gini for wealth in model.

Args:
model: a Model instance

Returns:
float: gini score

"""
agent_wealths = [agent.wealth for agent in model.agents]
x = sorted(agent_wealths)
n = model.num_agents
Expand All @@ -19,7 +32,15 @@ class BoltzmannWealth(mesa.Model):
"""

def __init__(self, seed=None, n=100, width=10, height=10):
super().__init__()
"""Initializes the model.

Args:
seed: the seed for random number generator
n: the number of agents
width: the width of the grid
height: the height of the grid
"""
super().__init__(seed)
self.num_agents = n
self.grid = mesa.space.MultiGrid(width, height, True)
self.schedule = mesa.time.RandomActivation(self)
Expand All @@ -38,11 +59,18 @@ def __init__(self, seed=None, n=100, width=10, height=10):
self.datacollector.collect(self)

def step(self):
"""Run the model for a single step."""
self.agents.shuffle().do("step")
# collect data
self.datacollector.collect(self)

def run_model(self, n):
"""Run the model for n steps.

Args:
n: the number of steps for which to run the model

"""
for _i in range(n):
self.step()

Expand All @@ -51,17 +79,24 @@ class MoneyAgent(mesa.Agent):
"""An agent with fixed initial wealth."""

def __init__(self, model):
"""Instantiate an agent.

Args:
model: a Model instance
"""
super().__init__(model)
self.wealth = 1

def move(self):
"""Move the agent to a random neighboring cell."""
possible_steps = self.model.grid.get_neighborhood(
self.pos, moore=True, include_center=False
)
new_position = self.random.choice(possible_steps)
self.model.grid.move_agent(self, new_position)

def give_money(self):
"""Give money to a random cell mate."""
cellmates = self.model.grid.get_cell_list_contents([self.pos])
cellmates.pop(
cellmates.index(self)
Expand All @@ -72,6 +107,7 @@ def give_money(self):
self.wealth -= 1

def step(self):
"""Run the agent for 1 step."""
self.move()
if self.wealth > 0:
self.give_money()
1 change: 1 addition & 0 deletions benchmarks/Flocking/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""initi for flocking benchmark model."""
38 changes: 17 additions & 21 deletions benchmarks/Flocking/flocking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
Flockers
=============================================================
A Mesa implementation of Craig Reynolds's Boids flocker model.
"""A Mesa implementation of Craig Reynolds's Boids flocker model.

Uses numpy arrays to represent vectors.
"""

Expand All @@ -11,8 +9,7 @@


class Boid(mesa.Agent):
"""
A Boid-style flocker agent.
"""A Boid-style flocker agent.

The agent follows three behaviors to flock:
- Cohesion: steering towards neighboring agents.
Expand All @@ -36,10 +33,10 @@ def __init__(
separate=0.015,
match=0.05,
):
"""
Create a new Boid flocker agent.
"""Create a new Boid flocker agent.

Args:
model: a Model instance
speed: Distance to move per step.
direction: numpy vector for the Boid's direction of movement.
vision: Radius to look around for nearby Boids.
Expand All @@ -59,10 +56,7 @@ def __init__(
self.match_factor = match

def step(self):
"""
Get the Boid's neighbors, compute the new vector, and move accordingly.
"""

"""Get the Boid's neighbors, compute the new vector, and move accordingly."""
neighbors = self.model.space.get_neighbors(self.pos, self.vision, False)
n = 0
match_vector, separation_vector, cohere = np.zeros((3, 2))
Expand All @@ -84,9 +78,7 @@ def step(self):


class BoidFlockers(mesa.Model):
"""
Flocker model class. Handles agent creation, placement and scheduling.
"""
"""Flocker model class. Handles agent creation, placement and scheduling."""

def __init__(
self,
Expand All @@ -102,18 +94,21 @@ def __init__(
match=0.05,
simulator=None,
):
"""
Create a new Flockers model.
"""Create a new Flockers model.

Args:
seed: seed for random number generator
population: Number of Boids
width, height: Size of the space.
width: the width of the space
height: the height of the space
speed: How fast should the Boids move.
vision: How far around should each Boid look for its neighbors
separation: What's the minimum distance each Boid will attempt to
keep from any other
cohere, separate, match: factors for the relative importance of
separation: What's the minimum distance each Boid will attempt to keep from any other
cohere: the relative importance of matching neighbors' positions'
separate: the relative importance of avoiding close neighbors
match: factors for the relative importance of
the three drives.
simulator: a Simulator Instance
"""
super().__init__(seed=seed)
self.population = population
Expand Down Expand Up @@ -146,6 +141,7 @@ def __init__(
self.schedule.add(boid)

def step(self):
"""Run the model for one step."""
self.schedule.step()


Expand Down
1 change: 1 addition & 0 deletions benchmarks/Schelling/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Schelling separation for performance benchmarking."""
38 changes: 19 additions & 19 deletions benchmarks/Schelling/schelling.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
"""Schelling separation for performance benchmarking."""

from mesa import Model
from mesa.experimental.cell_space import CellAgent, OrthogonalMooreGrid
from mesa.time import RandomActivation


class SchellingAgent(CellAgent):
"""
Schelling segregation agent
"""
"""Schelling segregation agent."""

def __init__(self, model, agent_type, radius, homophily):
"""
Create a new Schelling agent.
"""Create a new Schelling agent.

Args:
x, y: Agent initial location.
agent_type: Indicator for the agent's type (minority=1, majority=0)
model: model instance
agent_type: type of agent (minority=1, majority=0)
radius: size of neighborhood of agent
homophily: fraction of neighbors of the same type that triggers movement
"""
super().__init__(model)
self.type = agent_type
self.radius = radius
self.homophily = homophily

def step(self):
"""Run one step of the agent."""
similar = 0
neighborhood = self.cell.neighborhood(radius=self.radius)
for neighbor in neighborhood.agents:
Expand All @@ -35,9 +38,7 @@ def step(self):


class Schelling(Model):
"""
Model class for the Schelling segregation model.
"""
"""Model class for the Schelling segregation model."""

def __init__(
self,
Expand All @@ -50,16 +51,17 @@ def __init__(
seed=None,
simulator=None,
):
"""
Create a new Schelling model.
"""Create a new Schelling model.

Args:
height, width: Size of the space.
density: Initial Chance for a cell to populated
minority_pc: Chances for an agent to be in minority class
height: height of the grid
width: width of the grid
homophily: Minimum number of agents of same class needed to be happy
radius: Search radius for checking similarity
seed: Seed for Reproducibility
density: Initial Chance for a cell to populated
minority_pc: Chances for an agent to be in minority class
seed: the seed for the random number generator
simulator: a simulator instance
"""
super().__init__(seed=seed)
self.minority_pc = minority_pc
Expand All @@ -85,9 +87,7 @@ def __init__(
self.schedule.add(agent)

def step(self):
"""
Run one step of the model.
"""
"""Run one step of the model."""
self.happy = 0 # Reset counter of happy agents
self.schedule.step()

Expand Down
1 change: 1 addition & 0 deletions benchmarks/WolfSheep/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Wolf-Sheep Predation Model for performance benchmarking."""
Loading
Loading