JuliaDiff / ChainRules.jl

forward and reverse mode automatic differentiation primitives for Julia Base + StdLibs
Other
434 stars 89 forks source link

Use oneunit where it makes sense #479

Open sethaxen opened 3 years ago

sethaxen commented 3 years ago

I suspect some of the scalar rules should be using oneunit instead of one. For example, sign.

sethaxen commented 2 years ago

I just had a look at this and got really confused. So I think this needs someone who's thought more about derivatives of dimensional quantities to take care of this and is not after all a good first issue.

e.g. what should the units of (co)tangents be? A tangent of x is dx/dt for some upstream real x, so it should have units of x/t, but a cotangent of x is ds/dx for some downstream real s, so it should have units of s/x. A few checks. The Jacobian J of f: x ↦ y has units of y/x. So ẏ = J * ẋ has units of y/x * x/t = y/t. We also have x̄ = J' * ȳ with units of s/y * y/x = s/x. All good. Then we have <ẋ, x̄> with the desired units <dx/dt, ds/dx> = ds/dt.

This would imply that the units of (co)tangents are dependent on more than just the units of the primal, unless we explicitly define (co)tangents as being wrt dimensionless reals s and t. Then the tangent has the same units as the primal, while the cotangent's units are the inverse of the primal's.

Am I missing something here?

oxinabox commented 2 years ago

c.f. https://github.com/PainterQubits/Unitful.jl/pull/504