This repository compares the classic Wolf-Sheep predator–prey model across three implementations—ABSESpy, a stripped Mesa version, and a pure Python baseline—highlighting runtime performance and code size.
wolf_sheep/
├── absespy/ # ABSESpy implementation & docs
├── pure_python/ # Pure Python implementation & docs
├── mesa_impl/ # Mesa-inspired lightweight implementation
├── benchmark.py # Comparison script
└── __init__.py
tests/
└── test_pure_python_model.py
wolf_sheep/absespy: demonstrates ABSESpy’s scheduling, batch operations, and data collection.wolf_sheep/pure_python: uses only the standard library—grid, scheduling, and metrics are handwritten.wolf_sheep/mesa_impl: concise reimplementation based on Mesa’s example (comments/docstrings removed for line-count parity).
Each implementation exposes the same metrics (n_sheep, n_wolves, population_ratio, grass_coverage) so benchmarks align.
uv sync --all-extras && uv run pytestOptional extras:
- ABSESpy:
uv add abses matplotlib - Mesa:
uv add mesa
uv run python - <<'PY'
from wolf_sheep.pure_python import ModelParams, Simulation
history = Simulation(ModelParams(seed=42, max_steps=200)).run()
print(history[-1])
PYuv run python - <<'PY'
from wolf_sheep.absespy import WolfSheepModel
cfg = {
"model": {"shape": [30, 30], "n_sheep": 50, "n_wolves": 10, "rep_rate": 0.01},
"time": {"end": 200},
}
model = WolfSheepModel(parameters=cfg, seed=42)
model.run_model(steps=200)
print(model.n_sheep, model.n_wolves, model.population_ratio, model.grass_coverage)
PYuv run python - <<'PY'
from wolf_sheep import mesa_run_steps
print(mesa_run_steps(steps=200, seed=42).tail(1))
PYuv run python wolf_sheep/benchmark.py --steps 200 --repeats 3Avg Time (s): mean runtime across repeats.LOC raw/log: raw lines vs. logical lines (comments & docstrings removed).
Example output:
| Framework | Avg Time (s) | LOC raw/log |
|---|---|---|
| pure_python | 0.0437 | 341 / 304 |
| mesa | 0.0441 | 200 / 200 |
| absespy | 2.4238 | 237 / 99 |
n_sheep,n_wolves: population counts.population_ratio: sheep share of total population.grass_coverage: proportion of cells with regrown grass.
MIT License — see LICENSE.