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

Simulation determinism is dependent on non-functional code structuring #145

Open
james-whiteside opened this issue Mar 27, 2023 · 0 comments

Comments

@james-whiteside
Copy link
Contributor

james-whiteside commented Mar 27, 2023

Description

The following lines are present in the Simulation class:

val randomSource2 = randomSource.nextSource()
if (context.recreateDatabase) init(randomSource2)

Different data is generated when replaced with the following lines:

if (context.recreateDatabase) init(randomSource.nextSource())
else randomSource.nextSource()

The following unit test was written to test the behaviour of the RandomSource class:

@Test
fun testSource() {
    val seed: Long = 0
    val randomSourceA = RandomSource(seed)
    val randomSourceB = RandomSource(seed)
    assert(randomSourceA.nextInt(1000000) == randomSourceB.nextInt(1000000))

    val randomSourceA2 = randomSourceA.nextSource()
    repeat(1000000) {
        randomSourceA2.nextBoolean()
    }

    if (false) {}
    else randomSourceB.nextSource()

    assert(randomSourceA.nextInt(1000000) == randomSourceB.nextInt(1000000))
}

The test passed. It is unknown why a change that appears to be a trivial refactor causes changes to the data generated, and this warrants looking further into at a later date.

Environment

  1. OS: MacOS 12.6.1
  2. TypeDB version: 2.16.1
  3. TypeDB client: client-java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant