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

Use rng, not seed #48

Merged
merged 2 commits into from
Dec 19, 2024
Merged

Use rng, not seed #48

merged 2 commits into from
Dec 19, 2024

Conversation

swo
Copy link
Contributor

@swo swo commented Dec 19, 2024

  • Always pass a numpy.random.Generator to Simulation, rather than an integer seed
  • Use .spawn() to create the rngs for each simulation

@swo swo requested a review from afmagee42 December 19, 2024 16:47
ringvax/app.py Outdated
@@ -171,8 +172,12 @@ def app():
sims = []
with st.spinner("Running simulation..."):
tic = time.perf_counter()

# initialize rngs
rngs = numpy.random.default_rng(seed).spawn(nsim)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nifty

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've been waiting for a chance to use this

I spent a lot of time figuring out how this works for parallelizable simulations; see "Reproducible random number generation (RNG)" in https://cran.r-project.org/web/packages/furrr/furrr.pdf

@swo swo merged commit b6db22d into main Dec 19, 2024
2 checks passed
@swo swo deleted the swo_seeds branch December 19, 2024 21:43
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.

2 participants