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

fix: Don't continue playing when a model is reset #1796

Merged
merged 1 commit into from
Sep 16, 2023

Conversation

rht
Copy link
Contributor

@rht rht commented Sep 10, 2023

Fixes #1782.

@codecov
Copy link

codecov bot commented Sep 10, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.12% ⚠️

Comparison is base (ccde77b) 81.79% compared to head (971edab) 81.68%.

❗ Current head 971edab differs from pull request most recent head 712b1d1. Consider uploading reports for the commit 712b1d1 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1796      +/-   ##
==========================================
- Coverage   81.79%   81.68%   -0.12%     
==========================================
  Files          15       15              
  Lines         890      890              
  Branches      191      192       +1     
==========================================
- Hits          728      727       -1     
- Misses        138      139       +1     
  Partials       24       24              
Files Changed Coverage Δ
mesa/experimental/jupyter_viz.py 34.02% <0.00%> (-0.70%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

# clicking the reset button or changing the parameters. If previous_step >
# current_step, it means a model reset happens while the simulation is
# still playing.
previous_step = solara.use_reactive(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you seen the use previous hook? Might be usable here

https://solara.dev/api/use_previous

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tried, but with that, the simulation will always step once after the reset. Not sure why. At least this PR works, and the code is not that much different from if it were using use_previous.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's still a bit verbose. The step+1 got me curious and I was playing around a bit.

I think a simpler solution would be to use use_previous on the model and then look if the previous model is equal to the current model. If it's not set playing to False and reset current step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's problematic to store 2 copies of model with different specs at any given time. Consumes 2x RAM.

@rht
Copy link
Contributor Author

rht commented Sep 13, 2023

@tpike3 @jackiekazil can we disable the blocking the out-of-date branch? It is not necessary.

@jackiekazil
Copy link
Member

@rht not sure I understand.... what branch that is out of date is being blocked? and what are you trying to do?

@rht
Copy link
Contributor Author

rht commented Sep 13, 2023

This screenshot:

This branch is out-of-date with the base branch

2023-09-13-171553_835x292_scrot

@jackiekazil
Copy link
Member

Thank you for the clarification. It is updated now. Let me know if anything else needs to be done.

@rht
Copy link
Contributor Author

rht commented Sep 16, 2023

Can this PR be merged first for the upcoming release that is by the end of this month? It fixes a very problematic autoplay bug. There is no obvious solution regarding with use_previous, and it shouldn't block this PR.


def on_value_play(change):
if model.running:
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check for model.running and playing.value. That way you won't see any unwanted step+1 on reset

@Corvince
Copy link
Contributor

Sure, no this was never blocking

@Corvince Corvince merged commit 7f5a32e into projectmesa:main Sep 16, 2023
@rht rht deleted the solara_autoplay branch September 16, 2023 05:46
@tpike3 tpike3 added this to the Release 2.1.2 milestone Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JupyterViz: Changing simulation parameters shouldn't automatically start the simulation
4 participants