From 11bf04eb190ce8542a23fb745953de107e12a886 Mon Sep 17 00:00:00 2001 From: "Guillaume Dalle (bot)" <185490550+gdalle-bot@users.noreply.github.com> Date: Mon, 12 Oct 2026 09:43:26 +0000 Subject: [PATCH] fix: restore Diffractor support on Julia 1.10 and 1.11 Work around the broadcasting bug of Diffractor v0.2.7 to v0.2.10 (JuliaDiff/Diffractor.jl#290) by defining the missing `FwdMap{E}` constructor in the extension. Bump the compat bound to v0.2.10 and reactivate the Diffractor test group. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017t9zghYPb67WRAZPDhMCNt --- .github/workflows/Test.yml | 6 ++++- DifferentiationInterface/CHANGELOG.md | 1 + DifferentiationInterface/Project.toml | 2 +- DifferentiationInterface/README.md | 2 +- .../docs/src/explanation/backends.md | 5 ++-- .../DifferentiationInterfaceDiffractorExt.jl | 11 +++++++- .../test/Back/Diffractor/Project.toml | 12 +++++++++ .../test/Back/Diffractor/test.jl | 26 +++++++++++++++++++ 8 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 DifferentiationInterface/test/Back/Diffractor/Project.toml create mode 100644 DifferentiationInterface/test/Back/Diffractor/test.jl diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 5918d3185..cbac2fb06 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -91,7 +91,7 @@ jobs: group: - ChainRules - DifferentiateWith - # - Diffractor + - Diffractor - Enzyme - FastDifferentiation - FiniteDiff @@ -111,6 +111,10 @@ jobs: exclude: - skip_past: true version: '1.10' + - version: '1.12' + group: Diffractor + - version: '1.13' + group: Diffractor env: JULIA_DI_TEST_TYPE: 'Back' JULIA_DI_TEST_GROUP: ${{ matrix.group }} diff --git a/DifferentiationInterface/CHANGELOG.md b/DifferentiationInterface/CHANGELOG.md index e75526fbf..751cf91d0 100644 --- a/DifferentiationInterface/CHANGELOG.md +++ b/DifferentiationInterface/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Speed up `pick_batchsize` when the batch size is only known at run time ([#1076](https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/1076)) +- Restore Diffractor support on Julia 1.10 and 1.11 by working around a broadcasting bug ([#1079](https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/1079)) ## [0.7.21](https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.7.20...v0.7.21) diff --git a/DifferentiationInterface/Project.toml b/DifferentiationInterface/Project.toml index a2a694816..6a9d36863 100644 --- a/DifferentiationInterface/Project.toml +++ b/DifferentiationInterface/Project.toml @@ -63,7 +63,7 @@ Adapt = "4.5.0" ADTypes = "1.23.0" ChainRulesCore = "1.23.0" DiffResults = "1.1.0" -Diffractor = "=0.2.6" +Diffractor = "=0.2.10" Enzyme = "0.13.39" EnzymeCore = "0.8.8" FastDifferentiation = "0.4.3" diff --git a/DifferentiationInterface/README.md b/DifferentiationInterface/README.md index b6c2c6a59..1f285fefe 100644 --- a/DifferentiationInterface/README.md +++ b/DifferentiationInterface/README.md @@ -29,7 +29,7 @@ This package provides a unified syntax to differentiate functions, including: We support the following backends defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl): - [ChainRulesCore.jl](https://github.com/JuliaDiff/ChainRulesCore.jl) -- [Diffractor.jl](https://github.com/JuliaDiff/Diffractor.jl) (currently broken) +- [Diffractor.jl](https://github.com/JuliaDiff/Diffractor.jl) (only on Julia 1.10 and 1.11) - [Enzyme.jl](https://github.com/EnzymeAD/Enzyme.jl) (see below) - [FastDifferentiation.jl](https://github.com/brianguenter/FastDifferentiation.jl) - [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl) diff --git a/DifferentiationInterface/docs/src/explanation/backends.md b/DifferentiationInterface/docs/src/explanation/backends.md index 36193920d..b719e2694 100644 --- a/DifferentiationInterface/docs/src/explanation/backends.md +++ b/DifferentiationInterface/docs/src/explanation/backends.md @@ -120,9 +120,10 @@ Same-point preparation runs the forward sweep and returns the pullback closure. We only implement `pushforward`. -!!! danger +!!! warning - The latest releases of Diffractor [broke DifferentiationInterface](https://github.com/JuliaDiff/Diffractor.jl/issues/290). + The latest release of Diffractor (v0.2.10) cannot be loaded on Julia 1.12 and above, so this backend only works on Julia 1.10 and 1.11. + To make broadcasting work, our extension has to patch [a Diffractor bug](https://github.com/JuliaDiff/Diffractor.jl/issues/290) with a bit of type piracy. ### Enzyme diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceDiffractorExt/DifferentiationInterfaceDiffractorExt.jl b/DifferentiationInterface/ext/DifferentiationInterfaceDiffractorExt/DifferentiationInterfaceDiffractorExt.jl index e784e4d96..8bf263d85 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceDiffractorExt/DifferentiationInterfaceDiffractorExt.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceDiffractorExt/DifferentiationInterfaceDiffractorExt.jl @@ -2,7 +2,16 @@ module DifferentiationInterfaceDiffractorExt using ADTypes: ADTypes, AutoDiffractor import DifferentiationInterface as DI -using Diffractor: DiffractorRuleConfig, TaylorTangentIndex, ZeroBundle, bundle, ∂☆ +using Diffractor: + Diffractor, AbstractTangentBundle, FwdMap, TaylorTangentIndex, ZeroBundle, bundle, ∂☆ + +#= +Workaround for https://github.com/JuliaDiff/Diffractor.jl/issues/290 (type piracy). +The forward broadcast rule of Diffractor v0.2.7 to v0.2.10 calls `FwdMap{E}(f)` instead of `FwdMap{N,E}(f)`, which has no method. +=# +function Diffractor.FwdMap{E}(f::T) where {E, N, T <: AbstractTangentBundle{N}} + return FwdMap{N, E, T}(f) +end DI.check_available(::AutoDiffractor) = true DI.inplace_support(::AutoDiffractor) = DI.InPlaceNotSupported() diff --git a/DifferentiationInterface/test/Back/Diffractor/Project.toml b/DifferentiationInterface/test/Back/Diffractor/Project.toml new file mode 100644 index 000000000..910394a1a --- /dev/null +++ b/DifferentiationInterface/test/Back/Diffractor/Project.toml @@ -0,0 +1,12 @@ +[deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" +DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63" +DifferentiationInterfaceTest = "a82114a7-5aa3-49a8-9643-716bb13727a3" +Diffractor = "9f5e2b26-1114-432f-b630-d3fe2085c51c" +ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" +SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5" +SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[sources] +DifferentiationInterface = { path = "../../.." } diff --git a/DifferentiationInterface/test/Back/Diffractor/test.jl b/DifferentiationInterface/test/Back/Diffractor/test.jl new file mode 100644 index 000000000..86ac75aea --- /dev/null +++ b/DifferentiationInterface/test/Back/Diffractor/test.jl @@ -0,0 +1,26 @@ +include("../../testutils.jl") + +using DifferentiationInterface, DifferentiationInterfaceTest +using Diffractor: Diffractor +using Test + +using ExplicitImports +check_no_implicit_imports(DifferentiationInterface) + +for backend in [AutoDiffractor()] + @test check_available(backend) + @test !check_inplace(backend) +end + +@testset "Broadcast" begin + # https://github.com/JuliaDiff/Diffractor.jl/issues/290 + x, dx = [1.0, 2.0], [3.0, 4.0] + @test pushforward(x -> sin.(x), AutoDiffractor(), x, (dx,))[1] ≈ cos.(x) .* dx +end + +test_differentiation( + AutoDiffractor(), + default_scenarios(; linalg = false); + excluded = SECOND_ORDER, + logging = LOGGING, +);