Skip to content

Commit aa839b9

Browse files
authored
Add module-level docstring to experimental features (#2532)
* Extend DEVS module-level docstring * Extend Observables module-level docstring * Extend Cell Space module-level docstring * Add Experimental module-level docstring
1 parent 712c4ad commit aa839b9

18 files changed

+241
-24
lines changed

.codespellignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ ue
77
fpr
88
falsy
99
assertIn
10+
nD

mesa/experimental/__init__.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
"""Experimental init."""
1+
"""Experimental features package for Mesa.
2+
3+
This package contains modules that are under active development and testing. These
4+
features are provided to allow early access and feedback from the Mesa community, but
5+
their APIs may change between releases without following semantic versioning.
6+
7+
Current experimental modules:
8+
cell_space: Alternative API for discrete spaces with cell-centric functionality
9+
devs: Discrete event simulation system for scheduling events at arbitrary times
10+
mesa_signals: Reactive programming capabilities for tracking state changes
11+
12+
Notes:
13+
- Features in this package may be changed or removed without notice
14+
- APIs are not guaranteed to be stable between releases
15+
- Features graduate from experimental status once their APIs are stabilized
16+
"""
217

318
from mesa.experimental import cell_space, devs, mesa_signals
419

mesa/experimental/cell_space/__init__.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
"""Cell spaces.
1+
"""Cell spaces for active, property-rich spatial modeling in Mesa.
22
3-
Cell spaces offer an alternative API for discrete spaces. It is experimental and under development. The API is more
4-
expressive that the default grids available in `mesa.space`.
3+
Cell spaces extend Mesa's spatial modeling capabilities by making the space itself active -
4+
each position (cell) can have properties and behaviors rather than just containing agents.
5+
This enables more sophisticated environmental modeling and agent-environment interactions.
56
7+
Key components:
8+
- Cells: Active positions that can have properties and contain agents
9+
- CellAgents: Agents that understand how to interact with cells
10+
- Spaces: Different cell organization patterns (grids, networks, etc.)
11+
- PropertyLayers: Efficient property storage and manipulation
12+
13+
This is particularly useful for models where the environment plays an active role,
14+
like resource growth, pollution diffusion, or infrastructure networks. The cell
15+
space system is experimental and under active development.
616
"""
717

818
from mesa.experimental.cell_space.cell import Cell

mesa/experimental/cell_space/cell.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
"""The Cell in a cell space."""
1+
"""Cells are positions in space that can have properties and contain agents.
2+
3+
A cell represents a location that can:
4+
- Have properties (like temperature or resources)
5+
- Track and limit the agents it contains
6+
- Connect to neighboring cells
7+
- Provide neighborhood information
8+
9+
Cells form the foundation of the cell space system, enabling rich spatial
10+
environments where both location properties and agent behaviors matter. They're
11+
useful for modeling things like varying terrain, infrastructure capacity, or
12+
environmental conditions.
13+
"""
214

315
from __future__ import annotations
416

mesa/experimental/cell_space/cell_agent.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
"""An agent with movement methods for cell spaces."""
1+
"""Agents that understand how to exist in and move through cell spaces.
2+
3+
Provides specialized agent classes that handle cell occupation, movement, and
4+
proper registration:
5+
- CellAgent: Mobile agents that can move between cells
6+
- FixedAgent: Immobile agents permanently fixed to cells
7+
- Grid2DMovingAgent: Agents with grid-specific movement capabilities
8+
9+
These classes ensure consistent agent-cell relationships and proper state management
10+
as agents move through the space. They can be used directly or as examples for
11+
creating custom cell-aware agents.
12+
"""
213

314
from __future__ import annotations
415

mesa/experimental/cell_space/cell_collection.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
"""CellCollection class."""
1+
"""Collection class for managing and querying groups of cells.
2+
3+
The CellCollection class provides a consistent interface for operating on multiple
4+
cells, supporting:
5+
- Filtering and selecting cells based on conditions
6+
- Random cell and agent selection
7+
- Access to contained agents
8+
- Group operations
9+
10+
This is useful for implementing area effects, zones, or any operation that needs
11+
to work with multiple cells as a unit. The collection handles efficient iteration
12+
and agent access across cells. The class is used throughout the cell space
13+
implementation to represent neighborhoods, selections, and other cell groupings.
14+
"""
215

316
from __future__ import annotations
417

mesa/experimental/cell_space/discrete_space.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
"""DiscreteSpace base class."""
1+
"""Base class for building cell-based spatial environments.
2+
3+
DiscreteSpace provides the core functionality needed by all cell-based spaces:
4+
- Cell creation and tracking
5+
- Agent-cell relationship management
6+
- Property layer support
7+
- Random selection capabilities
8+
- Capacity management
9+
10+
This serves as the foundation for specific space implementations like grids
11+
and networks, ensuring consistent behavior and shared functionality across
12+
different space types. All concrete cell space implementations (grids, networks, etc.)
13+
inherit from this class.
14+
"""
215

316
from __future__ import annotations
417

mesa/experimental/cell_space/grid.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
"""Various Grid Spaces."""
1+
"""Grid-based cell space implementations with different connection patterns.
2+
3+
Provides several grid types for organizing cells:
4+
- OrthogonalMooreGrid: 8 neighbors in 2D, (3^n)-1 in nD
5+
- OrthogonalVonNeumannGrid: 4 neighbors in 2D, 2n in nD
6+
- HexGrid: 6 neighbors in hexagonal pattern (2D only)
7+
8+
Each grid type supports optional wrapping (torus) and cell capacity limits.
9+
Choose based on how movement and connectivity should work in your model -
10+
Moore for unrestricted movement, Von Neumann for orthogonal-only movement,
11+
or Hex for more uniform distances.
12+
"""
213

314
from __future__ import annotations
415

mesa/experimental/cell_space/network.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
"""A Network grid."""
1+
"""Network-based cell space using arbitrary connection patterns.
2+
3+
Creates spaces where cells connect based on network relationships rather than
4+
spatial proximity. Built on NetworkX graphs, this enables:
5+
- Arbitrary connectivity patterns between cells
6+
- Graph-based neighborhood definitions
7+
- Logical rather than physical distances
8+
- Dynamic connectivity changes
9+
- Integration with NetworkX's graph algorithms
10+
11+
Useful for modeling systems like social networks, transportation systems,
12+
or any environment where connectivity matters more than physical location.
13+
"""
214

315
from random import Random
416
from typing import Any

mesa/experimental/cell_space/property_layer.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
"""This module provides functionality for working with property layers in grids."""
1+
"""Efficient storage and manipulation of cell properties across spaces.
2+
3+
PropertyLayers provide a way to associate properties with cells in a space efficiently.
4+
The module includes:
5+
- PropertyLayer class for managing grid-wide properties
6+
- Property access descriptors for cells
7+
- Batch operations for property modification
8+
- Property-based cell selection
9+
- Integration with numpy for efficient operations
10+
11+
This system separates property storage from cells themselves, enabling
12+
fast bulk operations and sophisticated property-based behaviors while
13+
maintaining an intuitive interface through cell attributes. Properties
14+
can represent environmental factors, cell states, or any other grid-wide
15+
attributes.
16+
"""
217

318
import warnings
419
from collections.abc import Callable, Sequence

mesa/experimental/cell_space/voronoi.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
"""Support for Voronoi meshed grids."""
1+
"""Cell spaces based on Voronoi tessellation around seed points.
2+
3+
Creates irregular spatial divisions by building cells around seed points,
4+
where each cell contains the area closer to its seed than any other.
5+
Features:
6+
- Organic-looking spaces from point sets
7+
- Automatic neighbor determination
8+
- Area-based cell capacities
9+
- Natural regional divisions
10+
11+
Useful for models requiring irregular but mathematically meaningful spatial
12+
divisions, like territories, service areas, or natural regions.
13+
"""
214

315
from collections.abc import Sequence
416
from itertools import combinations

mesa/experimental/devs/__init__.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
"""Support for event scheduling."""
1+
"""Core event management functionality for Mesa's discrete event simulation system.
2+
3+
This module provides the foundational data structures and classes needed for event-based
4+
simulation in Mesa. The EventList class is a priority queue implementation that maintains
5+
simulation events in chronological order while respecting event priorities. Key features:
6+
7+
- Priority-based event ordering
8+
- Weak references to prevent memory leaks from canceled events
9+
- Efficient event insertion and removal using a heap queue
10+
- Support for event cancellation without breaking the heap structure
11+
12+
The module contains three main components:
13+
- Priority: An enumeration defining event priority levels (HIGH, DEFAULT, LOW)
14+
- SimulationEvent: A class representing individual events with timing and execution details
15+
- EventList: A heap-based priority queue managing the chronological ordering of events
16+
17+
The implementation supports both pure discrete event simulation and hybrid approaches
18+
combining agent-based modeling with event scheduling.
19+
"""
220

321
from .eventlist import Priority, SimulationEvent
422
from .simulator import ABMSimulator, DEVSimulator

mesa/experimental/devs/eventlist.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
"""Eventlist which is at the core of event scheduling."""
1+
"""Core event management functionality for Mesa's discrete event simulation system.
2+
3+
This module provides the foundational data structures and classes needed for event-based
4+
simulation in Mesa. The EventList class is a priority queue implementation that maintains
5+
simulation events in chronological order while respecting event priorities. Key features:
6+
7+
- Priority-based event ordering
8+
- Weak references to prevent memory leaks from canceled events
9+
- Efficient event insertion and removal using a heap queue
10+
- Support for event cancellation without breaking the heap structure
11+
12+
The module contains three main components:
13+
- Priority: An enumeration defining event priority levels (HIGH, DEFAULT, LOW)
14+
- SimulationEvent: A class representing individual events with timing and execution details
15+
- EventList: A heap-based priority queue managing the chronological ordering of events
16+
17+
The implementation supports both pure discrete event simulation and hybrid approaches
18+
combining agent-based modeling with event scheduling.
19+
"""
220

321
from __future__ import annotations
422

mesa/experimental/devs/simulator.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
"""Provides several simulator classes.
2-
3-
A Simulator is responsible for executing a simulation model. It controls time advancement and enables event scheduling.
4-
5-
1+
"""Simulator implementations for different time advancement approaches in Mesa.
2+
3+
This module provides simulator classes that control how simulation time advances and how
4+
events are executed. It supports both discrete-time and continuous-time simulations through
5+
three main classes:
6+
7+
- Simulator: Base class defining the core simulation control interface
8+
- ABMSimulator: A simulator for agent-based models that combines fixed time steps with
9+
event scheduling. Uses integer time units and automatically schedules model.step()
10+
- DEVSimulator: A pure discrete event simulator using floating-point time units for
11+
continuous time simulation
12+
13+
Key features:
14+
- Flexible time units (integer or float)
15+
- Event scheduling using absolute or relative times
16+
- Priority-based event execution
17+
- Support for running simulations for specific durations or until specific end times
18+
19+
The simulators enable Mesa models to use traditional time-step based approaches, pure
20+
event-driven approaches, or hybrid combinations of both.
621
"""
722

823
from __future__ import annotations

mesa/experimental/mesa_signals/__init__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
"""Functionality for Observables."""
1+
"""Mesa Signals (Observables) package that provides reactive programming capabilities.
2+
3+
This package enables tracking changes to properties and state in Mesa models through a
4+
reactive programming paradigm. It enables building models where components can observe
5+
and react to changes in other components' state.
6+
7+
The package provides the core Observable classes and utilities needed to implement
8+
reactive patterns in agent-based models. This includes capabilities for watching changes
9+
to attributes, computing derived values, and managing collections that emit signals
10+
when modified.
11+
"""
212

313
from .mesa_signal import All, Computable, Computed, HasObservables, Observable
414
from .observable_collections import ObservableList

mesa/experimental/mesa_signals/mesa_signal.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
"""Core classes for Observables."""
1+
"""Core implementation of Mesa's reactive programming system.
2+
3+
This module provides the foundational classes for Mesa's observable/reactive programming
4+
functionality:
5+
6+
- BaseObservable: Abstract base class defining the interface for all observables
7+
- Observable: Main class for creating observable properties that emit change signals
8+
- Computable: Class for properties that automatically update based on other observables
9+
- HasObservables: Mixin class that enables an object to contain and manage observables
10+
- All: Helper class for subscribing to all signals from an observable
11+
12+
The module implements a robust reactive system where changes to observable properties
13+
automatically trigger updates to dependent computed values and notify subscribed
14+
observers. This enables building models with complex interdependencies while maintaining
15+
clean separation of concerns.
16+
"""
217

318
from __future__ import annotations
419

mesa/experimental/mesa_signals/observable_collections.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
"""This module defines observable collections classes.
1+
"""Observable collection types that emit signals when modified.
22
3-
Observable collections behave like Observable but then for collections.
3+
This module extends Mesa's reactive programming capabilities to collection types like
4+
lists. Observable collections emit signals when items are added, removed, or modified,
5+
allowing other components to react to changes in the collection's contents.
46
7+
The module provides:
8+
- ObservableList: A list descriptor that emits signals on modifications
9+
- SignalingList: The underlying list implementation that manages signal emission
510
11+
These classes enable building models where components need to track and react to
12+
changes in collections of agents, resources, or other model elements.
613
"""
714

815
from collections.abc import Iterable, MutableSequence

mesa/experimental/mesa_signals/signals_util.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
"""helper functions and classes for mesa signals."""
1+
"""Utility functions and classes for Mesa's signals implementation.
2+
3+
This module provides helper functionality used by Mesa's reactive programming system:
4+
5+
- AttributeDict: A dictionary subclass that allows attribute-style access to its contents
6+
- create_weakref: Helper function to properly create weak references to different types
7+
8+
These utilities support the core signals implementation by providing reference
9+
management and convenient data structures used throughout the reactive system.
10+
"""
211

312
import weakref
413

0 commit comments

Comments
 (0)