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

Use StableRNGs for adapted_grid() #169

Merged
merged 6 commits into from
Oct 16, 2024

Conversation

ffreyer
Copy link
Contributor

@ffreyer ffreyer commented Oct 9, 2024

Julia 1.11 changed something about random number generation which causes rand(MersenneTwister(1337)) to return a different result from <1.11. This results in a different point selection in adapted_grid and causes a test failure in Makie. Making rng a kwarg doesn't fix the difference between versions, but allows for other packages to use StableRNG if they care about consistency

@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.15%. Comparing base (f16e07a) to head (39d2e34).
Report is 6 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (f16e07a) and HEAD (39d2e34). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (f16e07a) HEAD (39d2e34)
9 6
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #169      +/-   ##
==========================================
- Coverage   72.05%   62.15%   -9.91%     
==========================================
  Files           7        6       -1     
  Lines         662      650      -12     
==========================================
- Hits          477      404      -73     
- Misses        185      246      +61     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@asinghvi17 asinghvi17 left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@ffreyer
Copy link
Contributor Author

ffreyer commented Oct 9, 2024

I'm not sure about this yet. The master version always reset the RNG so the results are always consistent for same inputs. This may or may not, depending on how it's used. E.g. if you set const RNG = Xoshiro(123) and pass that, you will advance the rng between calls and not get the same output. Re-seeding the rng is dodgy, since it could also be Random.default_rng().

I wonder if this could use a weaker factor instead, or if we should just make this a StableRNG in general.

@BeastyBlacksmith
Copy link
Member

we should just make this a StableRNG in general.

I'd say we do this, since we just need some random numbers. Possibly making the rand_factor a callsite argument, since people might be more interested to tweak that instead of the RN stream.

@jkrumbiegel
Copy link
Member

we should just make this a StableRNG in general.

Sounds good to me, and if you really want to give people the ability to try different seeds then you could also just make the seed itself a kwarg and then do rng = StableRNG(seed) in the function. But for me it would also be fine without that.

@ffreyer
Copy link
Contributor Author

ffreyer commented Oct 10, 2024

This fails:

let f = sinc, int = (0, 40)  # JuliaPlots/Plots.jl/issues/3894
    xs, fs = adapted_grid(f, int)
    @test length(xs) > 400
end

but it doesn't reproduce the problem from the issue. With lines(-40..40, sinc) in Makie:

grafik
grafik

The 0..40 range also looks good.

@SimonDanisch SimonDanisch changed the title Make rng a kwarg in adapted_grid() Use StableRNGs for adapted_grid() Oct 16, 2024
@SimonDanisch SimonDanisch merged commit 9421008 into JuliaPlots:master Oct 16, 2024
7 of 12 checks passed
@ffreyer ffreyer deleted the ff/adapted_grid branch October 16, 2024 22:06
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.

6 participants