Skip to content

Fix color_patches SolaraViz portrayal + update README#346

Open
Nandha-kumar-S wants to merge 5 commits intomesa:mainfrom
Nandha-kumar-S:fix-color-patches-solara-readme
Open

Fix color_patches SolaraViz portrayal + update README#346
Nandha-kumar-S wants to merge 5 commits intomesa:mainfrom
Nandha-kumar-S:fix-color-patches-solara-readme

Conversation

@Nandha-kumar-S
Copy link

Summary

Updates the color_patches example to run with Mesa 3.x SolaraViz and updtaed the README run instructions.

Motive

The README referenced the legacy mesa runserver flow, and the Solara app portrayal used CanvasGrid-style keys that are ignored in Mesa 3.x.

Implementation

  • Updated examples/color_patches/app.py portrayal function to return the supported SolaraViz keys (color, size).
  • Updated examples/color_patches/Readme.md to use solara run app.py and corrected the listed files.

Usage Examples

solara run app.py

@Nandha-kumar-S
Copy link
Author

Nandha-kumar-S commented Mar 4, 2026

hi @EwoutH Can you review this PR please? as this example's readme.md may mislead the users who try to run this model. I know that maintainers are busy, but hoping for a review when you get time :)

@tpike3
Copy link
Member

tpike3 commented Mar 4, 2026

Thanks @Nandha-kumar-S! This is definitely overdue.

Could you please fix the parameters (heigh and width) they do not show up in the interface. If you have time could you also clean up some of the outdated comments like the line 66 in app.py and the Attribute error in lines 102 through 110.

@Nandha-kumar-S
Copy link
Author

hi @tpike3 , i have updated the changes as requested. Please review them. Thanks

@Nandha-kumar-S
Copy link
Author

Hi @tpike3 following up on the latest updates here. Ready for your review whenever you have a moment. Thanks

@EwoutH
Copy link
Member

EwoutH commented Mar 9, 2026

@Sahil-Chhoker any chance you can give this a look?

Comment on lines +52 to 61
return {
"color": _COLORS[cell.state],
"size": 100,
}


space_component = make_space_component(
color_patch_draw,
draw_grid=False,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we not using the lastest visualization API here?

Copy link
Author

Choose a reason for hiding this comment

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

Hi @Sahil-Chhoker, thanks for the review! Since this PR was originally just focused on fixing the missing height/width parameters in the interface and cleaning up the outdated comments as requested by @tpike3, I kept the existing dictionary structure to keep the scope of these changes narrow.
While looking into this, I noticed that several other examples in the repository also still need to be updated to the latest AgentPortrayalStyle visualization API.
Would it be acceptable to get these immediate fixes merged in first so this example runs correctly for users? If so, I'll gladly open a new issue to track the API migration across the whole repository, assign it to myself, and submit a separate PR to update all the examples at once. I figure this will keep the commit history clean and tackle the deprecation globally.
Let me know if this works for you!

@Sahil-Chhoker
Copy link
Collaborator

Thanks for stating your thought process @Nandha-kumar-S, let's go with that. I'll give a final review to this PR by tonight.

@Nandha-kumar-S
Copy link
Author

Thanks @Sahil-Chhoker !

Copy link
Collaborator

@Sahil-Chhoker Sahil-Chhoker left a comment

Choose a reason for hiding this comment

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

One quick question/suggestion, but otherwise LGTM!

Comment on lines 93 to 96
@property
def grid(self):
"""
/mesa/visualization/modules/CanvasGridVisualization.py
is directly accessing Model.grid
76 def render(self, model):
77 grid_state = defaultdict(list)
---> 78 for y in range(model.grid.height):
79 for x in range(model.grid.width):
80 cell_objects = model.grid.get_cell_list_contents([(x, y)])

AttributeError: 'ColorPatches' object has no attribute 'grid'
"""
"""Provide backward compatibility for accessing the grid."""
return self._grid
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a specific reason for creating a separate grid property to access the _grid attribute of the model instead of just renaming _grid to grid?

I personally think latter one is more cleaner.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @Sahil-Chhoker, great catch! And that's much cleaner. I looked at the docstring and saw it was just a lingering workaround for CanvasGridVisualization backward compatibility. But now we're moving this to SolaraViz anyway, I've gone ahead and removed that legacy @Property block entirely and renamed self._grid to self.grid directly in model.py.
I just pushed the commit.
Let me know if everything looks good to go now! Thanks again for the review.

@Sahil-Chhoker
Copy link
Collaborator

This PR is good to go from my side. @tpike3 can you give it a final review?

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.

4 participants