Repository navigation
Make ForwardDiff a weak dependency extension - #131
Conversation
- Move ForwardDiff-specific code to PreallocationToolsForwardDiffExt - ForwardDiff is now an optional dependency loaded via package extensions - Default implementations provided when ForwardDiff is not available - Uses ref cells to allow extension to modify behavior at runtime - All ForwardDiff-specific methods for Dual types moved to extension
|
GPU tests are failing, because ForwarDiff.jl started iterating over arrays when constructing seeds in version 1.0.1 rather than broadcasting as in previous versions. Tests are failing due to this. |
|
That wasn't ForwardDiff v1.0.1, it was a DifferentiationInterface.jl thing. I had just fixed that last week though: SciML/OrdinaryDiffEq.jl#2788, but it looks like I forgot to tag that so I'll get that tagged right away. |
|
Interesting. I understand the performance reason (well, the high level part - not the details), but I am telling you that: Passes with ForwardDiff 1.0.0 (Environment 1), whereas it fails with 1.0.1 (Environment 2). Environment 1: Environment 2: But in the end... as long as it works... 🤷 |
|
But that's not with OrdinaryDiffEqDifferentiation#master |
Summary
This PR converts ForwardDiff from a hard dependency to a weak dependency using Julia package extensions, reducing the dependency load for users who don't need automatic differentiation features.
Changes
[deps]to[weakdeps]in Project.tomlPreallocationToolsForwardDiffExtextension module inext/FixedSizeDiffCacheconstructor for Dual arrayschunksizemethod forForwardDiff.Dualtypesget_tmpmethods forForwardDiff.DualtypesImplementation Details
The implementation uses mutable ref cells (
DUAL_ARRAY_CREATORandCHUNK_SIZE_FUNC) that get set by the extension's__init__function when ForwardDiff is loaded. This avoids method overwriting issues while maintaining full backward compatibility.Benefits
Testing
The package tests pass with ForwardDiff loaded. The extension properly activates when ForwardDiff is imported, providing all the necessary dual number support.