Skip to content
Open
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
68 changes: 68 additions & 0 deletions .github/workflows/scripts/validate_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Validate metadata.toml files in all examples."""

import sys
from pathlib import Path

import tomllib

REQUIRED_FIELDS = [
"title",
"abstract",
"authors",
"domain",
"space",
"time",
"complexity",
"keywords",
"mesa",
]

ALLOWED_SPACE = {"Grid", "Network", "Continuous", "None"}
ALLOWED_TIME = {"Discrete", "Continuous"}
ALLOWED_COMPLEXITY = {"Basic", "Advanced"}

errors = []
examples_dir = Path("examples")

metadata_files = list(examples_dir.glob("*/metadata.toml"))

if not metadata_files:
print("No metadata.toml files found.")
sys.exit(0)

for path in metadata_files:
example = path.parent.name
with open(path, "rb") as f:
try:
data = tomllib.load(f)
except tomllib.TOMLDecodeError as e:
errors.append(f"{example}: Invalid TOML - {e}")
continue

for field in REQUIRED_FIELDS:
if field not in data:
errors.append(f"{example}: Missing required field '{field}'")

if "space" in data and data["space"] not in ALLOWED_SPACE:
errors.append(
f"{example}: 'space' must be one of {ALLOWED_SPACE}, got '{data['space']}'"
)

if "time" in data and data["time"] not in ALLOWED_TIME:
errors.append(
f"{example}: 'time' must be one of {ALLOWED_TIME}, got '{data['time']}'"
)

if "complexity" in data and data["complexity"] not in ALLOWED_COMPLEXITY:
errors.append(
f"{example}: 'complexity' must be one of {ALLOWED_COMPLEXITY}, "
f"got '{data['complexity']}'"
)

if errors:
print("Metadata validation FAILED:")
for e in errors:
print(f" - {e}")
sys.exit(1)

print(f"All {len(metadata_files)} metadata.toml files are valid.")
24 changes: 24 additions & 0 deletions .github/workflows/validate_metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Validate Example Metadata

on:
pull_request:
paths:
- 'examples/**/metadata.toml'
- '.github/workflows/validate_metadata.yml'

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install tomllib (stdlib in 3.11+)
run: echo "tomllib is built-in"

- name: Validate all metadata.toml files
run: python scripts/validate_metadata.py
3 changes: 2 additions & 1 deletion examples/deffuant_weisbuch/deffuant_weisbuch/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def step(self):
less than the confidence threshold, both agents update opinion values
symmetrically.
"""
agent_list = self.agents.to_list()
agent_list = list(self.agents)
# this is fix by vanya
for _ in range(self.n):
agent_a, agent_b = self.random.sample(agent_list, 2)
self.attempted_interactions += 1
Expand Down
307 changes: 187 additions & 120 deletions examples/forest_fire/Forest Fire Model.ipynb

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions examples/forest_fire/forest_fire/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
title = "Forest Fire Model"

abstract = """
A simple cellular automaton model of fire spreading through a forest.
Trees grow randomly, and fire spreads to neighboring trees. Demonstrates
self-organized criticality and emergent behavior from simple local rules.
"""

authors = ["Wilensky, U."]

domain = ["ecology", "complex systems"]

space = "Grid"

time = "Discrete"

complexity = "Basic"

keywords = ["forest fire", "cellular automaton", "self-organized criticality", "fire spread"]

mesa = ">=3.0"

doi = ""