Skip to content

Conversation

st--
Copy link
Contributor

@st-- st-- commented Sep 22, 2021

  • clarify order of @thunk and ProjectTo
  • correct misplaced paragraph
  • document new behaviour of ChainRulesTestUtils#218
  • improve example
  • some minor typo edits

@codecov-commenter
Copy link

codecov-commenter commented Sep 22, 2021

Codecov Report

Merging #468 (79082d1) into master (3ccd3c1) will decrease coverage by 6.54%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #468      +/-   ##
==========================================
- Coverage   92.98%   86.43%   -6.55%     
==========================================
  Files          14       13       -1     
  Lines         812      656     -156     
==========================================
- Hits          755      567     -188     
- Misses         57       89      +32     
Impacted Files Coverage Δ
src/config.jl 0.00% <0.00%> (-100.00%) ⬇️
src/tangent_types/tangent.jl 69.30% <0.00%> (-15.07%) ⬇️
src/projection.jl 87.42% <0.00%> (-10.70%) ⬇️
src/tangent_types/thunks.jl 85.00% <0.00%> (-10.00%) ⬇️
src/accumulation.jl 92.85% <0.00%> (-4.37%) ⬇️
src/rule_definition_tools.jl 94.01% <0.00%> (-2.17%) ⬇️
src/rules.jl 88.88% <0.00%> (-2.03%) ⬇️
src/tangent_arithmetic.jl 96.19% <0.00%> (-0.14%) ⬇️
src/ChainRulesCore.jl
src/tangent_types/notimplemented.jl 75.00% <0.00%> (+4.16%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ccd3c1...79082d1. Read the comment docs.

Copy link
Member

@mzgubic mzgubic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure about this one. The reason is that either order works since the projection is inserted into the thunk, see ProjectTo docstring. This is to allow thunk propagation.

While I do agree that it is preferable to add the @thunk outside project, I would argue that inserting a thunk complicates the point this section is trying to make.

However, perhaps adding a sentence at the end of this section to clarify the thunk/project order might be a good alternative?

@st--
Copy link
Contributor Author

st-- commented Sep 23, 2021

I'm happy to change it to whatever IS the recommended way to do this. I just got quite confused by looking at the FAQ entries for @thunk and for ProjectTo which both say effectively "this is the last thing you should be doing", so it's not clear which order you should do them in if you do need both. Is it @thunk(ProjectTo(<all the computation>)) or ProjectTo(@thunk(<all the computation>))?

@oxinabox
Copy link
Member

Fair.
Thanks.

@thunk is the lastest.

project is the last thing to do in a sequence of computations in order to compute the output.

Whereas @thunk should wrap the whole sequence of computations, Including the final project step
Rather thank last, I would say it is outermost.

Comment on lines +31 to +33
While this is more verbose, it ensures that if an error is thrown during the `pullback` the [`gensym`](https://docs.julialang.org/en/v1/base/base/#Base.gensym) name of the local function will include the name you gave it.
This makes it a lot simpler to debug from the stacktrace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph was in the @not_implemented section but seems to actually belong here!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct.
I guess text was inserted in wrong place

Comment on lines -265 to -266
While this is more verbose, it ensures that if an error is thrown during the `pullback` the [`gensym`](https://docs.julialang.org/en/v1/base/base/#Base.gensym) name of the local function will include the name you gave it.
This makes it a lot simpler to debug from the stacktrace.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to "Code Style" at the top.

)
```

Do not use `@not_implemented` if the differential does not exist mathematically (use `NoTangent()` instead).

While this is more verbose, it ensures that if an error is thrown during the `pullback` the [`gensym`](https://docs.julialang.org/en/v1/base/base/#Base.gensym) name of the local function will include the name you gave it.
This makes it a lot simpler to debug from the stacktrace.
Note: [ChainRulesTestUtils.jl](https://github.com/JuliaDiff/ChainRulesTestUtils.jl) marks `@not_implemented` differentials as "test broken".
Copy link
Contributor Author

@st-- st-- Sep 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To document the new behaviour of JuliaDiff/ChainRulesTestUtils.jl#218

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did that even before. for most cases.
The case it didn't handle was for things where the tangent was determined to be NoTangent.

But regardless this is a good change

@st-- st-- changed the title Clarify order of @thunk and ProjectTo in docs Clarify "writing good rules" documentation Sep 23, 2021
@oxinabox oxinabox changed the title Clarify "writing good rules" documentation Clarify "writing good rules" documentation re ProjectTo and thunks Sep 23, 2021
@oxinabox oxinabox changed the title Clarify "writing good rules" documentation re ProjectTo and thunks Clarify "writing good rules" documentation Sep 23, 2021
@oxinabox
Copy link
Member

thanks

@oxinabox oxinabox merged commit 2ec2549 into JuliaDiff:master Sep 23, 2021
@st-- st-- deleted the patch-2 branch September 27, 2021 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants