-
Notifications
You must be signed in to change notification settings - Fork 923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JupyterViz: Simulation step is very slow for huge grid size (e.g. 80x80) #1806
Comments
According to https://discuss.streamlit.io/t/plot-library-speed-trial/4688, Altair is orders of magnitude faster than Matplotlib. |
Altair is also suitable for interactive explorations, where matplotlib only displays a static image in solara. (https://solara.dev/examples/libraries/altair) Also we don't have to worry about thread safety since the actual plotting of altair happens in javascript (vega) |
Here is some code for a very simple altair grid chart def altair_space(model, test):
def get_data(agent, pos):
if agent:
return {"x": pos[0], "y": pos[1], "type": agent.type}
data = list(
filter(None, (get_data(agent, pos) for agent, pos in model.grid.coord_iter()))
)
chart = (
alt.Chart(alt.Data(values=data))
.mark_rect()
.encode(x="x:O", y="y:O", color="type:N")
)
return solara.FigureAltair(chart) But it does appear to be slower than Matplotlib :( Could you test this out @rht ? /edit to be used only for the schelling example |
It might have some issues with Jupyter. But yes the graphics are very rich, especially you can have a lots of information displayed via tooltip. |
Just tested. Altair is no-go for now. At first, I got this error
Then I did
|
You got me curious. This page talks about this: https://altair-viz.github.io/user_guide/large_datasets.html However, I tried it in mesa-interactive and it handled it just fine, so it seems to be solvable. For performance see the screencast e6497a6d-aa3d-42cf-b626-e824c290ca11.webm |
There is not much different in the code other than:
It could be my own install is problematic (I am using |
It seems fixing #1741 made it faster for both Matplotlib and Altair. Currently, the Altair version on main works even without the vegafusion acceleration, but the Matplotlib version of the space drawer is faster than Altair's, so I am leaving Matplotlib as the default, and am closing this issue. |
This is a continuation of the discussion started in #1772 (comment).
@rlskoeser suggested Altair, which might be faster than Solara's Matplotlib backend.
I did manual benchmark. I found that on my laptop (i5-1345U), the portray generation and
ax.scatter
took 80 ms, but the slowest part is actually Solara'ssavefig
: https://github.com/widgetti/solara/blob/a747a680478653ab73c3f9323aeb5fee45147b60/solara/components/matplotlib.py#L54, which took 1.2 s.I changed the output format from
png to svgsvg to png, and thesavefig
elapsed went down from 1.2 s to 180 ms. I additionally experimented with updating the scatter plot withset_offsets
(for x, y), andset_sizes
for size: the portrayal generation and scatter update went down from 80 ms to 6 ms. The branch I used to experiment can be found at https://github.com/rht/mesa/tree/solara_perf.This is very promising.
The text was updated successfully, but these errors were encountered: