Open rht opened 1 year ago
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.
Hi,
thanks for opening the issue, and you are right https://github.com/voila-dashboards/voila/issues/431 is probably related. Not that this is not a Voila issue specifically, but an ipywidget problem. The long term solution is https://github.com/jupyter-widgets/ipywidgets/pull/3759 I think.
In solara (when using solara-server) this will already be used (see https://github.com/widgetti/solara/pull/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
Thank you for the pointer to Solara! It's great that it is built on top if ipywidgets, and the demo looks slick.
Context for this issue: https://github.com/projectmesa/mesa/discussions/1622.
See also https://github.com/jupyter-widgets/ipywidgets/issues/2358#issuecomment-1866978693 which means that with ipykernel 6.29.0 this mighe work (please let us know here to confirm)
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.
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:
widgets.Output
https://github.com/rht/mesa-examples/blob/99a68386226f3fe5be3953d25a84bd92f8b7065c/examples/boltzmann_wealth_model/run_voila.py#L154-L159I have tried the
plt.draw()
as recommended in https://github.com/voila-dashboards/voila/issues/431#issuecomment-542390982, but it didn't work out. I have also tried addingclear_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