JuliaAttic / ReverseDiffSource.jl

Reverse automated differentiation from source
MIT License
47 stars 12 forks source link

rdiff() with functions containing for loops? #12

Closed ulzegasi closed 9 years ago

ulzegasi commented 9 years ago

Hi, I am using extensively rdiff() which does a really good job for my applications. Unfortunately my functions contain for loops. I am therefore using expressions and manually creating the functions with @eval. It is a good solution. However, I am currently trying to spawn differentiation operations over different processes using distributed arrays. The use of the localpart() of such arrays within the body of the expression to be differentiated seems to be a problem. You can refer to the following stackoverflow post.

http://stackoverflow.com/q/28959341/4600741?sem=2 (Julia: Use of Distributed Arrays in Expressions)

I was wondering if there is any plan to extend rdiff() to functions with for loops. This would automatically fix my problem and make my life much easier! (or do you have any alternative suggestions on how to overcome my issue?) Thanks a lot!

ulzegasi commented 9 years ago

Hi again, does anyone believe rdiff() will be extended to work with functions with for loops? I am sorry for insisting on this point, but I got stuck and would really need it to move on. Thanks a lot!

mlubin commented 9 years ago

I can't comment on @fredo-dedup's development plans, but applying reverse-mode AD to general loops in a reasonable way is quite a technical challenge.

fredo-dedup commented 9 years ago

Hi @ulzegasi Having for loops work for functions too is clearly an enhancement that I have in mind.... but I am still short on a satisfactory solution ! The best solution that I could think of was doing a reverse translation of the AST (starting from ifnots, gotos,..) and rebuilding the initial for loop. But that is not trivial and most importantly it will be a very brittle process : as soon as Julia internals evolve I will probably break. Another way could be to have rdiff work directly with gotos and ifnots but this kind of instructions make the execution path very hard to parse and rdiff needs to understand the execution path.

suggestions welcome !

ulzegasi commented 9 years ago

Thank you for your comments! I see your point. I'm afraid I cannot make any useful suggestion as this goes a bit beyond my expertise. I'll be patient.

fredo-dedup commented 9 years ago

Hi @ulzegasi I have pushed a version in the devl branch that can parse functions with for loops (run Pkg.checkout("ReverseDiffSource", "devl") to install it). I would like to know if it works for you before publishing it to master. You can check out functions that work in test\functions.jl. Thanks.

fredo-dedup commented 9 years ago

I've merged with master and tagged 0.1.4. Included also are precompilation and an updated README