Skip to content

Update Network to use Cell.position and layout for Visualisation#3345

Merged
quaquel merged 6 commits intomesa:mainfrom
codebreaker32:fix_space_renderer
Feb 21, 2026
Merged

Update Network to use Cell.position and layout for Visualisation#3345
quaquel merged 6 commits intomesa:mainfrom
codebreaker32:fix_space_renderer

Conversation

@codebreaker32
Copy link
Copy Markdown
Collaborator

@codebreaker32 codebreaker32 commented Feb 18, 2026

This PR updates space_renderer.py to treat Network spaces as direct position-based systems, aligning their rendering logic with OrthogonalGrid, VoronoiGrid, and ContinuousSpace.

Changes:-

  1. It decouples the visualization backends from NetworkX layout calculations. Because cell.position is now guaranteed, all dictionary lookups, np.unique ID mapping, and fallback layout algorithms were removed from the visualization layer. Network spaces now use the same highly optimized, direct coordinate pass-through as OrthogonalGrid and ContinuousSpace.

  2. Deleted obsolete tests that were checking the legacy dictionary lookup and missing-node warning logic, and updated coordinate mapping assertions.


if isinstance(self.space, OrthogonalGrid | VoronoiGrid | ContinuousSpace):
if isinstance(
self.space, OrthogonalGrid | VoronoiGrid | ContinuousSpace | Network
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how does this work if we don't assign positions to network inside the model? Is it still possible to handle this in the visualization or not?

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.

how does this work if we don't assign positions to network inside the model?

It won't

Is it still possible to handle this in the visualization or not?

Honestly I need to explore the visualization side a bit more, once #3323 is merged, I will explore it bit further if that's okay.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am also fine with requiring this at the model level across the board. In my view, this would be in line with the idea of a Locatable protocol.

@github-actions
Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -2.8% [-3.6%, -2.0%] 🔵 -2.6% [-2.9%, -2.4%]
BoltzmannWealth large 🔵 +0.9% [-0.1%, +1.9%] 🔵 +2.8% [+0.2%, +5.4%]
Schelling small 🔵 +0.5% [+0.1%, +0.8%] 🔵 +0.3% [+0.1%, +0.5%]
Schelling large 🔵 +0.5% [-0.1%, +1.3%] 🔴 +9.6% [+6.6%, +13.5%]
WolfSheep small 🔴 +4.9% [+4.5%, +5.3%] 🔵 +2.7% [+2.3%, +3.2%]
WolfSheep large 🔴 +7.3% [+6.1%, +8.7%] 🔴 +14.3% [+11.8%, +16.3%]
BoidFlockers small 🔵 +0.1% [-0.3%, +0.5%] 🔵 +1.3% [+1.0%, +1.6%]
BoidFlockers large 🔵 +0.4% [-0.1%, +0.8%] 🔵 +0.3% [-0.0%, +0.6%]

@quaquel
Copy link
Copy Markdown
Member

quaquel commented Feb 20, 2026

The tests are breaking on the network change. Can you take a look?

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

Something is definitely going wrong with Networks


Screen.Recording.2026-02-20.191738.mp4

I am working on it but any inputs will be highly appreciated

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

codebreaker32 commented Feb 20, 2026

Hi @quaquel,

After digging into these edge cases, they all trace back to a single root cause: handling topological networks where Cell._position is empty.

Currently, the visualization layer is forced to do the heavy lifting to translate node_ids into (x, y) coordinates and manage fallback layouts. If the long-term architectural vision is for the visualization to natively consume cell._position, I propose we enforce that Cell._position is never empty at the model level for Network spaces.

I see two options for when a user initializes a Network with layout=None:

  1. Automatically generate a default layout (e.g., nx.spring_layout) under the hood.
  2. Raise an exception

What are your thoughts?

@quaquel
Copy link
Copy Markdown
Member

quaquel commented Feb 20, 2026

I propose we enforce that Cell._position is never empty at the model level for Network spaces.

I agree and I am inclined to use a meaningful default if no position is provided. Not sure what that default should be. In my view it should be very cheap to calculate for large networks. So something like a circle layout might be sufficient. As long as this behavior is well documented, I think this is the best way to go.

@codebreaker32
Copy link
Copy Markdown
Collaborator Author

In my view it should be very cheap to calculate for large networks. So something like a circle layout might be sufficient

Agree. circular_layout is the perfect choice

@codebreaker32 codebreaker32 changed the title Fix _map_coordinates in SpaceRenderer Update Network to use Cell._position and layout for Visualisation Feb 20, 2026
@codebreaker32 codebreaker32 changed the title Update Network to use Cell._position and layout for Visualisation Update Network to use Cell.position and layout for Visualisation Feb 20, 2026
@codebreaker32
Copy link
Copy Markdown
Collaborator Author

This PR is ready for review and can be merged after #3355 as discussed

@quaquel quaquel added the enhancement Release notes label label Feb 21, 2026
@quaquel quaquel merged commit 3897cd8 into mesa:main Feb 21, 2026
15 checks passed
@codebreaker32 codebreaker32 deleted the fix_space_renderer branch March 9, 2026 17:14
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