Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.20
rev: v0.16.1
hooks:
# Run the linter.
- id: ruff
Expand All @@ -25,15 +25,15 @@ repos:
- id: check-toml
- id: check-yaml
- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
rev: v2.4.3
hooks:
- id: codespell
args: [
"--ignore-words",
".codespellignore",
]
- repo: https://github.com/DavidAnson/markdownlint-cli2 # For formatting markdown for documentation
rev: v0.23.0
rev: v0.23.2
hooks:
- id: markdownlint-cli2
args: [
Expand Down
12 changes: 6 additions & 6 deletions docs/general/tutorials/3_advanced_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ def __init__(
self.datacollector = DataCollector(
model=self,
model_reporters={
"mean_sugar": lambda m: 0.0
if len(m.sets[0]) == 0
else float(m.sets[0].df["sugar"].mean()),
"total_sugar": lambda m: float(m.sets[0].df["sugar"].sum())
if len(m.sets[0])
else 0.0,
"mean_sugar": lambda m: (
0.0 if len(m.sets[0]) == 0 else float(m.sets[0].df["sugar"].mean())
),
"total_sugar": lambda m: (
float(m.sets[0].df["sugar"].sum()) if len(m.sets[0]) else 0.0
),
"agents_alive": lambda m: float(len(m.sets[0])) if len(m.sets) else 0.0,
"gini": gini,
"corr_sugar_metabolism": corr_sugar_metabolism,
Expand Down
5 changes: 3 additions & 2 deletions docs/general/tutorials/4_datacollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def __init__(self, n: int):
},
storage="memory", # we'll switch this per example
storage_uri=None,
trigger=lambda m: m.steps % 2
== 0, # collect every 2 steps via conditional_collect
trigger=lambda m: (
m.steps % 2 == 0
), # collect every 2 steps via conditional_collect
reset_memory=True,
)

Expand Down
12 changes: 6 additions & 6 deletions examples/sugarscape_ig/backend_frames/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def __init__(
self.datacollector = DataCollector(
model=self,
model_reporters={
"mean_sugar": lambda m: 0.0
if len(m.sets[0]) == 0
else float(m.sets[0].df["sugar"].mean()),
"total_sugar": lambda m: float(m.sets[0].df["sugar"].sum())
if len(m.sets[0])
else 0.0,
"mean_sugar": lambda m: (
0.0 if len(m.sets[0]) == 0 else float(m.sets[0].df["sugar"].mean())
),
"total_sugar": lambda m: (
float(m.sets[0].df["sugar"].sum()) if len(m.sets[0]) else 0.0
),
"agents_alive": lambda m: float(len(m.sets[0])) if len(m.sets) else 0.0,
"gini": gini,
"corr_sugar_metabolism": corr_sugar_metabolism,
Expand Down
14 changes: 8 additions & 6 deletions examples/sugarscape_ig/backend_mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ def __init__(
# are comparable across backends.
self.datacollector = DataCollector(
model_reporters={
"mean_sugar": lambda m: float(np.mean([a.sugar for a in m.agent_list]))
if m.agent_list
else 0.0,
"total_sugar": lambda m: float(sum(a.sugar for a in m.agent_list))
if m.agent_list
else 0.0,
"mean_sugar": lambda m: (
float(np.mean([a.sugar for a in m.agent_list]))
if m.agent_list
else 0.0
),
"total_sugar": lambda m: (
float(sum(a.sugar for a in m.agent_list)) if m.agent_list else 0.0
),
"agents_alive": lambda m: float(len(m.agent_list)),
"gini": lambda m: gini(a.sugar for a in m.agent_list),
"corr_sugar_metabolism": lambda m: corr_sugar_metabolism(m),
Expand Down
Loading