Skip to content
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

Persistent loop of Matplotlib figure animation results in flickering output when run in a thread #1341

Open
rht opened this issue Jun 26, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@rht
Copy link

rht commented Jun 26, 2023

Description

The Mesa agent-based modeling library is looking to replace its self-hosted Tornado-based visualization server with Voilà. I have made a prototype in https://github.com/rht/mesa-examples/tree/voila. However, I encountered the flickering issue reported in #431. To summarize, it is like running the Game of Life simulation with play and stop buttons. The play and stop work, except that the display flickers.

The long-running loop: https://github.com/rht/mesa-examples/blob/99a68386226f3fe5be3953d25a84bd92f8b7065c/examples/boltzmann_wealth_model/run_voila.py#L161-L170. If I run the loop without threading or multiprocessing, it runs just fine. Each loop lasts for about 300 ms. My hypothesis is that the solutions in #431 does not apply because there is only 1 plot being constantly re-rendered, whereas in my case, I have 3 objects being constantly rerendered:

I have tried the plt.draw() as recommended in #431 (comment), but it didn't work out. I have also tried adding clear_output(wait=True), and it didn't work out.

I haven't tried on JupyterLab yet, and have been focusing to make it work with voila --no-browser --debug. I apologize in advance if this issue is not concise nor self-contained.

Context

  • voila version 0.4.0
  • Operating System and version: NixOS 23.05
  • Browser and version: Brave v1.52.126
@rht rht added the bug Something isn't working label Jun 26, 2023
@rht
Copy link
Author

rht commented Jun 27, 2023

I solved the problem for my use case by using widgets.Play, and thus simplifying the looping, threading, and observe situation. The flickering and out-of sync of the display is still there, but given that #431 is still open, I will close this as a duplicate of it.

@maartenbreddels
Copy link
Member

Hi,

thanks for opening the issue, and you are right #431 is probably related. Not that this is not a Voila issue specifically, but an ipywidget problem. The long term solution is jupyter-widgets/ipywidgets#3759 I think.

In solara (when using solara-server) this will already be used (see widgetti/solara#68 )
Although I think we could create an alternative output widget with this behavior without introducing a breaking change that should also work in the Jupyter notebook and Voila.

Regards,

Maarten

@rht
Copy link
Author

rht commented Jun 27, 2023

Thank you for the pointer to Solara! It's great that it is built on top if ipywidgets, and the demo looks slick.

@rht
Copy link
Author

rht commented Jun 27, 2023

Context for this issue: projectmesa/mesa#1622.

@maartenbreddels
Copy link
Member

See also jupyter-widgets/ipywidgets#2358 (comment) which means that with ipykernel 6.29.0 this mighe work (please let us know here to confirm)

@rht rht reopened this Feb 12, 2024
@rht
Copy link
Author

rht commented Feb 12, 2024

Tested on ipykernel==6.29.0 and mesa==2.1.5: the flickering is still there, except that it happens much less often, in about every ~15 s or 30 s or so. Whereas on ipykernel==6.26.0 it won't even play the animation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants