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

State of Random Number Generator Changes after plotting trj #19

Closed
fenghaolin opened this issue Sep 15, 2019 · 3 comments
Closed

State of Random Number Generator Changes after plotting trj #19

fenghaolin opened this issue Sep 15, 2019 · 3 comments

Comments

@fenghaolin
Copy link

I came across this issue because my program generated different outputs if I plot trajectory after setting random seed. I believe that most users (or is it just me?) would not expect a change of state of random number generator after a trajectory plot, since there is no simulation conducted yet. Here is a minimal example

my.trj<-trajectory() %>%
  log_('Hello')
set.seed(123)
oldseed <- .Random.seed
head(oldseed)
plot(my.trj)
newseed<- .Random.seed
head(newseed)

The output of head(oldseed) is

[1] 10403 624 -983674937 643431772 1162448557 -959247990

The output of head(newseed) is

[1] 10403 16 515190382 2133433928 917665867 1283494313

@Enchufa2
Copy link
Member

Certainly, but this is not simmer.plot's fault. The RNG state changes after this line, and this is because DiagrammeR calls sample here to generate a unique ID for the graph. Minimal example:

set.seed(123)
head(.Random.seed)
#> [1]      10403        624 -983674937  643431772 1162448557 -959247990
DiagrammeR::create_graph()
#> DiagrammeR Graph // no nodes
#>  ...
head(.Random.seed)
#> [1]      10403         16  515190382 2133433928  917665867 1283494313

Could you please report it there?

@fenghaolin
Copy link
Author

Thank you very much for a very prompt reply. Now I see why. But I still think simmer.plot could do something about it, since users of simmer for DES are likely to concern about reproducibility, while general users of DiagrammeR may not. It took me a long time to figure out why the seemingly same programs with same initial seed produced different results. I assume that as simmer becomes more and more popular, there will be more future users stumbling over this since they would not anticipate the change of RNG state using the overloaded plot function.

Currently, what I do for my code is to store the RNG state before trj plot, and restore it after the plot. I think it would be more natural to do it within simmer.plot. Just my suggestion, and I don't want to sound ungrateful. In fact, simmer is very valuable, and I appreciate your time and efforts.

Again, thanks very much for developing and maintaining these wonderful tools for DES.

@Enchufa2
Copy link
Member

Ok, I'll keep this open for now, and I might apply a patch if upstream is not responding, but ideally this should be fixed in DiagrammeR. I don't think it's reasonable to change the RNG state when creating a non-random graph. Upstream issue for reference: rich-iannone/DiagrammeR#358.

@Enchufa2 Enchufa2 reopened this Sep 16, 2019
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

No branches or pull requests

2 participants