Skip to content

Conversation

sanika-n
Copy link
Collaborator

Feature

I implemented post_process for Altair based components. And I just tested it out on the Boltzmann Wealth Model, with the following code:

def post_process(chart: alt.Chart) -> alt.Chart:
    return (
        chart
        .configure_legend(
            titleFontSize=14,  
            labelFontSize=12
        )
        .properties(title="Agent Wealth Distribution")
        .configure_view(
            stroke="black",
            strokeWidth=1
        )
    )

Before

image

After

Screenshot 2025-01-25 010414

@github-actions
Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +2.0% [+0.1%, +4.0%] 🔵 -1.2% [-1.5%, -0.9%]
BoltzmannWealth large 🔵 -0.9% [-1.6%, -0.3%] 🔵 -1.5% [-3.3%, +0.1%]
Schelling small 🔵 -1.9% [-2.3%, -1.6%] 🔵 -1.6% [-1.7%, -1.5%]
Schelling large 🔵 -1.4% [-1.9%, -1.1%] 🔵 -1.7% [-2.1%, -1.2%]
WolfSheep small 🔵 +0.7% [+0.3%, +1.2%] 🔵 -1.0% [-1.1%, -0.8%]
WolfSheep large 🔵 -1.4% [-2.1%, -0.7%] 🔵 -3.3% [-4.4%, -2.4%]
BoidFlockers small 🔵 -0.2% [-0.8%, +0.4%] 🔵 +1.9% [+1.7%, +2.1%]
BoidFlockers large 🔵 +0.4% [-0.2%, +1.0%] 🔵 +1.6% [+1.4%, +1.8%]

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.

Thanks @sanika-n!

Could you update the docstrings to ensure the API accurately reflects the change (~ Line 33) https://mesa.readthedocs.io/stable/apis/visualization.html#module-mesa.visualization.components.altair_components

And although this passes the tests check, it would be good to add a test to post process in the solara_viz test

mock_space_altair = mocker.spy(

Copy link
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.

Looks good to me.

@sanika-n
Copy link
Collaborator Author

I tried implementing the tests, it is working locally but it not working here... I noticed that @nissu99 is facing the same problem
image

image

@sanika-n sanika-n mentioned this pull request Jan 27, 2025
@tpike3
Copy link
Member

tpike3 commented Jan 27, 2025

@sanika-n I would look at the imports and __inits__; It seems to be failing here

ERROR    reacton:core.py:1721 Component react.component(mesa.visualization.components.altair_components.SpaceAltair) raised exception NameError("name 'alt' is not defined")
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/reacton/core.py", line 1702, in _render
    root_element = el.component.f(*el.args, **el.kwargs)
  File "/Users/runner/work/mesa/mesa/mesa/visualization/components/altair_components.py", line 69, in SpaceAltair
    chart = _draw_grid(space, agent_portrayal)
  File "/Users/runner/work/mesa/mesa/mesa/visualization/components/altair_components.py", line 163, in _draw_grid
    "x": alt.X("x", axis=None, type=x_y_type),
         ^^^

NameError: name 'alt' is not defined. Did you mean: 'all'?

@sanika-n
Copy link
Collaborator Author

@tpike3, Thank you so much, that fixed it

@tpike3 tpike3 merged commit c58af09 into projectmesa:main Jan 31, 2025
11 checks passed
@EwoutH EwoutH added visualisation enhancement Release notes label labels Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Release notes label visualisation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants