Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move mesa.experimental_cell to mesa.discrete_space #2610

Merged
merged 14 commits into from
Feb 10, 2025
Merged
2 changes: 1 addition & 1 deletion .github/workflows/build_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ jobs:
- name: Test examples
run: |
cd mesa-examples
pytest -rA -Werror -Wdefault::FutureWarning test_examples.py
pytest -rA -Werror -Wdefault::FutureWarning -Wi::DeprecationWarning test_examples.py
1 change: 1 addition & 0 deletions docs/apis/api_main.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ model
agent
time
space
discrete_space
datacollection
batchrunner
visualization
Expand Down
41 changes: 41 additions & 0 deletions docs/apis/discrete_space.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Discrete Space

```{eval-rst}
.. automodule:: mesa.discrete_space.__init__
:members:
```

```{eval-rst}
.. automodule:: mesa.discrete_space.cell
:members:
```

```{eval-rst}
.. automodule:: mesa.discrete_space.cell_agent
:members:
```

```{eval-rst}
.. automodule:: mesa.discrete_space.cell_collection
:members:
```

```{eval-rst}
.. automodule:: mesa.discrete_space.discrete_space
:members:
```

```{eval-rst}
.. automodule:: mesa.discrete_space.grid
:members:
```

```{eval-rst}
.. automodule:: mesa.discrete_space.network
:members:
```

```{eval-rst}
.. automodule:: mesa.discrete_space.voronoi
:members:
```
41 changes: 0 additions & 41 deletions docs/apis/experimental.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,6 @@
# Experimental
This namespace contains experimental features. These are under development, and their API is not necessarily stable.

## Cell Space

```{eval-rst}
.. automodule:: experimental.cell_space.__init__
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.cell
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.cell_agent
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.cell_collection
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.discrete_space
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.grid
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.network
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.voronoi
:members:
```

## Devs

Expand Down
50 changes: 50 additions & 0 deletions mesa/discrete_space/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Cell spaces for active, property-rich spatial modeling in Mesa.

Cell spaces extend Mesa's spatial modeling capabilities by making the space itself active -
each position (cell) can have properties and behaviors rather than just containing agents.
This enables more sophisticated environmental modeling and agent-environment interactions.

Key components:
- Cells: Active positions that can have properties and contain agents
- CellAgents: Agents that understand how to interact with cells
- Spaces: Different cell organization patterns (grids, networks, etc.)
- PropertyLayers: Efficient property storage and manipulation

This is particularly useful for models where the environment plays an active role,
like resource growth, pollution diffusion, or infrastructure networks. The cell
space system is experimental and under active development.
"""

from mesa.discrete_space.cell import Cell
from mesa.discrete_space.cell_agent import (
CellAgent,
FixedAgent,
Grid2DMovingAgent,
)
from mesa.discrete_space.cell_collection import CellCollection
from mesa.discrete_space.discrete_space import DiscreteSpace
from mesa.discrete_space.grid import (
Grid,
HexGrid,
OrthogonalMooreGrid,
OrthogonalVonNeumannGrid,
)
from mesa.discrete_space.network import Network
from mesa.discrete_space.property_layer import PropertyLayer
from mesa.discrete_space.voronoi import VoronoiGrid

__all__ = [
"Cell",
"CellAgent",
"CellCollection",
"DiscreteSpace",
"FixedAgent",
"Grid",
"Grid2DMovingAgent",
"HexGrid",
"Network",
"OrthogonalMooreGrid",
"OrthogonalVonNeumannGrid",
"PropertyLayer",
"VoronoiGrid",
]
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from random import Random
from typing import TYPE_CHECKING

from mesa.experimental.cell_space.cell_agent import CellAgent
from mesa.experimental.cell_space.cell_collection import CellCollection
from mesa.discrete_space.cell_agent import CellAgent
from mesa.discrete_space.cell_collection import CellCollection

if TYPE_CHECKING:
from mesa.agent import Agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mesa.agent import Agent

if TYPE_CHECKING:
from mesa.experimental.cell_space import Cell
from mesa.discrete_space import Cell

Check warning on line 21 in mesa/discrete_space/cell_agent.py

View check run for this annotation

Codecov / codecov/patch

mesa/discrete_space/cell_agent.py#L21

Added line #L21 was not covered by tests


class HasCellProtocol(Protocol):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from typing import TYPE_CHECKING, Generic, TypeVar

if TYPE_CHECKING:
from mesa.experimental.cell_space.cell import Cell
from mesa.experimental.cell_space.cell_agent import CellAgent
from mesa.discrete_space.cell import Cell
from mesa.discrete_space.cell_agent import CellAgent

Check warning on line 27 in mesa/discrete_space/cell_collection.py

View check run for this annotation

Codecov / codecov/patch

mesa/discrete_space/cell_collection.py#L26-L27

Added lines #L26 - L27 were not covered by tests

T = TypeVar("T", bound="Cell")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from typing import Generic, TypeVar

from mesa.agent import AgentSet
from mesa.experimental.cell_space.cell import Cell
from mesa.experimental.cell_space.cell_collection import CellCollection
from mesa.discrete_space.cell import Cell
from mesa.discrete_space.cell_collection import CellCollection

T = TypeVar("T", bound=Cell)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from random import Random
from typing import Any, Generic, TypeVar

from mesa.experimental.cell_space import Cell, DiscreteSpace
from mesa.experimental.cell_space.property_layer import (
from mesa.discrete_space import Cell, DiscreteSpace
from mesa.discrete_space.property_layer import (
HasPropertyLayers,
PropertyDescriptor,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from random import Random
from typing import Any

from mesa.experimental.cell_space.cell import Cell
from mesa.experimental.cell_space.discrete_space import DiscreteSpace
from mesa.discrete_space.cell import Cell
from mesa.discrete_space.discrete_space import DiscreteSpace


class Network(DiscreteSpace[Cell]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import numpy as np

from mesa.experimental.cell_space import Cell
from mesa.discrete_space import Cell

Coordinate = Sequence[int]
T = TypeVar("T", bound=Cell)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import numpy as np

from mesa.experimental.cell_space.cell import Cell
from mesa.experimental.cell_space.discrete_space import DiscreteSpace
from mesa.discrete_space.cell import Cell
from mesa.discrete_space.discrete_space import DiscreteSpace


class Delaunay:
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/epstein_civil_violence/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CitizenState(Enum):
ARRESTED = 3


class EpsteinAgent(mesa.experimental.cell_space.CellAgent):
class EpsteinAgent(mesa.discrete_space.CellAgent):
def update_neighbors(self):
"""
Look around and see who my neighbors are
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/epstein_civil_violence/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
self.movement = movement
self.max_iters = max_iters

self.grid = mesa.experimental.cell_space.OrthogonalVonNeumannGrid(
self.grid = mesa.discrete_space.OrthogonalVonNeumannGrid(
(width, height), capacity=1, torus=True, random=self.random
)

Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/pd_grid/agents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mesa.experimental.cell_space import CellAgent
from mesa.discrete_space import CellAgent


class PDAgent(CellAgent):
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/pd_grid/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mesa
from mesa.discrete_space import OrthogonalMooreGrid
from mesa.examples.advanced.pd_grid.agents import PDAgent
from mesa.experimental.cell_space import OrthogonalMooreGrid


class PdGrid(mesa.Model):
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/sugarscape_g1mt/agents.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math

from mesa.experimental.cell_space import CellAgent
from mesa.discrete_space import CellAgent


# Helper function
Expand Down
4 changes: 2 additions & 2 deletions mesa/examples/advanced/sugarscape_g1mt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import numpy as np

import mesa
from mesa.discrete_space import OrthogonalVonNeumannGrid
from mesa.discrete_space.property_layer import PropertyLayer
from mesa.examples.advanced.sugarscape_g1mt.agents import Trader
from mesa.experimental.cell_space import OrthogonalVonNeumannGrid
from mesa.experimental.cell_space.property_layer import PropertyLayer


# Helper Functions
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/wolf_sheep/agents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mesa.experimental.cell_space import CellAgent, FixedAgent
from mesa.discrete_space import CellAgent, FixedAgent


class Animal(CellAgent):
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/wolf_sheep/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

from mesa import Model
from mesa.datacollection import DataCollector
from mesa.discrete_space import OrthogonalVonNeumannGrid
from mesa.examples.advanced.wolf_sheep.agents import GrassPatch, Sheep, Wolf
from mesa.experimental.cell_space import OrthogonalVonNeumannGrid
from mesa.experimental.devs import ABMSimulator


Expand Down
4 changes: 2 additions & 2 deletions mesa/experimental/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
- Features graduate from experimental status once their APIs are stabilized
"""

from mesa.experimental import cell_space, continuous_space, devs, mesa_signals
from mesa.experimental import continuous_space, devs, mesa_signals

__all__ = ["cell_space", "continuous_space", "devs", "mesa_signals"]
__all__ = ["continuous_space", "devs", "mesa_signals"]
26 changes: 18 additions & 8 deletions mesa/experimental/cell_space/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@
space system is experimental and under active development.
"""

from mesa.experimental.cell_space.cell import Cell
from mesa.experimental.cell_space.cell_agent import (
import warnings

from mesa.discrete_space.cell import Cell
from mesa.discrete_space.cell_agent import (
CellAgent,
FixedAgent,
Grid2DMovingAgent,
)
from mesa.experimental.cell_space.cell_collection import CellCollection
from mesa.experimental.cell_space.discrete_space import DiscreteSpace
from mesa.experimental.cell_space.grid import (
from mesa.discrete_space.cell_collection import CellCollection
from mesa.discrete_space.discrete_space import DiscreteSpace
from mesa.discrete_space.grid import (
Grid,
HexGrid,
OrthogonalMooreGrid,
OrthogonalVonNeumannGrid,
)
from mesa.experimental.cell_space.network import Network
from mesa.experimental.cell_space.property_layer import PropertyLayer
from mesa.experimental.cell_space.voronoi import VoronoiGrid
from mesa.discrete_space.network import Network
from mesa.discrete_space.property_layer import PropertyLayer
from mesa.discrete_space.voronoi import VoronoiGrid

__all__ = [
"Cell",
Expand All @@ -48,3 +50,11 @@
"PropertyLayer",
"VoronoiGrid",
]


warnings.warn(
"you are importing from mesa.experimental.cell_space, "
"all cell spaces have been moved to mesa.discrete_space",
DeprecationWarning,
stacklevel=2,
)
2 changes: 1 addition & 1 deletion mesa/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
All Grid classes (:class:`_Grid`, :class:`SingleGrid`, :class:`MultiGrid`,
:class:`HexGrid`, etc.) are now in maintenance-only mode. While these classes remain
fully supported, new development occurs in the experimental cell space module
(:mod:`mesa.experimental.cell_space`).
(:mod:`mesa.discrete_space`).

The :class:`PropertyLayer` and :class:`ContinuousSpace` classes remain fully supported
and actively developed.
Expand Down
2 changes: 1 addition & 1 deletion mesa/visualization/components/altair_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
with contextlib.suppress(ImportError):
import altair as alt

from mesa.experimental.cell_space import DiscreteSpace, Grid
from mesa.discrete_space import DiscreteSpace, Grid
from mesa.space import ContinuousSpace, _Grid
from mesa.visualization.utils import update_counter

Expand Down
Loading
Loading