JuliaDiff / JuliaDiff/ForwardDiff.jl

`let` scope causes nested differentiation error

Open
#267 15 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

As reported by @tkoolen here. Note from my comment there - this does not seem to be a case of pertubation confusion, but rather an an inference problem of some sort (or possibly that ForwardDiff is incorrectly relying on inference behavior in some way).

The bug can be triggered with:

using ForwardDiff, Base.Test
@noinline f83a(z, x) = x[1]
z83a = ([(1, (2), [(3, (4, 5, [1, 2, (3, (4, 5), [5])]), (5))])])
let z = z83a
    g = x -> f83a(z, x)
    h = x -> g(x)
    @test ForwardDiff.hessian(h, [1.]) == zeros(1, 1)
end

If the let block is removed, then everything works normally. According to @tkoolen, this is coincidentally is fixed by #247, but it would be very valuable for us to figure out why.

ref https://github.com/tkoolen/RigidBodyDynamics.jl/issues/347
cc @goretkin

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

Start by running the Julia reproduction in the issue, comparing the nested let version with the version where let is removed. Read the discussion in #247 and the linked RigidBodyDynamics.jl issue to investigate the inference behavior; done means explaining the scope-dependent failure and resolving the Hessian test without relying on the coincidental #247 fix.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.