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

Stabilize random number reproducibility in doctests #3472

Merged
merged 7 commits into from
Dec 12, 2024

Conversation

nathanrboyer
Copy link
Contributor

@nathanrboyer nathanrboyer commented Oct 10, 2024

MersenneTwister(1234) from Random.jl yields different results now than those shown in the docstrings. I updated the docstrings of shuffle and shuffle! so that their output matches the new results. I also had to modify the docs Project.toml to be able to run the doctests correctly as suggested by Documenter.jl.

Note that for packages, you also likely need to have your package that you are documenting as a "dev dependency" of the docs/ environment.

This should fix the currently failing doctests in #3360.

This is suggested by the Documenter documentation.
I was not able to locally run make.jl until I did this.
(Actually the situation was worse because I was running the tests with a different version of the package than the local one, which was yielding confusing error messages.)
@nathanrboyer
Copy link
Contributor Author

This is what I ran from within the DataFrames directory which updated the docs Project.toml file and enabled me to run julia --project make.jl:

(DataFrames) pkg> activate docs

(docs) pkg> dev .

I'm not sure if that relationship is fully captured by the code in the Project.toml file.

@nathanrboyer
Copy link
Contributor Author

Now the behavior flipped so this branch is failing and #3360 passed???

@nathanrboyer
Copy link
Contributor Author

nathanrboyer commented Dec 5, 2024

Looks like the doctest behavior flipped again back to what I was originally experiencing. I expect the #3360 doctests to pass once this is merged.
Hey @bkamins, not trying to bug you, but I wanted to ping your inbox since this PR and #3360 have been ready for a little while now.

This was suggested in a discourse post where another package had
random numbers change between Julia versions.
Apparently this is expected behavior.
https://discourse.julialang.org/t/julia-1-11-1-gives-different-results-from-1-10-5/123433/53
@nathanrboyer
Copy link
Contributor Author

According to a recent discourse post, seeded random numbers can change between Julia versions. The StableRNGs.jl package was created for reproducible testing as used here, so I attempted to implement it.

I'm not sure if all of the calls to Random.seed! should also change to use StableRNG, but the doctests are passing for me as is.

@nathanrboyer nathanrboyer changed the title Fixed failing doctests because of changes to Random.jl Stabilize random number reproducibility in doctests Dec 6, 2024
@bkamins
Copy link
Member

bkamins commented Dec 11, 2024

@nathanrboyer thank you for working on it. I think we also need an entry to [compat' section for StableRNGs to fix its version. Other than that it looks good.

Then let us merge this PR and merge #360 with main after this merge it so that I can review #360 in a clean way (it is a big PR so it is better to avoid risks of later merge conflicts).

@nathanrboyer
Copy link
Contributor Author

I added a compat entry to the docs project.toml. I don't know of a way to do the same for test dependencies added as "extras"?

@@ -60,8 +60,21 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
ShiftedArrays = "1277b4bf-5013-50f5-be3d-901d8477a67a"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Copy link
Member

Choose a reason for hiding this comment

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

We need to also add these dependencies here as all extras entreis should have info in this file (we use them in tests not only in documentation building). Thank you!

@bkamins bkamins merged commit 86606d4 into JuliaData:main Dec 12, 2024
8 checks passed
@bkamins
Copy link
Member

bkamins commented Dec 12, 2024

Thank you!

@nathanrboyer nathanrboyer deleted the nb/fix-doctests branch December 12, 2024 15:54
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