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

Solara viz: use_task for non-threaded continuous play #2304

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

Corvince
Copy link
Contributor

This is an alternative to #2303

While investigating #2303 I realized that use_thread is deprecated and recommended to replace with use_task, which also allows not using a thread at all, but a coroutine. This allows this version to also work in environments where threading can be problematic (colab) or isn't available at all (Pyodide, WASM, etc.). It also avoids possible issues with threads running in the background forever.

It also runs blazingly fast!

screen-capture.1.webm

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔴 +6.8% [+5.0%, +8.6%] 🔴 +8.0% [+6.8%, +9.2%]
BoltzmannWealth large 🔵 -1.4% [-2.9%, -0.5%] 🔵 -0.4% [-0.8%, +0.0%]
Schelling small 🔵 -0.2% [-0.4%, +0.0%] 🔵 -0.2% [-0.4%, -0.1%]
Schelling large 🔵 -0.4% [-0.5%, -0.1%] 🔵 -0.0% [-0.3%, +0.2%]
WolfSheep small 🔵 -0.4% [-0.7%, -0.2%] 🔵 -0.2% [-0.4%, -0.1%]
WolfSheep large 🔵 -0.4% [-0.8%, +0.0%] 🔵 -0.4% [-0.9%, +0.0%]
BoidFlockers small 🔵 -0.5% [-0.9%, -0.2%] 🔵 +0.5% [-0.2%, +1.2%]
BoidFlockers large 🔵 -0.2% [-0.6%, +0.1%] 🔵 -0.4% [-1.3%, +0.5%]

while playing.value:
time.sleep(play_interval / 1000)
await asyncio.sleep(1 / 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't 1 be play_interval?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, of course. Thats why we have code reviews I guess :)

@EwoutH
Copy link
Member

EwoutH commented Sep 20, 2024

Awesome stuff!

As a reference, use_task is currently in the Solara Lab, which contains parts of Solara that are slightly experimental. They are currently considering stabilizing it, but if any changes in the meantime, this is probably the issue to track:

@Corvince Corvince merged commit 0cc8515 into main Sep 20, 2024
10 checks passed
@Corvince Corvince deleted the solara-viz-use-task branch September 20, 2024 09:57
@EwoutH EwoutH added the enhancement Release notes label label Sep 20, 2024
@EwoutH EwoutH changed the title Solara viz: use_task for non-threaded continous play Solara viz: use_task for non-threaded continuous play Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants