Skip to content

Backend array storage: make _data the single source of truth (RasterLayer refactor PR 2) - #332

Open
Tejasv-Singh wants to merge 2 commits into
mesa:mainfrom
Tejasv-Singh:feat/cell-proxy-decoupling
Open

Backend array storage: make _data the single source of truth (RasterLayer refactor PR 2)#332
Tejasv-Singh wants to merge 2 commits into
mesa:mainfrom
Tejasv-Singh:feat/cell-proxy-decoupling

Conversation

@Tejasv-Singh

@Tejasv-Singh Tejasv-Singh commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Backend array storage: _data as the single source of truth

Part of #328. Follows #330 (merged).

This is PR 2 of the GSoC 2026 RasterLayer refactor. Its scope was narrowed following maintainer feedback: Cell remains a mesa.Agent subclass in this PR. Decoupling Cell from Agent has been deferred to a follow-up PR (to land alongside the cell-collection work).

What this does

  • Makes RasterLayer._data (a dict[str, np.ndarray]) the single source of truth for all band data.
  • Removes the per-cell dual-write loops in set_band, get_band, remove_band, apply_raster, and get_raster, these now read from and write to _data directly instead of scattering/gathering across every cell.
  • Makes Cell a thin proxy: __getattr__/__setattr__ route band access (cell.<band>) directly into self._layer._data[name][row, col]. Cells no longer hold per-cell copies of band values.
  • Wires cell._layer via a _layer= kwarg passed in _initialize_cells, preserving exact backward compatibility for both the legacy (pos/indices) and current Cell constructor signatures.
  • Adds a regression test (test_agent_init_proxy_pos_interaction) confirming that the proxy safely ignores the default attribute assignments made by Agent.__init__, and that pos still behaves.
  • Adds a grid_pos property on Cell as a preferred replacement for the deprecated pos (see open question below).

Deferred to follow-up PRs

  • Decoupling Cell from mesa.Agent : moved to a separate PR to land with cell collection, so activation isn't split between agents and the collection.
  • Examples update : the GIS examples (urban_growth, rainfall, population) still assign band attributes (self.<band> = None) in __init__ before their bands exist. This is handled in a separate mesa-examples PR, per the breaking-change workflow (release → bump requirements.txt → update examples).

CI notes

  • Test GIS examples is expected to fail on this branch. It's the deferred examples regression above, not an accidental break, it'll go green once the mesa-examples PR lands after the next release.
  • All mesa-geo unit tests pass.

Open questions for review

  • grid_pos: kept here for now, but since pos deprecation is conceptually part of the cell redesign, happy to defer it to the decoupling PR if preferred.
  • Pre-assigned attribute shadowing: a subclass that assigns self.<band> = None before the band exists will shadow the proxy (the value stays in __dict__). Following the discussion, this is being handled by investigating a migrate-and-erase approach rather than a __getattribute__ safety net; noting it here so it's tracked in review..

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 20b13d18-8e14-4296-9f0a-39fc5a282179

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.50%. Comparing base (16ad316) to head (bc00b98).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #332      +/-   ##
==========================================
+ Coverage   78.32%   78.50%   +0.18%     
==========================================
  Files          10       10              
  Lines        1024     1033       +9     
  Branches      168      161       -7     
==========================================
+ Hits          802      811       +9     
  Misses        181      181              
  Partials       41       41              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tejasv-Singh
Tejasv-Singh force-pushed the feat/cell-proxy-decoupling branch 5 times, most recently from 2b613ff to 677a242 Compare July 27, 2026 14:49
@Tejasv-Singh
Tejasv-Singh force-pushed the feat/cell-proxy-decoupling branch from 677a242 to bdac019 Compare July 27, 2026 14:55
@Tejasv-Singh
Tejasv-Singh marked this pull request as ready for review July 28, 2026 08:20
@Tejasv-Singh Tejasv-Singh changed the title Draft: Cell proxy decoupling: PR 2 of the GSoC 2026 RasterLayer refactor Backend array storage: make _data the single source of truth (RasterLayer refactor PR 2) Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant