mesa
Use Mesa for agent-based simulation models, spatial ABM environments, experiment data collection, scenarios, and Solara visualization workflows.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- mesa
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use Mesa for agent-based simulation models, spatial ABM environments, experiment data collection, scenarios, and Solara visualization workflows.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/examples-index.md4.4 KB
- 参考文档references/repo-provenance.md2.1 KB
- 参考文档references/repo-routing-metadata.json396 B
- 参考文档references/troubleshooting.md3.8 KB
- 脚本scripts/check_mesa_install.py6.0 KB
03 SKILL.md 正文
Mesa
Use this repo skill when a task involves Mesa, the Python agent-based modeling framework: building ABM models, managing agents, adding spaces, collecting outputs, running scenarios, or creating browser/notebook visualizations.
Install and import
Mesa requires Python 3.12 or newer in this snapshot.
python -m pip install -U mesa
# For Mesa 4 pre-releases when a task depends on APIs from this skill:
python -m pip install -U --pre mesa
# Recommended optional stacks:
python -m pip install -U "mesa[network]" # Network spaces
python -m pip install -U "mesa[viz]" # Solara/matplotlib/altair visualization
python -m pip install -U "mesa[rec]" # network + viz recommended extras
Minimal import check:
import mesa
from mesa import Agent, DataCollector, Model
from mesa.discrete_space import OrthogonalMooreGrid
Run scripts/check_mesa_install.py for a safe JSON probe of the installed package and optional extras.
Route by task
| Task intent | Read |
|---|---|
Define Model and Agent classes, create agents, activate AgentSets, seed RNGs, schedule events, run time, remove agents |
model-core |
| Choose grids/cells/network/Voronoi/continuous spaces, move cell agents, use property layers, debug capacity or coordinates | spaces |
| Collect model/agent/table outputs, create DataFrames, run scenarios, use experimental recorders/actions/states/signals | analysis-experiments |
Build or debug SolaraViz, SpaceRenderer, component builders, portrayal styles, plots, user parameters, visualization extras |
visualization |
High-signal Mesa rules
- In Mesa 4,
Agent.__init__(model)automatically registers the agent and assignsunique_id. Do not reassign or manually mutatemodel.agents. Model(rng=...)creates bothmodel.rngandmodel.random; passrngfor reproducibility unless aScenarioinstance already owns the RNG.Model.step()is scheduled by default every 1.0 time units; userun_for()orrun_until()to process the event queue.- Prefer
model.agents.do(...),shuffle_do(...),map(...),select(...),groupby(...), andagg(...)over custom scheduler objects. - For new spatial models, use
mesa.discrete_spaceormesa.experimental.continuous_space, not legacymesa.spaceAPIs. DataCollectorsupports model, agent, agent-type, and table outputs; avoid lambdas when the model must be pickle-safe.SolaraVizre-creates models frommodel_params; model constructors must accept keyword arguments matching those parameter keys.
Optional dependency choices
- Core modeling, data collection, grids, Voronoi, and continuous spaces: base
mesainstall. - Network examples or
Networkdefault layouts: installmesa[network]or pass your own graph/layout stack. - Browser/notebook visualization: install
mesa[viz]ormesa[rec]. - Example-library and verification-style runs:
mesa[examples]includes recommended extras and pytest. - Browser end-to-end checks need additional frontend/browser tooling and are not required for ordinary modeling tasks.
References and checks
- references/repo-provenance.md records the source snapshot used to create this skill; read it before deciding whether to refresh the skill for a different checkout or Mesa version.
- references/examples-index.md maps classic Mesa example patterns to the owning sub-skills.
- references/troubleshooting.md covers cross-cutting install, version, optional-extra, and workflow-selection issues.
- Each sub-skill links its own API reference, workflows, troubleshooting guide, and smoke scripts.
Avoid this skill when
- The task is only generic Python, pandas, NumPy, NetworkX, Matplotlib, Altair, or Solara usage without Mesa model objects or Mesa visualization components.
- The task asks for a non-Mesa ABM framework such as NetLogo, Repast, MASON, Agents.jl, or a custom simulator.
- The task is benchmark-scale performance tuning or browser automation infrastructure; this skill records those as long-tail or optional areas, not primary guidance.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).