JuliaDiff / JuliaDiff/ForwardDiff.jl

Computational noise can corrupt NaN-safe computations

Open
#515 1 comment 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

Different amounts of computational noise in the value and partials of a dual number has the potential to corrupt even NaN-safe computations.

Minimum working example:

using ForwardDiff, LinearAlgebra

# start with zero valued vector of dual numbers
v = zeros(ForwardDiff.Dual{Nothing, Float64, 1}, 3);

# assume a perturbation of one component exists due to some computational noise
value = 1.0e-200 # so that value^2 == 0.0 (due to machine precision)
partial = 1.0e-100 # so that 2*value*partial != 0.0 (due to machine precision)
v[1] = ForwardDiff.Dual{Nothing}(value, partial);

# try out two functions
norm(v)
# Dual{Nothing}(1.0e-200,NaN)
sqrt(sum(v.^2))
# Dual{Nothing}(0.0,Inf)

Both implementations will result in NaNs propagated throughout the function, even in NaN-safe mode. I first encountered this after propagating derivatives through a Newton solve.

Originally posted by @taylormcd in https://github.com/JuliaDiff/ForwardDiff.jl/issues/243#issuecomment-539291591

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

Reproduce the minimum working example using ForwardDiff.Dual, norm(v), and sqrt(sum(v.^2)) as shown in the issue. Compare the NaN-safe behavior of both computations under the stated value and partial inputs, then determine a project-consistent expected result; done means the demonstrated noise case no longer propagates NaN or Inf unexpectedly.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.