Skip to content

Implemented post_process in Altair based components#2641

Merged
tpike3 merged 10 commits intomesa:mainfrom
sanika-n:altair
Jan 31, 2025
Merged

Implemented post_process in Altair based components#2641
tpike3 merged 10 commits intomesa:mainfrom
sanika-n:altair

Conversation

@sanika-n
Copy link
Copy Markdown
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
Copy Markdown

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator Author

@tpike3, Thank you so much, that fixed it

@tpike3 tpike3 merged commit c58af09 into mesa:main Jan 31, 2025
@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