Skip to content
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

Use ChainRulesCore.@not_implemented and extend tests #308

Merged
merged 3 commits into from
May 17, 2021

Conversation

devmotion
Copy link
Member

This PR updates the differentials to use the new @not_implemented macro instead of custom thunks with error("not implemented"). Additionally, now all differentials are tested.

The update to @not_implemented has multiple advantages:

  • officially supported by ChainRulesTestUtils and hence it is possible to test even incomplete rules
  • provide better debugging information for users if they try to perform computations with the differential that is not implemented (includes module and location where the rule is defined and an additional message that explains the incomplete status and contains a link to the corresponding Github issue)
  • fixes Gradient of SpecialFunctions.bessel... errors with SpecialFunctions >= 1 - support thunks? FluxML/Zygote.jl#873: now it is possible to use even incomplete rules with Zygote

I assume the rules in ChainRules should be updated in the same way @oxinabox?

@codecov
Copy link

codecov bot commented Apr 27, 2021

Codecov Report

Merging #308 (c1f7012) into master (feccbf4) will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #308      +/-   ##
==========================================
+ Coverage   89.28%   89.31%   +0.02%     
==========================================
  Files          12       12              
  Lines        2633     2640       +7     
==========================================
+ Hits         2351     2358       +7     
  Misses        282      282              
Flag Coverage Δ
unittests 89.31% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/chainrules.jl 100.00% <ø> (ø)

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 feccbf4...c1f7012. Read the comment docs.

@oxinabox
Copy link
Contributor

I assume the rules in ChainRules should be updated in the same way @oxinabox?

Yeah.
I look forward to removing them so we can stop this

(hankelh2(ν - 1, x) - hankelh2(ν + 1, x)) / 2,
),
)
ChainRulesCore.@scalar_rule(
polygamma(m, x),
(
ChainRulesCore.@thunk(error("not implemented")),
ChainRulesCore.DoesNotExist(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why wasn't it already the case?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I did not pay enough attention when I moved the rules from ChainRules and just replaced all NaN with @thunk(error("not implemented")) (https://github.com/JuliaDiff/ChainRules.jl/blob/bf54b2f0e77fb05d3bc42004c448b3db0432f9cd/src/rulesets/packages/SpecialFunctions.jl#L57).

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.

Gradient of SpecialFunctions.bessel... errors with SpecialFunctions >= 1 - support thunks?
3 participants