JuliaDiff / JuliaDiff/ForwardDiff.jl

ChainRules pushforward on Partials sometimes returns Array

Open
#432 2 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

julia> x, pf = frule(sin, 0.0)
(0.0, ChainRules.var"#83#sin_pushforward#59"{Float64}(0.0))

julia> pf(Zero(), Partials((1.0,)))
1-element Partials{1,Float64}:
Error showing value of type Partials{1,Float64}:
ERROR: MethodError: no method matching getindex(::Tuple{Float64}, ::Int64, ::Int64)

yeah yeah show fails (trying to do 2d access??) but that's not what I want to debug.

using ModelingToolkit

ForwardDiff.can_dual(::Type{Expression}) = true
ForwardDiff.can_dual(::Type{<:Expression}) = true

@variables x y

julia> a, pf = frule(sin, x)
(sin(x), ChainRules.var"#83#sin_pushforward#59"{Operation}(x))

julia> pf(Zero(), Partials((ModelingToolkit.Constant(1),)))
1-element Array{Operation,1}:
 +(cos(x) * 1)

This is not a Partials array!! And a Dual(x, p) where p is a Partials array is not the same as when p is an Array, so this ruins everything.

I suspect this is a Partials promotion problem and less sure that it's a ChainRules problem, so I'm opening this here and pinging @oxinabox

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 reproducing the frule examples with Partials and the ModelingToolkit Operation case. Trace the Partials promotion used by the ChainRules pushforward and compare it with the Dual construction; done means the pushforward preserves a Partials tangent rather than returning an Array, without breaking the shown examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
devtools
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.