Skip to content

Convert DiscreteSpace to an Abstract Base Class#3387

Merged
quaquel merged 2 commits intomesa:mainfrom
codebreaker32:make_discrete_space_abc
Feb 28, 2026
Merged

Convert DiscreteSpace to an Abstract Base Class#3387
quaquel merged 2 commits intomesa:mainfrom
codebreaker32:make_discrete_space_abc

Conversation

@codebreaker32
Copy link
Copy Markdown
Collaborator

Summary

This PR Converts DiscreteSpace into a formal Abstract Base Class (abc.ABC) to enforce a strict spatial API contract across all environments. Subclasses are now mandated to implement fundamental spatial hooks like find_nearest_cell and _connect_cells.

Implementation

  • mesa/discrete_space/discrete_space.py: Inherited DiscreteSpace from abc.ABC and applied @abstractmethod decorators to find_nearest_cell and _connect_cells.
  • mesa/discrete_space/grid.py: Raise NotImplementedError in _connect_cells_2d and _connect_cells_nd

Additional Notes

This PR paves the way for the continuous-to-discrete synchronization layer required by Stacked Spaces. See #3268 and #2585 (reply in thread) for discussions

@codebreaker32 codebreaker32 force-pushed the make_discrete_space_abc branch from a68b563 to c3b6adb Compare February 26, 2026 14:01
@github-actions
Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +2.7% [+1.8%, +3.5%] 🔵 -2.1% [-2.6%, -1.5%]
BoltzmannWealth large 🔵 +2.0% [+0.5%, +3.6%] 🔴 +8.1% [+3.9%, +12.0%]
Schelling small 🔵 +1.9% [+1.3%, +2.5%] 🔵 +2.8% [+2.3%, +3.4%]
Schelling large 🔵 -1.3% [-2.6%, +0.3%] 🔵 -2.2% [-7.5%, +3.8%]
WolfSheep small 🔵 -0.9% [-2.1%, +0.4%] 🔵 -0.4% [-1.8%, +1.2%]
WolfSheep large 🔵 -0.2% [-1.6%, +1.3%] 🔵 -3.7% [-5.7%, -1.5%]
BoidFlockers small 🔵 -0.9% [-1.7%, -0.0%] 🔵 +0.1% [-0.4%, +0.7%]
BoidFlockers large 🔵 -1.2% [-2.2%, -0.2%] 🔵 -0.9% [-1.7%, -0.1%]

@codebreaker32 codebreaker32 force-pushed the make_discrete_space_abc branch from c3b6adb to 49f1ac3 Compare February 26, 2026 14:20
@codebreaker32 codebreaker32 force-pushed the make_discrete_space_abc branch from a6a2145 to bb0ecc1 Compare February 26, 2026 14:31
@quaquel quaquel merged commit 9041cab into mesa:main Feb 28, 2026
12 of 15 checks passed
@quaquel quaquel added the enhancement Release notes label label Mar 2, 2026
@codebreaker32 codebreaker32 deleted the make_discrete_space_abc branch March 11, 2026 17:51
@EwoutH EwoutH mentioned this pull request Mar 13, 2026
42 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants