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

Determinism between versions #85

Open
jchia opened this issue Jun 11, 2022 · 2 comments
Open

Determinism between versions #85

jchia opened this issue Jun 11, 2022 · 2 comments

Comments

@jchia
Copy link

jchia commented Jun 11, 2022

Is there a policy regarding whether two versions of the library will generate the same pseudo-random values given the same seed, or any other way to tell whether switching from one version to another will preserve behavior? I couldn't find any relevant description in the change log.

For example, client software that assumes that the same pseudo-random sequence is always generated for a given seed will break when upgrading mwc-random if the determinism is not preserved between the old and new versions, and the user needs to know whether a given mwc-random upgrade is safe in this regard.

Today, after switching stack resolver from lts-15 to nightly-2022-06-10, I noticed that my app that does random sampling with controlled seed behaved differently. In the end, I found out that the difference is due to the mwc-random version change from 0.14.0.0 to 0.15.0.2

@Shimuuar
Copy link
Collaborator

There's no explicit policy about that. This I believe an omission but it also bring question of how much is guaranteed? Sequence of random Word32 produced by generator is very stable. But any change to derived generators will likely to spoil it. Generators frequently use rejection sampling and will consume different number of Word32s

Change between 0.14 & 0.15 sounds strange. I would expect no change it was only to support random-1.2. Do you have test case by chance?

@jchia
Copy link
Author

jchia commented Jun 15, 2022

Yes, https://github.com/jchia/nd
The code demonstrating the difference is here, based on stack resolver nightly-2022-06-10:

module Main where

import qualified Data.Vector as V
import           Data.Word
import qualified System.Random.MWC as M
import qualified System.Random.MWC.Distributions as M

main :: IO ()
main = do
  g <- M.create
  i :: Word32 <- M.uniform g
  v :: V.Vector Int <- M.uniformPermutation 10 g
  print i
  print v

The first line of output is always 2254043345. The second line varies:
With mwc-random-0.14.0.0, the second line is [5,3,7,4,8,9,6,1,2,0].
With mwc-random-0.15.0.2, the second line is [6,3,2,0,9,5,7,1,4,8].

So, perhaps the cause is a change to the uniformPermutation algorithm.

I think it would be helpful to document the actual or possible changes between versions in both the underlying random generator and the distribution algorithms.

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