-
Notifications
You must be signed in to change notification settings - Fork 64
make creation of inputs to propagation consistently hyginic #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
nickrobinson251
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yikes. Not sure how to test this / if it's worth it.
I could make a regression test for exactly that symptom if you think that is a good idea
How easy is that to do? I think it might be worth it if the test code is not too complex or hard to maintain?
Also, is it maybe worth adding a comment linking to this PR, to make it prominent if/when someone comes to edit this code? it's quite a sneaky gotcha.
| end | ||
|
|
||
| "Declares properly hygenic inputs for propagation expressions" | ||
| _propagator_inputs(n) = [esc(gensym(Symbol(:Δ, i))) for i in 1:n] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the gensym?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gensym gives it a name that is certain not to clash with anything.
it is a name like ##Δ2#991
So just incase the person had named a variable Δ2 and written something like
@scalar_rule foobar(x) (Δ2=10.0; Δ2*2), x
using gensym makes sure we don't clash into that variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes thanks esc doesn't help us with that
Co-authored-by: Nick Robinson <npr251@gmail.com>
|
The regression test was not that hard to add. |
Codecov Report
@@ Coverage Diff @@
## master #276 +/- ##
==========================================
+ Coverage 87.79% 87.82% +0.02%
==========================================
Files 13 13
Lines 418 419 +1
==========================================
+ Hits 367 368 +1
Misses 51 51
Continue to review full report at Codecov.
|
Turns out that we were not escaping the inputs correctly in the pullbacks generated by
@scalarrule.And in the case of multi-input functions that actually ended up creating and assigining to a global variable during the input destructuring.
Which must be some edge case of the compiler, as normally it errors if you try to do that.
Anyway that in turn was making the
sincos's rule in ChainRules.jl type-unstable because it was accessing this global variable.Testing this is really hard. I could make a regression test for exactly that symptom if you think that is a good idea.z
Before
After