projectmesa / mesa

Mesa is an open-source Python library for agent-based modeling, ideal for simulating complex systems and exploring emergent behaviors.
https://mesa.readthedocs.io
Apache License 2.0
2.52k stars 879 forks source link

jupyterviz agent space and measures flash on mesa 2.1.4 #1867

Closed rlskoeser closed 1 year ago

rlskoeser commented 1 year ago

Describe the bug When I run my simulations on the latest release (v2.1.4), my agent space and charts flicker.

Expected behavior In mesa 2.1.2 these render smoothly and update without any flickering.

To Reproduce My code base is here if you want to try running solara apps yourself: https://github.com/Princeton-CDH/simulating-risk If you check it out and install dependencies, you can run one of the models like this:

solara run --host localhost simulatingrisk/hawkdovevar/app.py

I'm going to pin mesa to version 2.1.2 for now, but I like the new layout and would like to update once this is resolved.

Additional context I looked at the release notes and some of the PRs; I tried changing the play_interval in my code when I initialize JupyterViz for my model, but it didn't have any effect.

I'm using altair instead of matplotlib, in case that's relevant.

I made a couple of screen recordings so you can see what I'm describing.

Nice smooth updating on mesa 2.1.2: https://github.com/projectmesa/mesa/assets/691231/22b676b9-d83c-4658-a93f-46ab343a8f9d

Jerky, flashing updating on mesa 2.1.4: https://github.com/projectmesa/mesa/assets/691231/06adccee-8823-44c1-b029-ce3660256034

rht commented 1 year ago

Upon investigating, it is due to the fact that the plot objects seem to be recreated from scratch for each step. This affects both the Matplotlib render as well. Removing https://github.com/projectmesa/mesa/blob/8e901d3510c46e1d1dba945d29cf014e899ba804/mesa/experimental/jupyter_viz.py#L63 fixes the issue. A proper solution would be to ensure the ColorCard and subcomponent of ColorCard are rerendered only when necessary.

rlskoeser commented 1 year ago

thanks for investigating and resolving so quickly!