Skip to content

Remove PropertyLayer and HasPropertyLayers mixin #3340

Merged
quaquel merged 26 commits intomesa:mainfrom
codebreaker32:remove_property_layer
Feb 28, 2026
Merged

Remove PropertyLayer and HasPropertyLayers mixin #3340
quaquel merged 26 commits intomesa:mainfrom
codebreaker32:remove_property_layer

Conversation

@codebreaker32
Copy link
Copy Markdown
Collaborator

@codebreaker32 codebreaker32 commented Feb 18, 2026

This PR removes PropertyLayer and HasPropertyLayers from discrete spaces

Replaces PropertyLayer with raw NumPy arrays stored directly on the grid as _property_layers: dict[str, np.ndarray]. Property access on cells is handled via native property closures attached to the dynamic GridCell class.

Changes:

  • create_property_layer(name, ...) - allocates and attaches a new array
  • add_property_layer(name, array) - attaches an existing array
  • remove_property_layer(name) - removes array and cell accessor
  • select_cells() removed - use numpy directly on property_layers
  • Visualization backends updated to match new APIs
  • Sugarscape and Termites examples updated

Example Usage

grid.create_property_layer("sugar", default_value=0.0)

# grid-level: full array
grid.sugar[:] = 0              
grid.sugar[grid.sugar > 4] = 4 # numpy ops directly

 # cell-level: scalar
cell.sugar = 2.0              

# replaces select_cells type ops
coords = list(zip(*np.where(grid.sugar > 2)))  

@codebreaker32 codebreaker32 marked this pull request as draft February 18, 2026 09:56
@github-actions
Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.7% [-2.1%, -1.4%] 🔵 -0.4% [-0.9%, +0.1%]
BoltzmannWealth large 🔵 -0.5% [-0.8%, -0.2%] 🔵 +1.5% [+1.2%, +1.9%]
Schelling small 🔵 -0.8% [-1.1%, -0.6%] 🔵 +0.4% [+0.3%, +0.5%]
Schelling large 🔵 -3.5% [-4.6%, -2.5%] 🟢 -8.6% [-13.0%, -5.2%]
WolfSheep small 🔵 -2.7% [-3.1%, -2.4%] 🔵 -0.2% [-0.5%, +0.1%]
WolfSheep large 🔵 +3.1% [+1.2%, +5.4%] 🔴 +8.1% [+4.6%, +11.4%]
BoidFlockers small 🔵 +0.9% [+0.5%, +1.2%] 🔵 +2.4% [+2.1%, +2.6%]
BoidFlockers large 🔵 +1.0% [+0.4%, +1.5%] 🔵 +2.6% [+2.4%, +2.7%]

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

Hi @quaquel
The PropertyLayer is deeply embedded in Visualisation as well, so I would love to get a heads up before working on it further if it aligns with your vision. I realize the diff is fairly large, but the core changes are concentrated in grid.py only

@quaquel
Copy link
Copy Markdown
Member

quaquel commented Feb 18, 2026

I'll try to take a look somewhere today.

Copy link
Copy Markdown
Member

@quaquel quaquel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the direction this is taking. I have some initial thoughts and comments.

Also, separate from this, I still want to add sugarscape to the benchmarks.

@codebreaker32 codebreaker32 marked this pull request as ready for review February 20, 2026 09:38
@github-actions
Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.8% [-2.3%, -1.3%] 🔵 +0.4% [+0.2%, +0.6%]
BoltzmannWealth large 🔵 -0.9% [-1.4%, -0.4%] 🔵 +0.8% [-0.3%, +2.1%]
Schelling small 🔵 -1.4% [-1.6%, -1.2%] 🔵 -0.8% [-0.9%, -0.6%]
Schelling large 🔵 -0.9% [-1.3%, -0.6%] 🔵 +0.5% [-0.3%, +1.9%]
WolfSheep small 🔵 -0.3% [-0.6%, -0.1%] 🔵 -0.2% [-0.3%, +0.0%]
WolfSheep large 🔵 -0.2% [-1.2%, +0.9%] 🔵 +0.3% [-1.6%, +1.9%]
BoidFlockers small 🔵 -0.2% [-0.6%, +0.2%] 🔵 -1.9% [-2.1%, -1.8%]
BoidFlockers large 🔵 -0.1% [-0.5%, +0.3%] 🔵 -1.2% [-1.6%, -0.8%]

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

This PR is ready for review.

During refactoring, I noticed that using property feels a bit awkward since it’s also a built-in Python decorator. Should we consider a clearer alternative name?

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

codebreaker32 commented Feb 21, 2026

I profiled the Sugarscape model comparing main against this PR and results are:

Run main This PR Change(in %)
Run 1 3.81 3.69 96.90%
Run 2 3.97 3.56 89.89%
Run 3 3.25 3.08 94.50%
Run 4 3.39 3.14 92.82%
Run 5 3.44 3.16 91.67%
Run 6 3.43 3.49 101.64%
Run 7 3.23 3.15 97.58%
Run 8 3.05 3.02 98.93%
Run 9 3.50 3.62 103.60%
Run 10 3.91 3.52 90.03%

1000 steps in each Run with different rng

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

codebreaker32 commented Feb 21, 2026

On termites model from mesa-examples

Run main This PR Change (%)
Run 1 6.90 6.93 100.39%
Run 2 6.72 7.36 109.63%
Run 3 6.33 7.06 111.46%
Run 4 7.01 6.49 92.64%
Run 5 6.57 7.30 111.23%
Run 6 6.49 6.21 95.63%
Run 7 6.56 6.78 103.34%
Run 8 6.25 6.59 105.54%
Run 9 6.57 6.85 104.18%
Run 10 6.37 6.37 100.06%

1000 steps in each run with different rng

@quaquel
Copy link
Copy Markdown
Member

quaquel commented Feb 22, 2026

Can you take a look at the pre-commit and fix the errors?

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

codebreaker32 commented Feb 22, 2026

In some methods/arguments naming, we were using propertylayer*( such as for propertylayer_portrayal) and somewhere else property_layer*. While renaming back, I was finding it difficult to sync where we have used what so I have replaced all propertylayer* namings with property_layer* to maintain uniformity

Comment on lines -27 to -28
"> **NOTE:**\n",
"> This is not a tutorial on property layers themselves, but rather on their visualization. To explore the functionalities of property layers, please refer to this tutorial.\n",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this Note because I couldn't find any tuorial link here.

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

I think this is good to go from my end. I have also opened a PR in mesa-examples for failing example mesa/mesa-examples#334

@codebreaker32 codebreaker32 changed the title Remove PropertyLayer Remove PropertyLayer and HasPropertyLayers mixin Feb 22, 2026
Copy link
Copy Markdown
Member

@quaquel quaquel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks largely fine. One remaining API level question.

@quaquel quaquel merged commit 2cf3a63 into mesa:main Feb 28, 2026
13 of 15 checks passed
@codebreaker32 codebreaker32 deleted the remove_property_layer branch March 9, 2026 17:14
@EwoutH EwoutH added the breaking Release notes label label Mar 13, 2026
@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

breaking Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants