JuliaDiff / JuliaDiff/ForwardDiff.jl

Inconsistent random numbers with some RNGs

Open
#593 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
1k
Forks
160
PR merge metrics
No merged PRs in 30d

Description

A MWE:

julia> using Random, ForwardDiff

julia> N = 8;

julia> x = Vector{ForwardDiff.Dual{Nothing,Float64,1}}(undef, N);

julia> randn!(Xoshiro(1), x);

julia> x[end].value
-0.8260207919192974

julia> x = Vector{Float64}(undef, N);

julia> randn!(Xoshiro(1), x);

julia> x[end]
0.8653808054093252

MersenneTwister breaks at N=13. StableRNGs seems fine always. This is because some result-changing optimizations done on Float64 arrays here which don't happen for Dual arrays.

I'm trying to think of what the best solution is, but in the meantime wanted to file this and maybe get some ideas as well.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the Julia MWE with Xoshiro, MersenneTwister, StableRNGs, Float64 arrays, and ForwardDiff.Dual arrays. Then inspect Julia's Random/src/normal.jl lines 213-242, where the issue reports result-changing Float64 optimizations, and determine how the differing randn! behavior should be tested and resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.