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

Add R0 slider #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add R0 slider #50

wants to merge 2 commits into from

Conversation

swo
Copy link
Contributor

@swo swo commented Dec 19, 2024

  • User specifies one of R0 or infection rate to specify
  • The other value is shown on a grayed-out slider
  • On the backend:
    • The upper and lower limits for infection duration are set (with the duration > 0 as a requirement, to avoid infinite infection rate)
    • R0 has upper and lower limits (lower limit is zero)
    • Limits on infection rate are set by limits on duration and R0
  • If infection rate is varied, and it is set so high that R0>10, then a warning displays

Resolves #37

@swo swo requested a review from afmagee42 December 19, 2024 21:31
@afmagee42
Copy link
Contributor

I had to have the order of the two sliders swap. There's probably some way to do this nicer, but this is a start.

Probably something with either st.empty() or st.session_state. But agreed it's not a serious issue.

Limits on infection rate are set by limits on duration and R0. To get to the maximum value, duration and R0 must both be pulled to their maximum, which maybe is a little weird, but I think it's the only way to make it work.

That is not the experience I'm having running the app. The greyed out bar for infection rate gets a bigger maximum when I set R0 and infection duration to maximum. But then when I toggle to infection rate, it gets set to the default and its range goes to [0,1].

@afmagee42
Copy link
Contributor

I think that if you want persistent behavior across changing the R toggle, you might need session_state?

@swo
Copy link
Contributor Author

swo commented Dec 20, 2024

I think that if you want persistent behavior across changing the R toggle, you might need session_state?

Reworked! It took me a while to figure out how to do this, but it was simpler in the end than I expected

The thing I settled on was:

  • Give each slider a key
  • Set the default values for the sliders by adjusting the session state at the top of the script
  • Set the slider values in callbacks using the session state
  • Use the output values from the sliders in downstream logic (I think it would be equivalent to use the session state value, but this looks cleaner; the callback logic is in session state, and the downstream logic is all in normal variable)

@afmagee42
Copy link
Contributor

afmagee42 commented Dec 24, 2024

If I mess with the infectious_duration slider at all now I get

AssertionError:
Traceback:
File "ringvax/app.py", line 359, in
app()
File "ringvax/app.py", line 155, in app
assert np.isclose(R0, infection_rate * infectious_duration)

This goes away if I then touch R or the infection rate. Which means... something

@afmagee42
Copy link
Contributor

I have tried adding the R0 callback, alternately the rate callback, to infectious_duration and making sure infectious_duration had a session_default but the error persists.

Print-statement debugging says R0 isn't being recomputed in either case, so while I can't rule out that those are missing, I think the callbacks are not quite right?

Copy link
Contributor

@afmagee42 afmagee42 left a comment

Choose a reason for hiding this comment

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

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.

R0 in a slider
2 participants