-
Notifications
You must be signed in to change notification settings - Fork 18
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 weak dependencies if supported #68
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #68 +/- ##
==========================================
+ Coverage 83.82% 84.36% +0.54%
==========================================
Files 6 8 +2
Lines 476 467 -9
==========================================
- Hits 399 394 -5
+ Misses 77 73 -4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
This is a great PR, thanks! I need to study this feature before I can review the PR. But if someone else approves the PR, I am happy to merge. |
Maybe in addition to the Pkg docs linked above, it could be interesting to check Kristoffer's PR to PGFPlotsX: KristofferC/PGFPlotsX.jl#306 |
Can you quasi-namespace the extensions? I.e. AbstractDifferentiationForwardDiffExt? Otherwise you'll get collisions. |
src/AbstractDifferentiation.jl
Outdated
@require FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000" include("finitedifferences.jl") | ||
@require Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" include("tracker.jl") | ||
@require Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" begin | ||
@static if !EXTENSIONS_SUPPORTED |
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.
can move this out of the init definition
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.
I tried many different versions and this was the (only?) one that seemed to work. But I'll give it another shot.
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.
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, I think the problem was that I had put using Requires
in the same check (outside of ìnit) which does not work. Having to if
statements seems to work though.
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.
Actually, I just managed to reproduce the problem: tpapp/LogDensityProblemsAD.jl@e4194f8 failed with https://github.com/tpapp/LogDensityProblemsAD.jl/actions/runs/4226767173/jobs/7340561574
src/AbstractDifferentiation.jl
Outdated
@static if VERSION >= v"1.6" | ||
ZygoteBackend() = ReverseRuleConfigBackend(Zygote.ZygoteRuleConfig()) | ||
@require Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" include("../ext/ZygoteExt.jl") |
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 is this Zygote one versioned off?
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.
For simplicity, just bump to LTS?
Sure, I've seen this discussion in other places and Kristoffer said that probably it would be reasonable even if the collision issues are fixed upstream. It's a bit hacky though IMO since just adding a prefix does not guarantee that there won't be any collisions - e.g., an extension such as |
…erentiation.jl into dw/weakdeps
Well, well. Updating to |
To summarize the last commits:
The PR is ready for a thorough review and updated with the current practices for defining extensions. |
module AbstractDifferentiationChainRulesCoreExt | ||
|
||
import AbstractDifferentiation as AD | ||
using ChainRulesCore: ChainRulesCore |
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.
This is not being imported using the ..ChainRulesCore
that's needed for Requires
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.
It's not loaded with Requires.
using Requires: @require | ||
include("../ext/AbstractDifferentiationChainRulesCoreExt.jl") |
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.
I see, because there's no backwards compat to do? It's a bit odd but fine I guess.
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.
I followed the same pattern as in other packages: pre-Julia 1.9 ChainRulesCore is a proper dependency (no Requires involved) whereas in >= 1.9 it's an extension.
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.
This looks correct.
This PR replaces the use of Requires with weak dependencies on Julia >= 1.9 (https://pkgdocs.julialang.org/dev/creating-packages/#Weak-dependencies).
Currently the PR is breaking since it removes the
AD
alias and export. I couldn't get the Requires/weak dependencies submodules working with theAD
alias on a first try (I tried different combinations ofusing AbstractDifferentiation: AD
,using AbstractDifferentiation: AbstractDifferentiation
,using AD: AD
etc.). I'm sure there's some way to fix it but I did not spend more time on it sinceas
" feature in Julia >= 1.6,FDM
in the docs but does not define it in the package itself)Edit: Shouldn't be merged until the Registrator deployment of JuliaRegistries/Registrator.jl#397 is done.Edit: A few additional changes (see below):
@assert length(x) == 1; x[1]
withonly(x)