Skip to content

Conversation

Sahil-Chhoker
Copy link
Collaborator

@Sahil-Chhoker Sahil-Chhoker commented Jul 23, 2025

Summary

Updating the examples and docs showcasing the usage of the new API.

Motive

Part of my GSoC commitment.

Implementation

Updated the examples to include the basic usage of renderer with comments explaining what the code is actually doing.

Additional Notes

@tpike3, I've updated basic examples showcasing basic functionalities of the renderer, please review them and tell me how can they be improved.
One functionality I've left out is passing the kwargs to draw_structure to customize how the grid is drawn, I couldn't find a good place to fit it in, in the basic examples, maybe you can suggest something.

Summary by CodeRabbit

  • New Features

    • Enhanced visualization in multiple examples by introducing a more flexible renderer for displaying agents, grids, and property layers.
    • Updated agent portrayal to use a dedicated style object, enabling improved customization of appearance and backend compatibility.
    • Added advanced tutorial notebooks demonstrating comprehensive visualization techniques with interactive dashboards.
  • Bug Fixes

    • Improved color schemes, marker sizing, and legend styling for better visual clarity and consistency across models.
    • Fixed resource path handling to ensure reliable loading of image markers.
  • Documentation

    • Added and updated comments and tutorial notebooks to clarify visualization setup, rendering steps, and customization options.
    • Updated tutorial links and metadata for accuracy and improved user guidance.
  • Refactor

    • Replaced previous visualization components with a unified renderer approach across several example applications.
    • Updated plotting functions to use modern libraries and styling options, including Altair and Matplotlib backends.
    • Streamlined visualization code by removing deprecated components and adopting explicit renderer usage.

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +2.7% [+1.7%, +3.7%] 🔵 +0.0% [-0.2%, +0.3%]
BoltzmannWealth large 🔵 +1.8% [+1.0%, +2.7%] 🔵 +5.1% [+1.1%, +8.7%]
Schelling small 🔵 +2.2% [+2.0%, +2.5%] 🔵 +2.2% [+1.8%, +2.6%]
Schelling large 🔵 +1.4% [+0.9%, +1.9%] 🔴 +7.8% [+5.5%, +10.4%]
WolfSheep small 🔵 +1.9% [+1.6%, +2.2%] 🔵 +2.1% [+1.8%, +2.4%]
WolfSheep large 🔴 +5.3% [+4.5%, +6.0%] 🔴 +10.6% [+8.5%, +12.9%]
BoidFlockers small 🔵 -0.2% [-0.9%, +0.5%] 🔵 -1.4% [-1.5%, -1.2%]
BoidFlockers large 🔵 -0.3% [-0.9%, +0.4%] 🔵 -0.5% [-0.8%, -0.1%]

@Sahil-Chhoker
Copy link
Collaborator Author

@coderabbitai full review

Copy link

coderabbitai bot commented Jul 23, 2025

✅ Actions performed

Full review triggered.

@Sahil-Chhoker Sahil-Chhoker requested a review from tpike3 July 23, 2025 03:50
Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

This update refactors several Mesa example applications and tutorials to adopt the new SpaceRenderer and AgentPortrayalStyle classes for visualization. It replaces previous usage of make_space_component and dictionary-based agent portrayals with these structured classes, revises plotting post-processing functions, updates imports, and improves visualization consistency across examples and documentation.

Changes

File(s) Change Summary
Basic examples
mesa/examples/basic/boid_flockers/app.py, .../boltzmann_wealth_model/app.py, .../conways_game_of_life/app.py, .../schelling/app.py, .../virus_on_network/app.py
Replaced make_space_component with SpaceRenderer; agent portrayal functions now return AgentPortrayalStyle; updated visualization setup and post-processing for plots.
Advanced examples
mesa/examples/advanced/epstein_civil_violence/app.py, .../pd_grid/app.py, .../sugarscape_g1mt/app.py, .../wolf_sheep/app.py
Migrated visualization code to use SpaceRenderer and AgentPortrayalStyle; replaced old space components; updated rendering backends and post-processing accordingly.
Visualization backends
mesa/visualization/backends/altair_backend.py, mesa/visualization/backends/matplotlib_backend.py
Minor fixes: removed title from Altair fill encoding; changed alpha retrieval in Matplotlib backend to preserve dictionary key.
Visualization core
mesa/visualization/space_renderer.py
Enhanced Network coordinate mapping to suppress IndexErrors during coordinate assignment using contextlib.suppress.
Tutorial notebooks
docs/tutorials/4_visualization_basic.ipynb, 5_visualization_dynamic_agents.ipynb, 6_visualization_rendering_with_space_renderer.ipynb, 7_visualization_propertylayer_visualization.ipynb, 8_visualization_custom.ipynb, 9_batch_run.ipynb
Updated tutorials to use SpaceRenderer and AgentPortrayalStyle; revised visualization explanations, agent portrayal functions, and post-processing; updated links and metadata.

Sequence Diagram(s)

sequenceDiagram
    participant Model
    participant SpaceRenderer
    participant AgentPortrayalStyle
    participant SolaraViz

    Model->>SpaceRenderer: Initialize with model and backend
    SpaceRenderer->>AgentPortrayalStyle: Use for agent portrayal
    SpaceRenderer->>SpaceRenderer: Render grid and agents
    SpaceRenderer->>SolaraViz: Pass renderer as component
    SolaraViz->>SpaceRenderer: Display visualization
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~45 minutes

Possibly related PRs

  • Added AgentPortrayalStyle and PropertyLayerStyle #2786: Introduced AgentPortrayalStyle and PropertyLayerStyle classes replacing dictionary-based styles, directly related to this refactoring.
  • Introduction of Space Renderer #2803: Refactors example applications to utilize SpaceRenderer, aligning with the visualization updates in this PR.
  • projectmesa/mesa#2779: Improvements to visualization backends and rendering infrastructure that support the new rendering approach.

Suggested labels

example, visualisation

Suggested reviewers

  • tpike3

Poem

A rabbit hopped through grids anew,
With colors bright and markers true.
Renderers now take the stage,
As agents dance from cage to cage.
Portrayal styles, so neat and spry—
Mesa’s world, a clearer sky!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
mesa/examples/basic/schelling/app.py (1)

18-44: Fix invalid marker usage causing pipeline failure.

The matplotlib backend doesn't support image file paths as markers. The pipeline failure confirms this: "ValueError caused by unrecognized marker style './resources/orange_happy.png'".

Replace image file paths with valid matplotlib markers:

def agent_portrayal(agent):
    style = AgentPortrayalStyle(
        x=agent.cell.coordinate[0],
        y=agent.cell.coordinate[1],
-        marker="./resources/orange_happy.png",
+        marker="o",  # Use circle marker
        size=75,
    )
    if agent.type == 0:
        if agent.happy:
            style.update(
-                ("marker", "./resources/blue_happy.png"),
+                ("marker", "s"),  # Use square marker
            )
        else:
            style.update(
-                ("marker", "./resources/blue_unhappy.png"),
+                ("marker", "^"),  # Use triangle marker
                ("size", 50),
                ("zorder", 2),
            )
    else:
        if not agent.happy:
            style.update(
-                ("marker", "./resources/orange_unhappy.png"),
+                ("marker", "v"),  # Use inverted triangle marker
                ("size", 50),
                ("zorder", 2),
            )
    return style
🧹 Nitpick comments (2)
mesa/examples/basic/schelling/app.py (1)

60-67: Update comments to reflect actual implementation.

The comments mention "images as markers" but the code uses matplotlib marker symbols, not actual image files.

-# Note: Models with images as markers are very performance intensive.
+# Note: The renderer provides a unified interface for drawing agents and grid structure.
# Here we use renderer.render() to render the agents and grid in one go.
# This function always renders the grid and then renders the agents or
# property layers on top of it if specified. It also supports passing the
# post_process function to fine-tune the plot after rendering in itself.
mesa/examples/basic/boid_flockers/app.py (1)

20-34: Optimize marker application in style update.

The marker caching approach is excellent for performance. However, line 33 redundantly reapplies the same marker that was already set.

    if neighbors >= 2:
-        boid_style.update(("color", "green"), ("marker", MARKER_CACHE[rounded_deg]))
+        boid_style.update(("color", "green"))

The marker is already set during initial style creation, so it doesn't need to be reapplied when only the color changes.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47eff74 and 377f301.

📒 Files selected for processing (5)
  • mesa/examples/basic/boid_flockers/app.py (3 hunks)
  • mesa/examples/basic/boltzmann_wealth_model/app.py (3 hunks)
  • mesa/examples/basic/conways_game_of_life/app.py (3 hunks)
  • mesa/examples/basic/schelling/app.py (2 hunks)
  • mesa/examples/basic/virus_on_network/app.py (2 hunks)
🧠 Learnings (5)
📓 Common learnings
Learnt from: Sahil-Chhoker
PR: projectmesa/mesa#2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.
mesa/examples/basic/schelling/app.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

mesa/examples/basic/boltzmann_wealth_model/app.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

mesa/examples/basic/boid_flockers/app.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

mesa/examples/basic/virus_on_network/app.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

🧬 Code Graph Analysis (2)
mesa/examples/basic/conways_game_of_life/app.py (2)
mesa/visualization/space_renderer.py (1)
  • SpaceRenderer (44-394)
mesa/visualization/components/portrayal_components.py (1)
  • AgentPortrayalStyle (18-73)
mesa/examples/basic/boltzmann_wealth_model/app.py (2)
mesa/visualization/space_renderer.py (1)
  • SpaceRenderer (44-394)
mesa/visualization/components/portrayal_components.py (1)
  • AgentPortrayalStyle (18-73)
🪛 GitHub Actions: build
mesa/examples/basic/schelling/app.py

[error] 67-67: Test failure in test_schelling_model: ValueError caused by unrecognized marker style './resources/orange_happy.png' in matplotlib scatter plot marker setting.

mesa/examples/basic/boltzmann_wealth_model/app.py

[error] 54-54: Test failure in test_boltzmann_model: ValueError due to invalid RGBA argument np.int64(1) in matplotlib color handling during agent rendering.

🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: Sahil-Chhoker
PR: projectmesa/mesa#2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.
mesa/examples/basic/schelling/app.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

mesa/examples/basic/boltzmann_wealth_model/app.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

mesa/examples/basic/boid_flockers/app.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

mesa/examples/basic/virus_on_network/app.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

🧬 Code Graph Analysis (2)
mesa/examples/basic/conways_game_of_life/app.py (2)
mesa/visualization/space_renderer.py (1)
  • SpaceRenderer (44-394)
mesa/visualization/components/portrayal_components.py (1)
  • AgentPortrayalStyle (18-73)
mesa/examples/basic/boltzmann_wealth_model/app.py (2)
mesa/visualization/space_renderer.py (1)
  • SpaceRenderer (44-394)
mesa/visualization/components/portrayal_components.py (1)
  • AgentPortrayalStyle (18-73)
🪛 GitHub Actions: build
mesa/examples/basic/schelling/app.py

[error] 67-67: Test failure in test_schelling_model: ValueError caused by unrecognized marker style './resources/orange_happy.png' in matplotlib scatter plot marker setting.

mesa/examples/basic/boltzmann_wealth_model/app.py

[error] 54-54: Test failure in test_boltzmann_model: ValueError due to invalid RGBA argument np.int64(1) in matplotlib color handling during agent rendering.

🔇 Additional comments (15)
mesa/examples/basic/schelling/app.py (2)

7-7: Import change looks good.

The addition of SpaceRenderer import aligns with the new visualization API.


71-79: SolaraViz configuration updated correctly.

The direct usage of the renderer object instead of the old component approach is consistent with the new API.

mesa/examples/basic/conways_game_of_life/app.py (4)

4-6: Import changes align with new API.

The replacement of old components with SpaceRenderer and AgentPortrayalStyle is consistent with the modernization effort.


9-14: Agent portrayal correctly implemented.

The function properly returns AgentPortrayalStyle with valid matplotlib markers and appropriate styling based on agent state.


58-66: Renderer setup is well-implemented.

The explicit use of draw_agents() followed by post_process assignment provides clear control over the rendering pipeline. The detailed comments effectively explain the renderer's capabilities.


73-78: SolaraViz configuration follows new API correctly.

The direct renderer usage aligns with the modernized visualization approach.

mesa/examples/basic/boltzmann_wealth_model/app.py (3)

5-5: Import changes support new visualization API.

The addition of SpaceRenderer and AgentPortrayalStyle aligns with the modernization effort across examples.

Also applies to: 8-8


44-55: Renderer setup is well-documented and structured.

The explicit rendering steps with colormap configuration provide clear control over the visualization pipeline. The comprehensive comments effectively explain the process.


70-76: SolaraViz configuration updated correctly.

The combination of the renderer with additional plot components demonstrates proper usage of the new API.

mesa/examples/basic/virus_on_network/app.py (4)

13-13: Import changes support Altair backend usage.

The imports align with the new visualization API and demonstrate cross-backend compatibility.

Also applies to: 16-16


19-25: Agent portrayal correctly updated for new API.

The color scheme simplification and size increase improve readability while maintaining proper state-based visualization.


96-108: Post-processing function properly adapted for Altair.

The chart styling and legend configuration demonstrate proper Altair usage for visualization enhancement.


111-131: Altair backend implementation is well-integrated.

The consistent use of Altair across the renderer and plot components with matching color schemes demonstrates proper cross-component coordination.

mesa/examples/basic/boid_flockers/app.py (2)

9-10: Import changes align with new visualization API.

The consolidated import and addition of AgentPortrayalStyle support the modernized rendering approach.


75-83: Renderer setup demonstrates concise API usage.

The method chaining approach effectively combines renderer creation and rendering in a single line while maintaining readability.

@Sahil-Chhoker
Copy link
Collaborator Author

@tpike3, can you please also take a look at this PR.

@tpike3
Copy link
Member

tpike3 commented Jul 26, 2025

@Sahil-Chhoker I would not worry about the draw_structure you can include that in the advanced examples.

However, the goal is to provide users with examples that show the wide range of possibilities with your new front end. As an example, could you make half of them altair backends. This will also help, in some small way, the LLM issue overtime as it will help generate via users more and diverse examples of current Mesa for its probabilistic generation.

In addition for the maintainers, the examples are the most effective way to show them what you did and how you upgraded the front end.

Remember, for repeated users of Mesa big changes can be really annoying, because they are learning the new syntax while trying to build their models (which is what they are most concerned about). The examples and tutorial are critical to reduce that pain and sell them on why we decided to pursue this upgrade.

Short version, really leverage the examples to show off the new front end capabilities and provide easy references for users, as this is the best way to communicate to the Mesa community the visualization module's new functionality.

@Sahil-Chhoker
Copy link
Collaborator Author

@tpike3, I think I'm done with the basic examples, they show the fastest way to setup visualization and every possible customization except the property layers which can be achieved through advanced examples.
We can give the detailed explanation of how things works in the tutorial.

Please go through them and tell me if you find anything concerning.

@tpike3
Copy link
Member

tpike3 commented Aug 6, 2025

@tpike3, I also want to add the property layer visualization tutorial, but I am not sure this is the right place for it, what do you recommend? Also take a look at the changes made to the tutorials.

@Sahil-Chhoker Just went through the tutorials--- Those are great! I would absolutely add a property layer tutorial here I think that would be hugely helpful. Appreciating the the Model may not lend itself to property layer attributes, I would say there is two paths. 1 - In 6 add a overview of property layer and reference an example or 2 - just make up some aspect of property layer for Boltzmann wealth just to demo the capability that is only used for that tutorial.

If you go with path 2 - I would probably put it as 7 then bump everything else up 1. Just make sure you change the binder and colab hyperlinks as required.

By Monday, I will really try and put the examples through their paces, so we can identify if there are any problems like we have in existing examples as noted in #2822

@Sahil-Chhoker
Copy link
Collaborator Author

@Sahil-Chhoker Just went through the tutorials--- Those are great! I would absolutely add a property layer tutorial here I think that would be hugely helpful. Appreciating the the Model may not lend itself to property layer attributes, I would say there is two paths. 1 - In 6 add a overview of property layer and reference an example or 2 - just make up some aspect of property layer for Boltzmann wealth just to demo the capability that is only used for that tutorial.

I think I'll make a separate tutorial for the property layer, so your points are noted!

By Monday, I will really try and put the examples through their paces, so we can identify if there are any problems like we have in existing examples as noted in #2822

Thanks, please do!

@Sahil-Chhoker
Copy link
Collaborator Author

@tpike3, I am not sure how binder works, do we have a binder link for every tutorial or a common one for every tutorial?

@Sahil-Chhoker Sahil-Chhoker marked this pull request as ready for review August 7, 2025 07:07
@Sahil-Chhoker Sahil-Chhoker requested a review from tpike3 August 7, 2025 07:08
@Sahil-Chhoker
Copy link
Collaborator Author

@coderabbitai full review

Copy link

coderabbitai bot commented Aug 7, 2025

✅ Actions performed

Full review triggered.

Copy link

github-actions bot commented Aug 7, 2025

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +1.8% [+0.9%, +2.6%] 🔵 +0.9% [+0.7%, +1.0%]
BoltzmannWealth large 🔵 -0.7% [-1.3%, -0.2%] 🔵 -2.2% [-4.9%, +0.4%]
Schelling small 🔵 -0.2% [-0.4%, +0.0%] 🔵 +0.4% [+0.3%, +0.6%]
Schelling large 🔵 +0.4% [-0.2%, +1.0%] 🔵 +1.5% [-0.3%, +3.7%]
WolfSheep small 🔵 -0.5% [-0.8%, -0.2%] 🔵 -0.4% [-0.5%, -0.2%]
WolfSheep large 🔵 +0.2% [-0.3%, +0.8%] 🔵 +0.5% [-1.0%, +2.4%]
BoidFlockers small 🔵 -0.3% [-1.0%, +0.4%] 🔵 -1.2% [-1.4%, -1.1%]
BoidFlockers large 🔵 +0.2% [-0.2%, +0.7%] 🔵 -1.1% [-1.4%, -0.9%]

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (4)
mesa/examples/basic/conways_game_of_life/app.py (1)

1-6: Add CLI compatibility imports as previously requested.

The past review comment requested adding CLI compatibility imports that are still missing.

Apply this diff to add the missing imports:

+import os
+import sys
+
+sys.path.insert(0, os.path.abspath("../../../.."))
+
 from mesa.examples.basic.conways_game_of_life.model import ConwaysGameOfLife
mesa/examples/basic/schelling/app.py (1)

1-2: Add CLI compatibility imports as previously requested.

The past review comment requested CLI compatibility imports that are still missing.

Apply this diff to add the missing imports:

 import os
+import sys
+
+sys.path.insert(0, os.path.abspath("../../../.."))
 
docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb (2)

16-17: LGTM! Binder link correctly configured.

The Binder badge and URL are properly set up for this tutorial, matching the format requested in past review comments.


227-247: LGTM! Comprehensive explanation of interactive controls.

The documentation thoroughly explains the Play Interval Slider, Render Interval Slider, and Use Threads Checkbox, addressing the feedback from past review comments about explaining what each control does.

🧹 Nitpick comments (2)
docs/tutorials/7_visualization_propertylayer_visualization.ipynb (1)

170-179: Remove useless expression from the code cell.

The semicolon at the end of line 179 creates a useless expression as flagged by static analysis.

-g.set(title="Wealth distribution", xlabel="Wealth", ylabel="number of agents");
+g.set(title="Wealth distribution", xlabel="Wealth", ylabel="number of agents")
docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb (1)

161-171: Remove useless expression from the code cell.

Similar to the other notebook, the semicolon creates a useless expression as flagged by static analysis.

-g.set(title="Wealth distribution", xlabel="Wealth", ylabel="number of agents");
+g.set(title="Wealth distribution", xlabel="Wealth", ylabel="number of agents")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1231bf and 04108ca.

📒 Files selected for processing (18)
  • docs/tutorials/4_visualization_basic.ipynb (8 hunks)
  • docs/tutorials/5_visualization_dynamic_agents.ipynb (9 hunks)
  • docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb (1 hunks)
  • docs/tutorials/7_visualization_propertylayer_visualization.ipynb (1 hunks)
  • docs/tutorials/8_visualization_custom.ipynb (1 hunks)
  • docs/tutorials/9_batch_run.ipynb (1 hunks)
  • mesa/examples/advanced/epstein_civil_violence/app.py (3 hunks)
  • mesa/examples/advanced/pd_grid/app.py (2 hunks)
  • mesa/examples/advanced/sugarscape_g1mt/app.py (3 hunks)
  • mesa/examples/advanced/wolf_sheep/app.py (2 hunks)
  • mesa/examples/basic/boid_flockers/app.py (3 hunks)
  • mesa/examples/basic/boltzmann_wealth_model/app.py (2 hunks)
  • mesa/examples/basic/conways_game_of_life/app.py (3 hunks)
  • mesa/examples/basic/schelling/app.py (3 hunks)
  • mesa/examples/basic/virus_on_network/app.py (2 hunks)
  • mesa/visualization/backends/altair_backend.py (0 hunks)
  • mesa/visualization/backends/matplotlib_backend.py (1 hunks)
  • mesa/visualization/space_renderer.py (2 hunks)
💤 Files with no reviewable changes (1)
  • mesa/visualization/backends/altair_backend.py
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: Sahil-Chhoker
PR: projectmesa/mesa#2819
File: mesa/examples/basic/boltzmann_wealth_model/app.py:13-15
Timestamp: 2025-07-23T04:03:11.386Z
Learning: PR #2818 "Allowing color mapping to integers in AgentPortrayalStyle" fixes integer color mapping issues in AgentPortrayalStyle by modifying the matplotlib backend's collect_agent_data function to properly handle integer color values with colormaps, enabling patterns like AgentPortrayalStyle(color=agent.wealth) to work correctly.
📚 Learning: pr #2818 "allowing color mapping to integers in agentportrayalstyle" fixes integer color mapping iss...
Learnt from: Sahil-Chhoker
PR: projectmesa/mesa#2819
File: mesa/examples/basic/boltzmann_wealth_model/app.py:13-15
Timestamp: 2025-07-23T04:03:11.386Z
Learning: PR #2818 "Allowing color mapping to integers in AgentPortrayalStyle" fixes integer color mapping issues in AgentPortrayalStyle by modifying the matplotlib backend's collect_agent_data function to properly handle integer color values with colormaps, enabling patterns like AgentPortrayalStyle(color=agent.wealth) to work correctly.

Applied to files:

  • mesa/examples/advanced/pd_grid/app.py
  • mesa/examples/basic/boid_flockers/app.py
  • mesa/examples/basic/conways_game_of_life/app.py
  • mesa/visualization/backends/matplotlib_backend.py
  • mesa/examples/advanced/sugarscape_g1mt/app.py
  • mesa/examples/basic/schelling/app.py
  • mesa/examples/basic/virus_on_network/app.py
  • docs/tutorials/7_visualization_propertylayer_visualization.ipynb
  • mesa/examples/advanced/wolf_sheep/app.py
  • mesa/examples/advanced/epstein_civil_violence/app.py
  • mesa/examples/basic/boltzmann_wealth_model/app.py
  • docs/tutorials/5_visualization_dynamic_agents.ipynb
  • docs/tutorials/4_visualization_basic.ipynb
📚 Learning: in mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer ...
Learnt from: Sahil-Chhoker
PR: projectmesa/mesa#2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

Applied to files:

  • mesa/examples/advanced/pd_grid/app.py
  • mesa/examples/basic/boid_flockers/app.py
  • mesa/visualization/backends/matplotlib_backend.py
  • mesa/examples/advanced/sugarscape_g1mt/app.py
  • mesa/examples/basic/virus_on_network/app.py
  • docs/tutorials/7_visualization_propertylayer_visualization.ipynb
  • mesa/examples/advanced/epstein_civil_violence/app.py
  • mesa/examples/basic/boltzmann_wealth_model/app.py
  • docs/tutorials/5_visualization_dynamic_agents.ipynb
  • docs/tutorials/4_visualization_basic.ipynb
  • docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb
🪛 Ruff (0.12.2)
docs/tutorials/7_visualization_propertylayer_visualization.ipynb

205-205: Found useless expression. Either assign it to a variable or remove it.

(B018)

docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb

215-215: Found useless expression. Either assign it to a variable or remove it.

(B018)

⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: run-benchmarks
🔇 Additional comments (57)
docs/tutorials/8_visualization_custom.ipynb (1)

350-350: LGTM! Tutorial link correctly updated.

The link update to tutorial 9 is appropriate and maintains navigation consistency.

docs/tutorials/9_batch_run.ipynb (1)

383-383: LGTM! Tutorial link correctly updated.

The link update to tutorial 10 maintains proper navigation flow in the tutorial sequence.

mesa/visualization/backends/matplotlib_backend.py (1)

216-216: LGTM! Alpha value retention improves argument handling.

The change from pop("alpha") to direct access preserves the alpha value in the arguments dictionary for downstream use in scatter plot creation, which improves consistency with the visualization API updates.

mesa/visualization/space_renderer.py (2)

7-7: LGTM! Import added for error suppression.

The contextlib import is appropriately added to support the IndexError handling in network coordinate mapping.


156-160: LGTM! Race condition handling for network coordinates.

The use of contextlib.suppress(IndexError) appropriately handles the race condition where coordinate indices update before position data is ready. The FIXME comment correctly indicates this is a temporary solution that should be improved in the future.

mesa/examples/advanced/epstein_civil_violence/app.py (3)

10-13: LGTM! Proper imports for new visualization API.

The imports correctly bring in SpaceRenderer and AgentPortrayalStyle for the modernized visualization approach.


67-74: LGTM! Excellent migration to SpaceRenderer API.

The refactoring properly:

  • Creates a SpaceRenderer instance with matplotlib backend
  • Configures agent drawing with the updated portrayal function
  • Assigns the post-processing function to the renderer
  • Updates SolaraViz to use the renderer directly instead of component lists

This aligns perfectly with the new visualization API approach.


28-34: No change needed for AgentPortrayalStyle.update syntax
The update method is explicitly implemented to accept one or more (key, value) tuple arguments for batch property updates and is used consistently throughout the library (see tutorials 5, 6, and 7). The tuple-based API is intentional and correct. You may still assign single properties via portrayal.color = value if you prefer, but the existing update(("color", value)) calls are valid and require no modification.

Likely an incorrect or invalid review comment.

mesa/examples/basic/conways_game_of_life/app.py (2)

10-14: LGTM! Correct implementation of AgentPortrayalStyle.

The agent portrayal function correctly uses the new AgentPortrayalStyle class with appropriate properties for Conway's Game of Life visualization.


58-62: LGTM! Proper SpaceRenderer setup.

The SpaceRenderer is correctly instantiated and configured for agent-only rendering, which is appropriate for Conway's Game of Life where only cell states matter.

mesa/examples/advanced/sugarscape_g1mt/app.py (2)

25-28: LGTM! Appropriate post-processing for Altair backend.

The post_process function correctly sets fixed chart dimensions for the Altair visualization, which is essential for consistent display sizing.


57-61: LGTM! Correct SpaceRenderer implementation with Altair backend.

The SpaceRenderer is properly configured with the Altair backend and includes both agent and property layer portrayals, maintaining the full visualization capabilities of the original implementation.

mesa/examples/basic/schelling/app.py (2)

20-21: LGTM! Improved path handling for cross-platform compatibility.

Using os.path.dirname and os.path.abspath ensures proper resource path resolution regardless of the current working directory.


76-81: LGTM! Appropriate SpaceRenderer usage with helpful comments.

The SpaceRenderer setup with matplotlib backend is correct, and the comments about performance and the render() method functionality are valuable for users.

mesa/examples/advanced/pd_grid/app.py (3)

19-21: LGTM! Clean AgentPortrayalStyle implementation.

The agent portrayal function correctly uses AgentPortrayalStyle with conditional coloring based on agent cooperation strategy.


43-43: LGTM! Consistent backend specification.

Explicitly specifying backend="altair" and grid=True for the plot component maintains consistency with the SpaceRenderer backend choice.


47-48: LGTM! Proper SpaceRenderer setup with Altair backend.

The SpaceRenderer instantiation with Altair backend and immediate render() call correctly implements the new visualization pattern.

mesa/examples/advanced/wolf_sheep/app.py (3)

18-22: LGTM! Good default initialization pattern.

Creating the AgentPortrayalStyle with sensible defaults (size, marker, zorder) and then updating specific properties based on agent type is a clean approach.


33-33: LGTM! Efficient multiple property updates.

Using portrayal.update() with multiple tuple arguments to set marker, size, and zorder simultaneously is an efficient way to customize GrassPatch visualization.


84-89: LGTM! Correct SpaceRenderer configuration.

The SpaceRenderer setup with matplotlib backend, draw_agents() call, and post_process assignment correctly implements the new visualization pattern.

mesa/examples/basic/virus_on_network/app.py (6)

13-16: LGTM! Clean import updates for new API.

The import changes correctly replace make_space_component with SpaceRenderer and add AgentPortrayalStyle for the new visualization approach.


19-25: Good improvement in agent portrayal implementation.

The function now returns an AgentPortrayalStyle object instead of a dictionary, which is the correct approach for the new API. The color changes (removing "tab:" prefixes) align well with Altair backend requirements, and increasing size from 10 to 20 improves agent visibility.


96-108: Excellent post-processing function for Altair.

The rewritten post_process_lineplot function correctly configures Altair chart properties and legend styling instead of manipulating matplotlib axes. The legend styling with stroke, fill, and positioning creates a professional appearance.


111-117: Great demonstration of explicit rendering workflow.

This code excellently demonstrates the new SpaceRenderer approach with:

  • Clear model instantiation
  • Explicit structure drawing with customized node/edge styling
  • Separate agent drawing call
  • Good use of comments explaining the workflow

This provides a clear example for users migrating to the new API.


120-124: Consistent backend usage and color scheme.

The StatePlot correctly uses the Altair backend with colors matching the agent portrayal, and properly integrates the post-processing function.


126-135: Clean SolaraViz integration.

The SolaraViz setup correctly uses the renderer instance directly instead of the deprecated component list approach.

mesa/examples/basic/boltzmann_wealth_model/app.py (6)

1-2: Good addition of Altair import.

Adding the Altair import is necessary for the post-processing function to configure chart properties.


7-10: Correct imports for new visualization API.

The import changes properly bring in SpaceRenderer and AgentPortrayalStyle for the modernized visualization approach.


15-18: Excellent use of integer color mapping.

The agent portrayal correctly uses agent.wealth directly as the color value. This leverages the integer color mapping functionality that was fixed in PR #2818, allowing the colormap to handle the wealth-to-color translation seamlessly.


40-54: Well-implemented post-processing function.

The post_process function correctly configures an Altair chart with:

  • Proper color encoding using viridis colormap
  • Gradient legend with appropriate styling
  • Clear domain specification (0-10) for wealth values

The docstring clearly explains the purpose, making it educational for users.


59-70: Excellent educational comments and implementation.

The comments provide clear explanations of:

  • SpaceRenderer's role and layer-based approach
  • Backend specification
  • Grid customization options
  • Agent rendering with colormap parameters

This serves as a great example for users learning the new API. The implementation correctly demonstrates the explicit rendering workflow.


75-83: Good integration and documentation.

The SolaraViz setup is clean and well-documented. The comment about running with solara run app.py is helpful for users. The direct renderer usage follows the new pattern correctly.

mesa/examples/basic/boid_flockers/app.py (4)

4-5: Clean import updates for new API.

The imports correctly replace the deprecated components with SpaceRenderer and AgentPortrayalStyle for the modernized visualization approach.


24-29: Excellent conditional styling implementation.

The boid_draw function showcases a clean pattern:

  • Creates base AgentPortrayalStyle with default properties
  • Uses the update() method for conditional modifications based on agent state
  • Preserves the cached marker optimization for performance

This demonstrates effective use of the new styling system.


72-76: Great streamlined rendering approach.

The chained SpaceRenderer(...).render(agent_portrayal=boid_draw) call demonstrates the most concise way to set up visualization with the new API. The comment clearly explains this as the quickest visualization method.


78-83: Clean SolaraViz integration.

The SolaraViz setup correctly uses the renderer instance directly, following the new pattern established across the examples.

docs/tutorials/4_visualization_basic.ipynb (5)

63-64: Correct import updates for new visualization API.

The imports properly replace make_space_component with SpaceRenderer and add AgentPortrayalStyle to support the modernized visualization approach.


191-195: Excellent updated explanation of agent portrayal.

The text now correctly describes that portrayal functions return AgentPortrayalStyle objects rather than dictionaries. This provides accurate guidance for users learning the new API.


204-205: Good agent portrayal implementation.

The function correctly returns an AgentPortrayalStyle object with appropriate color and size parameters, demonstrating the new approach clearly.


252-270: Comprehensive SpaceRenderer documentation.

This new section excellently explains:

  • SpaceRenderer's role in visualization
  • Backend options (matplotlib/altair)
  • Post-processing capabilities
  • The render() method usage
  • Full-screen viewing tip

This provides valuable educational content for users transitioning to the new API.


281-293: Clean tutorial implementation.

The visualization setup correctly demonstrates:

  • SpaceRenderer instantiation with backend specification
  • Chained render() call with agent portrayal
  • Direct renderer usage in SolaraViz
  • Proper component integration

This serves as a clear example for tutorial users.

docs/tutorials/5_visualization_dynamic_agents.ipynb (6)

17-17: Correct Binder link update.

The link now correctly points to the current tutorial (5_visualization_dynamic_agents.ipynb) rather than the previous one.


63-64: Consistent import updates.

The imports correctly use SpaceRenderer and AgentPortrayalStyle to maintain consistency with the new visualization API across all tutorials.


193-203: Valuable educational content on backend compatibility.

This expanded explanation excellently covers:

  • Backend-specific shape support (matplotlib vs altair)
  • Cross-references to documentation
  • Important compatibility warnings
  • Limited conversion support between backends

This helps users avoid common pitfalls when working with different rendering backends.


215-219: Good demonstration of conditional agent styling.

The agent_portrayal function effectively shows:

  • Base AgentPortrayalStyle creation with default properties
  • Conditional styling using the update() method
  • Wealth-based visual differentiation

This builds well on the concepts from the previous tutorial.


274-282: Consistent tutorial implementation.

The visualization setup correctly follows the established pattern with SpaceRenderer and maintains consistency with the previous tutorial's approach.


306-306: Good tutorial progression link.

The updated link correctly points to the next tutorial on SpaceRenderer, maintaining proper tutorial flow.

docs/tutorials/7_visualization_propertylayer_visualization.ipynb (6)

16-17: LGTM! Binder link is correctly formatted.

The Binder badge and link are properly configured to launch this specific tutorial.


61-65: LGTM! Imports align with the new Mesa visualization API.

The imports correctly demonstrate the transition to SpaceRenderer, AgentPortrayalStyle, and PropertyLayerStyle components, replacing the older make_space_component approach.


83-161: LGTM! Well-structured Boltzmann Wealth Model implementation.

The model implementation is clean and properly demonstrates:

  • Agent movement and wealth exchange mechanics
  • Property layer creation with random test data
  • Data collection for Gini coefficient tracking

The addition of the property layer with np.random.randint(0, 10, size=(width, height)) provides a good foundation for demonstrating property layer visualization.


314-327: LGTM! Property layer portrayal function demonstrates best practices.

The propertylayer_portrayal function correctly:

  • Uses conditional logic based on layer.name for multi-layer support
  • Returns PropertyLayerStyle objects with appropriate styling
  • Demonstrates key properties like color, alpha, and colorbar

344-378: LGTM! Comprehensive demonstration of SpaceRenderer capabilities.

The code properly demonstrates:

  • Individual drawing methods (draw_structure, draw_agents, draw_propertylayer)
  • The consolidated render() method with space_kwargs
  • Both approaches provide equivalent functionality with different API styles

431-441: LGTM! SolaraViz integration follows the new visualization patterns.

The dashboard setup correctly:

  • Uses SpaceRenderer instance directly instead of component lists
  • Includes custom plot components with post-processing
  • Provides interactive model parameters
  • Demonstrates the modern Mesa visualization approach
docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb (4)

81-152: LGTM! Standard Boltzmann Wealth Model implementation.

The model implementation is consistent with Mesa best practices and provides a solid foundation for demonstrating visualization features.


306-346: LGTM! Excellent demonstration of backend-specific rendering.

The code effectively shows:

  • Matplotlib backend with line styling parameters (lw, ls, color, alpha)
  • Altair backend with different parameter names (grid_width, grid_dash, etc.)
  • Clear distinction between backend-specific approaches

This helps users understand the API differences between backends.


372-414: LGTM! Clear examples of post-processing for both backends.

The post-processing functions demonstrate:

  • Matplotlib: Direct axis manipulation with ax.set_title(), ax.grid(), etc.
  • Altair: Chart property configuration with method chaining
  • Backend-specific customization patterns

The warning about backend incompatibility is particularly valuable for users.


464-474: LGTM! Modern SolaraViz integration pattern.

The dashboard setup follows the updated Mesa visualization approach by:

  • Passing SpaceRenderer instance directly to SolaraViz
  • Including custom components with post-processing
  • Providing interactive model parameters

This demonstrates the transition from the older component-based approach.

@tpike3
Copy link
Member

tpike3 commented Aug 7, 2025

@tpike3, I am not sure how binder works, do we have a binder link for every tutorial or a common one for every tutorial?

There is a binder link for each tutorial. Essentially, it just goes to the url of your file in your github repo and gives you a server based jupyter environment. https://mybinder.org/

@Sahil-Chhoker
Copy link
Collaborator Author

Then does just updating the final destination keep the links consistent?

@tpike3
Copy link
Member

tpike3 commented Aug 7, 2025

Then does just updating the final destination keep the links consistent?

Yes, updating the hyperlink in the markdown is all you need to do.

@tpike3
Copy link
Member

tpike3 commented Aug 9, 2025

@Sahil-Chhoker -- A couple things going through the examples

  • In Schelling there should be a markdown displaying the number of happy agents. That plot is not appearing
  • In Schelling is there anyway to make it render faster with the smiley face images? I think we talked about this before, but if so I need a refresher.
  • For sugarscape it seems to be getting a mix of matplotlib (components) and altair (renderer). Can you make it if they call renderer for altair, all plot are in altair as well, or ability to mix and match???
  • For sugarscape, when you do a bunch of resets/change parameters its start getting odd behavior, for instance the agents stopped plotting but their impact on the landscape was still there
  • For sugarscape, the price plot is overlapping the renderer
  • For alliance_formation your visualization module has a Network Drawer, is there a reason you didnt want to integrate that into alliance formation?
  • Please update the getting_started.md in the docs folder, the hyper links to the tutorials are no longer valid (see lines 9-18 and 56-66)
  • For custom visualization, will we still need the update_counter? In effect will custom visualizations stay the same?

You are doing excellent work, and I think this will be the most thoroughly we have have gone through examples with respect to the visualizations.

@Sahil-Chhoker
Copy link
Collaborator Author

  • In Schelling there should be a markdown displaying the number of happy agents. That plot is not appearing
image

It's appearing on mine.

  • In Schelling is there anyway to make it render faster with the smiley face images? I think we talked about this before, but if so I need a refresher.

I don't think so, I was aware of this and have tried a few combinations in the backend rendering but this is the fastest I could get it to run.

  • For sugarscape it seems to be getting a mix of matplotlib (components) and altair (renderer). Can you make it if they call renderer for altair, all plot are in altair as well, or ability to mix and match???

If they want to change the plot component to altair they can just pass the backend as altair in the make_plot_component. I've mentioned this, I think, in the tutorial that both can co-exist.

  • For sugarscape, when you do a bunch of resets/change parameters its start getting odd behavior, for instance the agents stopped plotting but their impact on the landscape was still there

It's working fine for me, if you're getting visual artifacts, I believe solara is the reason behind this and also think that it is completely random and can happen in the performance extensive models.
Can you maybe try again and see if you can recreate the behavior, if you can it's best to put up a issue on this.

  • For sugarscape, the price plot is overlapping the renderer

I believe I mentioned that dynamic spacing between the spaces is not possible, therefore when you add colorbar the render's space extend, users will have to rearrange the grids to how they like it in this case.

  • For alliance_formation your visualization module has a Network Drawer, is there a reason you didnt want to integrate that into alliance formation?

Your example doesn't use any of the mesa grids, drawers only exist for mesa grids.

  • Please update the getting_started.md in the docs folder, the hyper links to the tutorials are no longer valid (see lines 9-18 and 56-66)

Will do, thanks for checking.

  • For custom visualization, will we still need the update_counter? In effect will custom visualizations stay the same?

Yes.

@tpike3
Copy link
Member

tpike3 commented Aug 11, 2025

Thanks @Sahil-Chhoker I think we have culminated with this PR---

Two relatively quick things:

  • Could you update the tests so we meet the diff mark
  • I may have missed the paragraph explanation, but I need see the use of backed in the tutorial for plot components, if it is not there could you explicitly call out mix and matching plot types in the visual as part of the explanation and could you also add a comment in the sugarscape comments that the to libraries are mixed and matched, just to be very explicit to the user community

Then I will merge,


On related topics:

For the sugarscape issue, I could not consistently recreate the issues, so will need to explore it more later, but my sense it is is about the model not the visual.

As you look to the next PR and potentially adding multiple pages, could you take a look at the solara_viz.py

Updating the below function I can prevent the overlap in sugarscape, but it is also not behaving the way I would hope or necessarily responsive to parameter changes and may break other things.

def make_initial_grid_layout(num_components, 
                             chart_width=5, 
                             chart_height=15, 
                             chart_gap = 0):
    """Create an initial grid layout for visualization components.

    Args:
        num_components: Number of components to display

    Returns:
        list: Initial grid layout configuration
    """
    cols = 2
    item_w = chart_width 
    item_h = chart_height 
    vertical_gap_units = chart_gap  

    layout = []
    for i in range(num_components):
        row = i // cols
        col = i % cols
        layout.append(
            {
                "i": i,
                "w": item_w,
                "h": item_h,
                "moved": False,
                "x": item_w * col,
                "y": (item_h + vertical_gap_units) * row,
            }
        )
    return layout

@Sahil-Chhoker
Copy link
Collaborator Author

I'm not sure what test is missing, codecov's report kind of confuses me.

Copy link
Member

@tpike3 tpike3 left a comment

Choose a reason for hiding this comment

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

LGTM!

Excellent work thanks @Sahil-Chhoker

@tpike3
Copy link
Member

tpike3 commented Aug 12, 2025

I'm not sure what test is missing, codecov's report kind of confuses me.

The way I understand it is Codecov looks at two things
1 - Total percent of code covered by tests, which is 90.63%, you added tests covered post process which is very good and actually then covers missing lines in the patch
2 - Percent of the code in the PR that is covered by tests, this helps ensure new code is well tested and above the percent. In this case everything that was left from your PR was 7 lines of code from examples, which some of the lines (xlim and ylim) should have been covered because they were indirectly part of the post process test you created, but I don't think they count as they are not directly covered by the example tests.

Overall, you increased the number percentage of tests for the repo (to include examples) and you covered some basic functionality of visualization with tests of post-process so it would seem pretty draconian to delay this PR any further.

@tpike3 tpike3 merged commit ded4c49 into projectmesa:main Aug 12, 2025
10 of 12 checks passed
@tpike3 tpike3 added the docs Release notes label label Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants