diff --git a/lib/NonlinearSolveFirstOrder/test/rootfind_tests.jl b/lib/NonlinearSolveFirstOrder/test/rootfind_tests.jl index 3aa61b256..393399589 100644 --- a/lib/NonlinearSolveFirstOrder/test/rootfind_tests.jl +++ b/lib/NonlinearSolveFirstOrder/test/rootfind_tests.jl @@ -9,11 +9,22 @@ end using LineSearches: LineSearches using BenchmarkTools: @ballocated using StaticArrays: @SVector - using Zygote, Enzyme, ForwardDiff, FiniteDiff + using Zygote, ForwardDiff, FiniteDiff + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0) - @testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme()) + # Filter autodiff backends based on Julia version + autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for ad in autodiff_backends @testset "$(nameof(typeof(linesearch)))" for linesearch in ( LineSearchesJL(; method = LineSearches.Static(), autodiff = ad), LineSearchesJL(; method = LineSearches.BackTracking(), autodiff = ad), @@ -93,14 +104,25 @@ end using ADTypes, Random, LinearSolve, LinearAlgebra using BenchmarkTools: @ballocated using StaticArrays: @SVector - using Zygote, Enzyme, ForwardDiff, FiniteDiff + using Zygote, ForwardDiff, FiniteDiff + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end preconditioners = [ (u0) -> nothing, u0 -> ((args...) -> (Diagonal(rand!(similar(u0))), nothing)) ] - @testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme()) + # Filter autodiff backends based on Julia version + autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for ad in autodiff_backends u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0) @testset "[OOP] u0: $(typeof(u0))" for u0 in u0s @@ -176,7 +198,12 @@ end using ADTypes, LinearSolve, LinearAlgebra using BenchmarkTools: @ballocated using StaticArrays: @SVector - using Zygote, Enzyme, ForwardDiff, FiniteDiff + using Zygote, ForwardDiff, FiniteDiff + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end radius_update_schemes = [ RadiusUpdateSchemes.Simple, RadiusUpdateSchemes.NocedalWright, @@ -184,7 +211,13 @@ end RadiusUpdateSchemes.Yuan, RadiusUpdateSchemes.Fan, RadiusUpdateSchemes.Bastin ] - @testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme()) + # Filter autodiff backends based on Julia version + autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for ad in autodiff_backends @testset for radius_update_scheme in radius_update_schemes, linsolve in (nothing, LUFactorization(), KrylovJL_GMRES(), \) @@ -296,9 +329,20 @@ end using ADTypes, LinearSolve, LinearAlgebra using BenchmarkTools: @ballocated using StaticArrays: SVector, @SVector - using Zygote, Enzyme, ForwardDiff, FiniteDiff + using Zygote, ForwardDiff, FiniteDiff + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end - @testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme()) + # Filter autodiff backends based on Julia version + autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for ad in autodiff_backends solver = LevenbergMarquardt(; autodiff = ad) @testset "[OOP] u0: $(typeof(u0))" for u0 in ([1.0, 1.0], 1.0, @SVector([1.0, 1.0])) @@ -394,8 +438,14 @@ end @testitem "Simple Sparse AutoDiff" setup=[CoreRootfindTesting] tags=[:core] begin using ADTypes, SparseConnectivityTracer, SparseMatrixColorings - - @testset for ad in (AutoForwardDiff(), AutoFiniteDiff(), AutoZygote(), AutoEnzyme()) + + # Filter autodiff backends based on Julia version + autodiff_backends = [AutoForwardDiff(), AutoFiniteDiff(), AutoZygote()] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for ad in autodiff_backends @testset for u0 in ([1.0, 1.0], 1.0) prob = NonlinearProblem( NonlinearFunction(quadratic_f; sparsity = TracerSparsityDetector()), u0, 2.0 diff --git a/lib/NonlinearSolveHomotopyContinuation/test/allroots.jl b/lib/NonlinearSolveHomotopyContinuation/test/allroots.jl index 79a874a49..9031c5c01 100644 --- a/lib/NonlinearSolveHomotopyContinuation/test/allroots.jl +++ b/lib/NonlinearSolveHomotopyContinuation/test/allroots.jl @@ -2,9 +2,13 @@ using NonlinearSolve using NonlinearSolveHomotopyContinuation using SciMLBase: NonlinearSolution using ADTypes -using Enzyme import NaNMath +# Conditionally import Enzyme only if not on Julia prerelease +if isempty(VERSION.prerelease) + using Enzyme +end + alg = HomotopyContinuationJL{true}(; threading = false) @testset "scalar u" begin @@ -14,9 +18,13 @@ alg = HomotopyContinuationJL{true}(; threading = false) jac = function (u, p) return 2u - p[1] end - @testset "`NonlinearProblem` - $name" for (jac_or_autodiff, name) in [ - (AutoForwardDiff(), "no jac - forwarddiff"), (AutoEnzyme(), "no jac - enzyme"), ( - jac, "jac")] + # Filter autodiff backends based on Julia version + autodiff_backends = [(AutoForwardDiff(), "no jac - forwarddiff"), (jac, "jac")] + if isempty(VERSION.prerelease) + push!(autodiff_backends, (AutoEnzyme(), "no jac - enzyme")) + end + + @testset "`NonlinearProblem` - $name" for (jac_or_autodiff, name) in autodiff_backends if jac_or_autodiff isa Function jac = jac_or_autodiff autodiff = nothing @@ -107,11 +115,17 @@ fjac = function (u, p) 2*p[2]*u[2] 3*u[2]^2+2*p[2]*u[1]+1] end -@testset "vector u - $name" for (rhs, jac_or_autodiff, name) in [ - (f, AutoForwardDiff(), "oop + forwarddiff"), (f, AutoEnzyme(), "oop + enzyme"), ( - f, fjac, "oop + jac"), - (f!, AutoForwardDiff(), "iip + forwarddiff"), (f!, AutoEnzyme(), "iip + enzyme"), ( - f!, fjac!, "iip + jac")] +# Filter test cases based on Julia version +vector_test_cases = [ + (f, AutoForwardDiff(), "oop + forwarddiff"), (f, fjac, "oop + jac"), + (f!, AutoForwardDiff(), "iip + forwarddiff"), (f!, fjac!, "iip + jac") +] +if isempty(VERSION.prerelease) + push!(vector_test_cases, (f, AutoEnzyme(), "oop + enzyme")) + push!(vector_test_cases, (f!, AutoEnzyme(), "iip + enzyme")) +end + +@testset "vector u - $name" for (rhs, jac_or_autodiff, name) in vector_test_cases sol = nothing if jac_or_autodiff isa Function jac = jac_or_autodiff diff --git a/lib/NonlinearSolveHomotopyContinuation/test/single_root.jl b/lib/NonlinearSolveHomotopyContinuation/test/single_root.jl index 615c433e6..a9057e731 100644 --- a/lib/NonlinearSolveHomotopyContinuation/test/single_root.jl +++ b/lib/NonlinearSolveHomotopyContinuation/test/single_root.jl @@ -12,9 +12,13 @@ alg = HomotopyContinuationJL{false}(; threading = false) jac = function (u, p) return 2u - (p + 3) end - @testset "`NonlinearProblem` - $name" for (jac_or_autodiff, name) in [ - (AutoForwardDiff(), "no jac - forwarddiff"), (AutoEnzyme(), "no jac - enzyme"), ( - jac, "jac")] + # Filter autodiff backends based on Julia version + autodiff_backends = [(AutoForwardDiff(), "no jac - forwarddiff"), (jac, "jac")] + if isempty(VERSION.prerelease) + push!(autodiff_backends, (AutoEnzyme(), "no jac - enzyme")) + end + + @testset "`NonlinearProblem` - $name" for (jac_or_autodiff, name) in autodiff_backends if jac_or_autodiff isa Function jac = jac_or_autodiff autodiff = nothing @@ -96,11 +100,17 @@ jac = function (u, p) 2*p[2]*u[2] 3*u[2]^2+2*p[2]*u[1]+1] end -@testset "vector u - $name" for (rhs, jac_or_autodiff, name) in [ - (f, AutoForwardDiff(), "oop + forwarddiff"), (f, AutoEnzyme(), "oop + enzyme"), ( - f, jac, "oop + jac"), - (f!, AutoForwardDiff(), "iip + forwarddiff"), (f!, AutoEnzyme(), "iip + enzyme"), ( - f!, jac!, "iip + jac")] +# Filter test cases based on Julia version +vector_test_cases = [ + (f, AutoForwardDiff(), "oop + forwarddiff"), (f, jac, "oop + jac"), + (f!, AutoForwardDiff(), "iip + forwarddiff"), (f!, jac!, "iip + jac") +] +if isempty(VERSION.prerelease) + push!(vector_test_cases, (f, AutoEnzyme(), "oop + enzyme")) + push!(vector_test_cases, (f!, AutoEnzyme(), "iip + enzyme")) +end + +@testset "vector u - $name" for (rhs, jac_or_autodiff, name) in vector_test_cases if jac_or_autodiff isa Function jac = jac_or_autodiff autodiff = nothing diff --git a/lib/NonlinearSolveQuasiNewton/test/core_tests.jl b/lib/NonlinearSolveQuasiNewton/test/core_tests.jl index d22481b4c..d8b4c49cd 100644 --- a/lib/NonlinearSolveQuasiNewton/test/core_tests.jl +++ b/lib/NonlinearSolveQuasiNewton/test/core_tests.jl @@ -9,11 +9,22 @@ end using LineSearches: LineSearches using BenchmarkTools: @ballocated using StaticArrays: @SVector - using Zygote, Enzyme, ForwardDiff, FiniteDiff + using Zygote, ForwardDiff, FiniteDiff + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0) - @testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme()) + # Filter autodiff backends based on Julia version + autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for ad in autodiff_backends @testset "$(nameof(typeof(linesearch)))" for linesearch in ( # LineSearchesJL(; method = LineSearches.Static(), autodiff = ad), # LineSearchesJL(; method = LineSearches.BackTracking(), autodiff = ad), @@ -84,9 +95,20 @@ end using LineSearches: LineSearches using BenchmarkTools: @ballocated using StaticArrays: @SVector - using Zygote, Enzyme, ForwardDiff, FiniteDiff + using Zygote, ForwardDiff, FiniteDiff + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end - @testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme()) + # Filter autodiff backends based on Julia version + autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for ad in autodiff_backends @testset "$(nameof(typeof(linesearch)))" for linesearch in ( # LineSearchesJL(; method = LineSearches.Static(), autodiff = ad), # LineSearchesJL(; method = LineSearches.BackTracking(), autodiff = ad), @@ -157,9 +179,20 @@ end using LineSearches: LineSearches using BenchmarkTools: @ballocated using StaticArrays: @SVector - using Zygote, Enzyme, ForwardDiff, FiniteDiff + using Zygote, ForwardDiff, FiniteDiff + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end - @testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme()) + # Filter autodiff backends based on Julia version + autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for ad in autodiff_backends @testset "$(nameof(typeof(linesearch)))" for linesearch in ( # LineSearchesJL(; method = LineSearches.Static(), autodiff = ad), # LineSearchesJL(; method = LineSearches.BackTracking(), autodiff = ad), diff --git a/lib/SciMLJacobianOperators/test/core_tests.jl b/lib/SciMLJacobianOperators/test/core_tests.jl index e3b595221..fbbd51844 100644 --- a/lib/SciMLJacobianOperators/test/core_tests.jl +++ b/lib/SciMLJacobianOperators/test/core_tests.jl @@ -1,23 +1,32 @@ @testitem "Scalar Ops" begin using ADTypes, SciMLBase - using Enzyme, Zygote, ForwardDiff, FiniteDiff, ReverseDiff, Tracker + using Zygote, ForwardDiff, FiniteDiff, ReverseDiff, Tracker using SciMLJacobianOperators + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end reverse_ADs = [ - AutoEnzyme(), - AutoEnzyme(; mode = Enzyme.Reverse), AutoZygote(), AutoReverseDiff(), AutoTracker(), AutoFiniteDiff() ] + if isempty(VERSION.prerelease) + push!(reverse_ADs, AutoEnzyme()) + push!(reverse_ADs, AutoEnzyme(; mode = Enzyme.Reverse)) + end forward_ADs = [ - AutoEnzyme(), - AutoEnzyme(; mode = Enzyme.Forward), AutoForwardDiff(), AutoFiniteDiff() ] + if isempty(VERSION.prerelease) + push!(forward_ADs, AutoEnzyme()) + push!(forward_ADs, AutoEnzyme(; mode = Enzyme.Forward)) + end prob = NonlinearProblem(NonlinearFunction{false}((u, p) -> u^2 - p), 1.0, 2.0) @@ -85,22 +94,31 @@ end @testitem "Inplace Problems" begin using ADTypes, SciMLBase - using Enzyme, ForwardDiff, FiniteDiff, ReverseDiff + using ForwardDiff, FiniteDiff, ReverseDiff using SciMLJacobianOperators + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end reverse_ADs = [ - AutoEnzyme(), - AutoEnzyme(; mode = Enzyme.Reverse), AutoReverseDiff(), AutoFiniteDiff() ] + if isempty(VERSION.prerelease) + push!(reverse_ADs, AutoEnzyme()) + push!(reverse_ADs, AutoEnzyme(; mode = Enzyme.Reverse)) + end forward_ADs = [ - AutoEnzyme(), - AutoEnzyme(; mode = Enzyme.Forward), AutoForwardDiff(), AutoFiniteDiff() ] + if isempty(VERSION.prerelease) + push!(forward_ADs, AutoEnzyme()) + push!(forward_ADs, AutoEnzyme(; mode = Enzyme.Forward)) + end prob = NonlinearProblem( NonlinearFunction{true}((du, u, p) -> du .= u .^ 2 .- p .+ u[2] * u[1]), [1.0, 3.0], 2.0) @@ -174,24 +192,33 @@ end @testitem "Out-of-place Problems" begin using ADTypes, SciMLBase - using Enzyme, ForwardDiff, FiniteDiff, ReverseDiff, Zygote, Tracker + using ForwardDiff, FiniteDiff, ReverseDiff, Zygote, Tracker using SciMLJacobianOperators + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end reverse_ADs = [ - AutoEnzyme(), - AutoEnzyme(; mode = Enzyme.Reverse), AutoZygote(), AutoTracker(), AutoReverseDiff(), AutoFiniteDiff() ] + if isempty(VERSION.prerelease) + push!(reverse_ADs, AutoEnzyme()) + push!(reverse_ADs, AutoEnzyme(; mode = Enzyme.Reverse)) + end forward_ADs = [ - AutoEnzyme(), - AutoEnzyme(; mode = Enzyme.Forward), AutoForwardDiff(), AutoFiniteDiff() ] + if isempty(VERSION.prerelease) + push!(forward_ADs, AutoEnzyme()) + push!(forward_ADs, AutoEnzyme(; mode = Enzyme.Forward)) + end prob = NonlinearProblem( NonlinearFunction{false}((u, p) -> u .^ 2 .- p .+ u[2] * u[1]), [1.0, 3.0], 2.0) diff --git a/lib/SimpleNonlinearSolve/test/core/rootfind_tests.jl b/lib/SimpleNonlinearSolve/test/core/rootfind_tests.jl index 468e04916..a0f29c819 100644 --- a/lib/SimpleNonlinearSolve/test/core/rootfind_tests.jl +++ b/lib/SimpleNonlinearSolve/test/core/rootfind_tests.jl @@ -1,6 +1,11 @@ @testsnippet RootfindTestSnippet begin using StaticArrays, Random, LinearAlgebra, ForwardDiff, NonlinearSolveBase, SciMLBase - using ADTypes, PolyesterForwardDiff, Enzyme, ReverseDiff + using ADTypes, PolyesterForwardDiff, ReverseDiff + + # Conditionally import Enzyme only if not on Julia prerelease + if isempty(VERSION.prerelease) + using Enzyme + end quadratic_f(u, p) = u .* u .- p quadratic_f!(du, u, p) = (du .= u .* u .- p) @@ -47,13 +52,18 @@ end SimpleTrustRegion, (; kwargs...) -> SimpleTrustRegion(; kwargs..., nlsolve_update_rule = Val(true)) ) - @testset for autodiff in ( + # Filter autodiff backends based on Julia version + autodiff_backends = [ AutoForwardDiff(), AutoFiniteDiff(), AutoReverseDiff(), - AutoEnzyme(), nothing - ) + ] + if isempty(VERSION.prerelease) + push!(autodiff_backends, AutoEnzyme()) + end + + @testset for autodiff in autodiff_backends @testset "[OOP] u0: $(typeof(u0))" for u0 in ( [1.0, 1.0], @SVector[1.0, 1.0], 1.0) broken_inferred = u0 isa StaticArray && (autodiff isa AutoFiniteDiff ||