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

accept user-specified rng for random-number generation #303

Open
stevengj opened this issue Oct 29, 2021 · 2 comments · May be fixed by #304
Open

accept user-specified rng for random-number generation #303

stevengj opened this issue Oct 29, 2021 · 2 comments · May be fixed by #304

Comments

@stevengj
Copy link
Member

Rather than calling rand(...), it would be good to call rand(rng, ...) with an optionally user-specified rng::AbstractRNG keyword argument in algorithms that require pseudo-random initialization, e.g. lobpcg (

@inbounds X[:,j] .= rand.()
), bicgstabl (
r_shadow = rand(T, n)
), and idrs (
r_shadow = rand(T, n)
).

Rationale: if deterministic results are desired (as is often the case), it is better for the user to be able to specify an RNG than setting the global Random.seed!.

Moreover, arguably the default rng should be a new deterministic RNG object created with a fixed seed every time the iterative solver is initialized, so that the algorithm defaults to being deterministic.

(Note: "deterministic" ≠ "reproducible" … e.g. changing the Julia version could change the results. But it is useful to be able to run the same code with the same software on the same hardware multiple times and get exactly the same results as much as possible.)

@antoine-levitt
Copy link

Or simply accept rshadow as a kwarg and let the user do the initialization if needed?

@stevengj
Copy link
Member Author

stevengj commented Oct 30, 2021

Different iterative algorithms initialize different pseudorandom internal state. It seems like it's asking a lot of the caller to know what that internal state means for different solvers. Also, it's nice to have a uniform API that works with all of the algorithms that employ pseudorandom state.

@stevengj stevengj linked a pull request Oct 30, 2021 that will close this issue
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 a pull request may close this issue.

2 participants