Skip to content

Commit

Permalink
Julia 1.6 compat (#243)
Browse files Browse the repository at this point in the history
* Parsing works

* Fix JET compat

* Some tests are passing

* Skip formal tests

* Widen Symbolics compat

* Use Compat

* Replace with @compat

* Widen FiniteDiff compat

* No test on Diffractor

* Less diff

* Fix stack

* Remove more Diffractor

* No FastDifferentiation

* Fix docs

* Remove extensions

* Remove Tapir

* Add Compat 3

* Remove Symbolics

* Remove compat

* Fix stuff

* Remove PolyesterForwardDiff

* Fix

* Fix type stability

* Reput everything in docs

* Fix stdlib compats

* Remove stdlib compats

* Pkg dark magic

* No SparseDiffTools

* Right project

* Use the right DI

* Fix

* FiniteDiff is 1.10

* Fix failing tests

* Fix Compat

* Fix

* Fix

* Stdlib compat

* Relax FillArrays

* Force DI compat bounds in tmp env

* Revert some compat bounds

* FiniteDiff is a subset of FiniteDifferences

* Version bumps

* Fix FiniteDiff vs FiniteDifferences

* Docs warning
  • Loading branch information
gdalle authored May 6, 2024
1 parent 571133f commit db908fb
Show file tree
Hide file tree
Showing 32 changed files with 407 additions and 312 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
dir: './DifferentiationInterfaceTest'
version:
- '1'
- '1.6'
os:
- ubuntu-latest
arch:
Expand All @@ -46,6 +47,14 @@ jobs:
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- name: Dev dependencies (temporary)
run: julia --project=${{ matrix.pkg.dir}}/ -e '
using Pkg;
Pkg.Registry.update();
if "${{ matrix.pkg.name}}" == "DifferentiationInterfaceTest";
Pkg.develop(PackageSpec(path="./DifferentiationInterface"));
end;
Pkg.instantiate();'
- uses: julia-actions/julia-runtest@v1
with:
project: ${{ matrix.pkg.dir }}
Expand Down
32 changes: 12 additions & 20 deletions DifferentiationInterface/Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name = "DifferentiationInterface"
uuid = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
authors = ["Guillaume Dalle", "Adrian Hill"]
version = "0.3.3"
version = "0.3.4"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[weakdeps]
Expand All @@ -20,7 +22,6 @@ FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
Tapir = "07d77754-e150-4737-8c94-cd238a1fb45b"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Expand All @@ -44,29 +45,32 @@ DifferentiationInterfaceZygoteExt = "Zygote"
[compat]
ADTypes = "1.0.0"
ChainRulesCore = "1.23.0"
Compat = "3,4"
Diffractor = "=0.2.6"
DocStringExtensions = "0.9.3"
Enzyme = "0.11.20,0.12"
FastDifferentiation = "0.3.9"
FillArrays = "1.9.3"
FillArrays = "1.7.0"
FiniteDiff = "2.23.1"
FiniteDifferences = "0.12.31"
ForwardDiff = "0.10.36"
LinearAlgebra = "1"
LinearAlgebra = "<0.0.1,1"
PackageExtensionCompat = "1.0.2"
PolyesterForwardDiff = "0.1.1"
ReverseDiff = "1.15.1"
SparseArrays = "1"
SparseArrays = "<0.0.1,1"
Symbolics = "5.27.1"
Tapir = "0.2.4"
Tracker = "0.2.33"
Zygote = "0.6.69"
julia = "1.10"
julia = "1.6"

[extras]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DifferentiationInterfaceTest = "a82114a7-5aa3-49a8-9643-716bb13727a3"
# DifferentiationInterfaceTest = "a82114a7-5aa3-49a8-9643-716bb13727a3"
Diffractor = "9f5e2b26-1114-432f-b630-d3fe2085c51c"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
Expand All @@ -92,24 +96,12 @@ test = [
"ADTypes",
"Aqua",
"DataFrames",
"DifferentiationInterfaceTest",
"Diffractor",
# "DifferentiationInterfaceTest",
"Documenter",
"Enzyme",
"FastDifferentiation",
"FiniteDiff",
"FiniteDifferences",
"ForwardDiff",
"JET",
"JuliaFormatter",
"Pkg",
"PolyesterForwardDiff",
"ReverseDiff",
"SparseArrays",
"SparseConnectivityTracer",
"Symbolics",
"Tapir",
"Test",
"Tracker",
"Zygote",
]
10 changes: 10 additions & 0 deletions DifferentiationInterface/docs/src/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ For sparse backends, only the Jacobian and Hessian operators are implemented dif
backend_table #hide
```

!!! danger "Compatibility with Julia 1.6"
As of version 0.3.4, DifferentiationInterface.jl is compatible with Julia 1.6, the Long Term Support (LTS) version of the language.
However, we were only able to test the following backends on LTS:
- FiniteDifferences.jl
- ForwardDiff.jl
- ReverseDiff.jl
- Tracker.jl
- Zygote.jl
We strongly recommend that users upgrade to Julia 1.10, where all backends are tested.

## Checks

### Availability
Expand Down
2 changes: 1 addition & 1 deletion DifferentiationInterface/docs/src/overloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ using FiniteDiff: FiniteDiff
using FiniteDifferences: FiniteDifferences
using ForwardDiff: ForwardDiff
using PolyesterForwardDiff: PolyesterForwardDiff
using Symbolics: Symbolics
using ReverseDiff: ReverseDiff
using Symbolics: Symbolics
using Tapir: Tapir
using Tracker: Tracker
using Zygote: Zygote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using ChainRulesCore:
RuleConfig,
frule_via_ad,
rrule_via_ad
using Compat
import DifferentiationInterface as DI
using DifferentiationInterface: DifferentiateWith, NoPullbackExtras, NoPushforwardExtras

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function ChainRulesCore.frule((_, dx), dw::DifferentiateWith, x)
(; f, backend) = dw
@compat (; f, backend) = dw
y, dy = DI.value_and_pushforward(f, backend, x, dx)
return y, dy
end

function ChainRulesCore.rrule(dw::DifferentiateWith, x)
(; f, backend) = dw
@compat (; f, backend) = dw
y, pullbackfunc = DI.value_and_pullback_split(f, backend, x)
pullbackfunc_adjusted(dy) = (NoTangent(), pullbackfunc(dy))
return y, pullbackfunc_adjusted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module DifferentiationInterfaceForwardDiffExt

using ADTypes: AbstractADType, AutoForwardDiff
using Base: Fix1
using Compat
import DifferentiationInterface as DI
using DifferentiationInterface:
DerivativeExtras,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
function compute_ydual_onearg(
f::F, x, dx, extras::ForwardDiffOneArgPushforwardExtras{T}
) where {F,T}
(; xdual_tmp) = extras
@compat (; xdual_tmp) = extras
make_dual!(T, xdual_tmp, x, dx)
ydual = f(xdual_tmp)
return ydual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
function compute_ydual_twoarg(
f!::F, y, x::Number, dx, extras::ForwardDiffTwoArgPushforwardExtras{T}
) where {F,T}
(; ydual_tmp) = extras
@compat (; ydual_tmp) = extras
xdual_tmp = make_dual(T, x, dx)
f!(ydual_tmp, xdual_tmp)
return ydual_tmp
Expand All @@ -26,7 +26,7 @@ end
function compute_ydual_twoarg(
f!::F, y, x, dx, extras::ForwardDiffTwoArgPushforwardExtras{T}
) where {F,T}
(; xdual_tmp, ydual_tmp) = extras
@compat (; xdual_tmp, ydual_tmp) = extras
make_dual!(T, xdual_tmp, x, dx)
f!(ydual_tmp, xdual_tmp)
return ydual_tmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using ADTypes: AutoTracker
import DifferentiationInterface as DI
using DifferentiationInterface: NoGradientExtras, NoPullbackExtras
using Tracker: Tracker, back, data, forward, gradient, jacobian, param, withgradient
using Compat

DI.check_available(::AutoTracker) = true
DI.twoarg_support(::AutoTracker) = DI.TwoArgNotSupported()
Expand Down Expand Up @@ -34,12 +35,12 @@ end
DI.prepare_gradient(f, ::AutoTracker, x) = NoGradientExtras()

function DI.value_and_gradient(f, ::AutoTracker, x, ::NoGradientExtras)
(; val, grad) = withgradient(f, x)
@compat (; val, grad) = withgradient(f, x)
return val, data(only(grad))
end

function DI.gradient(f, ::AutoTracker, x, ::NoGradientExtras)
(; grad) = withgradient(f, x)
@compat (; grad) = withgradient(f, x)
return data(only(grad))
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using DifferentiationInterface:
using DocStringExtensions
using Zygote:
ZygoteRuleConfig, gradient, hessian, jacobian, pullback, withgradient, withjacobian
using Compat

DI.check_available(::AutoZygote) = true
DI.twoarg_support(::AutoZygote) = DI.TwoArgNotSupported()
Expand Down Expand Up @@ -37,7 +38,7 @@ end
DI.prepare_gradient(f, ::AutoZygote, x) = NoGradientExtras()

function DI.value_and_gradient(f, ::AutoZygote, x, ::NoGradientExtras)
(; val, grad) = withgradient(f, x)
@compat (; val, grad) = withgradient(f, x)
return val, only(grad)
end

Expand Down
6 changes: 6 additions & 0 deletions DifferentiationInterface/src/DifferentiationInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ using ADTypes:
AutoTapir,
AutoTracker,
AutoZygote
using Compat
using DocStringExtensions
using FillArrays: OneElement
using LinearAlgebra: Symmetric, Transpose, dot, parent, transpose
using PackageExtensionCompat: @require_extensions
using SparseArrays: SparseMatrixCSC, nonzeros, nzrange, rowvals, sparse

abstract type Extras end
Expand Down Expand Up @@ -64,6 +66,10 @@ include("sparse/hessian.jl")

include("translation/differentiate_with.jl")

function __init__()
@require_extensions
end

export SecondOrder

export value_and_pushforward!, value_and_pushforward
Expand Down
12 changes: 6 additions & 6 deletions DifferentiationInterface/src/first_order/pullback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
function value_and_pullback_onearg_aux(
f::F, backend, x, dy, extras::PushforwardPullbackExtras
) where {F}
(; pushforward_extras) = extras
@compat (; pushforward_extras) = extras
y = f(x)
dx = if x isa Number && y isa Number
dy * pushforward(f, backend, x, one(x), pushforward_extras)
Expand Down Expand Up @@ -170,7 +170,7 @@ end
function value_and_pullback_twoarg_aux(
f!::F, y, backend, x, dy, extras::PushforwardPullbackExtras
) where {F}
(; pushforward_extras) = extras
@compat (; pushforward_extras) = extras
dx = if x isa Number && y isa AbstractArray
dot(dy, pushforward(f!, y, backend, x, one(x), pushforward_extras))
elseif x isa AbstractArray && y isa AbstractArray
Expand Down Expand Up @@ -235,12 +235,12 @@ struct OneArgPullbackFunc!{B,F,X,E}
end

function (pbf::OneArgPullbackFunc)(dy)
(; f, backend, x, extras) = pbf
@compat (; f, backend, x, extras) = pbf
return pullback(f, backend, x, dy, extras)
end

function (pbf::OneArgPullbackFunc!)(dx, dy)
(; f, backend, x, extras) = pbf
@compat (; f, backend, x, extras) = pbf
return pullback!(f, dx, backend, x, dy, extras)
end

Expand Down Expand Up @@ -279,12 +279,12 @@ struct TwoArgPullbackFunc!{B,F,X,E}
end

function (pbf::TwoArgPullbackFunc)(y, dy)
(; f!, backend, x, extras) = pbf
@compat (; f!, backend, x, extras) = pbf
return pullback(f!, y, backend, x, dy, extras)
end

function (pbf::TwoArgPullbackFunc!)(y, dx, dy)
(; f!, backend, x, extras) = pbf
@compat (; f!, backend, x, extras) = pbf
return pullback!(f!, y, dx, backend, x, dy, extras)
end

Expand Down
4 changes: 2 additions & 2 deletions DifferentiationInterface/src/first_order/pushforward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ end
function value_and_pushforward_onearg_aux(
f::F, backend, x, dx, extras::PullbackPushforwardExtras
) where {F}
(; pullback_extras) = extras
@compat (; pullback_extras) = extras
y, pullbackfunc = value_and_pullback_split(f, backend, x, pullback_extras)
dy = if x isa Number && y isa Number
dx * pullbackfunc(one(y))
Expand Down Expand Up @@ -159,7 +159,7 @@ end
function value_and_pushforward_twoarg_aux(
f!::F, y, backend, x, dx, extras::PullbackPushforwardExtras
) where {F}
(; pullback_extras) = extras
@compat (; pullback_extras) = extras
dy = if x isa Number && y isa AbstractArray
map(CartesianIndices(y)) do i
dx * pullback(f!, y, backend, x, basis(backend, y, i), pullback_extras)
Expand Down
16 changes: 8 additions & 8 deletions DifferentiationInterface/src/second_order/hvp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,27 @@ function hvp(
end

function hvp_aux(f::F, backend, x, v, extras::ForwardOverForwardHVPExtras) where {F}
(; inner_gradient_closure, outer_pushforward_extras) = extras
@compat (; inner_gradient_closure, outer_pushforward_extras) = extras
return pushforward(
inner_gradient_closure, outer(backend), x, v, outer_pushforward_extras
)
end

function hvp_aux(f::F, backend, x, v, extras::ForwardOverReverseHVPExtras) where {F}
(; inner_gradient_closure, outer_pushforward_extras) = extras
@compat (; inner_gradient_closure, outer_pushforward_extras) = extras
return pushforward(
inner_gradient_closure, outer(backend), x, v, outer_pushforward_extras
)
end

function hvp_aux(f::F, backend, x, v, extras::ReverseOverForwardHVPExtras) where {F}
(; inner_pushforward_closure_generator, outer_gradient_extras) = extras
@compat (; inner_pushforward_closure_generator, outer_gradient_extras) = extras
inner_pushforward_closure = inner_pushforward_closure_generator(v)
return gradient(inner_pushforward_closure, outer(backend), x, outer_gradient_extras)
end

function hvp_aux(f::F, backend, x, v, extras::ReverseOverReverseHVPExtras) where {F}
(; inner_gradient_closure, outer_pullback_extras) = extras
@compat (; inner_gradient_closure, outer_pullback_extras) = extras
return pullback(inner_gradient_closure, outer(backend), x, v, outer_pullback_extras)
end

Expand All @@ -157,26 +157,26 @@ function hvp!(
end

function hvp_aux!(f::F, p, backend, x, v, extras::ForwardOverForwardHVPExtras) where {F}
(; inner_gradient_closure, outer_pushforward_extras) = extras
@compat (; inner_gradient_closure, outer_pushforward_extras) = extras
return pushforward!(
inner_gradient_closure, p, outer(backend), x, v, outer_pushforward_extras
)
end

function hvp_aux!(f::F, p, backend, x, v, extras::ForwardOverReverseHVPExtras) where {F}
(; inner_gradient_closure, outer_pushforward_extras) = extras
@compat (; inner_gradient_closure, outer_pushforward_extras) = extras
return pushforward!(
inner_gradient_closure, p, outer(backend), x, v, outer_pushforward_extras
)
end

function hvp_aux!(f::F, p, backend, x, v, extras::ReverseOverForwardHVPExtras) where {F}
(; inner_pushforward_closure_generator, outer_gradient_extras) = extras
@compat (; inner_pushforward_closure_generator, outer_gradient_extras) = extras
inner_pushforward_closure = inner_pushforward_closure_generator(v)
return gradient!(inner_pushforward_closure, p, outer(backend), x, outer_gradient_extras)
end

function hvp_aux!(f::F, p, backend, x, v, extras::ReverseOverReverseHVPExtras) where {F}
(; inner_gradient_closure, outer_pullback_extras) = extras
@compat (; inner_gradient_closure, outer_pullback_extras) = extras
return pullback!(inner_gradient_closure, p, outer(backend), x, v, outer_pullback_extras)
end
Loading

0 comments on commit db908fb

Please sign in to comment.