JuliaDiff / JuliaDiff/ForwardDiff.jl
Forced periodicity (modulo) breaks ForwardDiff
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 1k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
It seems that modulo periodicity that seems to break ForwardDiff:
If I give it a very simple function that should be differentiable, but use a modulo for time, then this happens:
#+begin_src julia
function f(t)
sin(pi * 2 * (t % 1))^2
end
#+end_src
#+RESULTS:
: f (generic function with 1 method)
#+begin_src julia
ForwardDiff.derivative(f, 1)
#+end_src
#+RESULTS:
: NaN
#+begin_src julia
derivative(f, 1)
#+end_src
#+RESULTS:
: -5.736299254432828e-15
So the result from the CD is close to zero, as expected. But the ForwardDiff gives NaN. If I take the modulo out, then AutoDiff works.
So while I took care that my functions are continuous, smooth and differentiable at the period boundaries, AutoDiff will not work for them. It does work for cosine series, which are naturally periodic, but not with piecewise continuous functions with modulo periodicity.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the Julia function f(t) and the ForwardDiff.derivative(f, 1) call shown in the report, then compare it with derivative(f, 1). Investigate how the modulo expression is handled at the period boundary; done means the ForwardDiff result is finite and agrees with the expected near-zero derivative.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100