Skip to content

Commit f98e470

Browse files
Exclude Enzyme from pre-release tests
1 parent 4db4000 commit f98e470

File tree

12 files changed

+368
-52
lines changed

12 files changed

+368
-52
lines changed

lib/NonlinearSolveFirstOrder/test/rootfind_tests.jl

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@ end
99
using LineSearches: LineSearches
1010
using BenchmarkTools: @ballocated
1111
using StaticArrays: @SVector
12-
using Zygote, Enzyme, ForwardDiff, FiniteDiff
12+
using Zygote, ForwardDiff, FiniteDiff
13+
14+
# Conditionally import Enzyme only if not on Julia prerelease
15+
include("test_utilities.jl")
16+
if !is_julia_prerelease()
17+
using Enzyme
18+
end
1319

1420
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)
1521

16-
@testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme())
22+
# Filter autodiff backends based on Julia version
23+
autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()]
24+
if !is_julia_prerelease()
25+
push!(autodiff_backends, AutoEnzyme())
26+
end
27+
28+
@testset for ad in autodiff_backends
1729
@testset "$(nameof(typeof(linesearch)))" for linesearch in (
1830
LineSearchesJL(; method = LineSearches.Static(), autodiff = ad),
1931
LineSearchesJL(; method = LineSearches.BackTracking(), autodiff = ad),
@@ -93,14 +105,26 @@ end
93105
using ADTypes, Random, LinearSolve, LinearAlgebra
94106
using BenchmarkTools: @ballocated
95107
using StaticArrays: @SVector
96-
using Zygote, Enzyme, ForwardDiff, FiniteDiff
108+
using Zygote, ForwardDiff, FiniteDiff
109+
110+
# Conditionally import Enzyme only if not on Julia prerelease
111+
include("test_utilities.jl")
112+
if !is_julia_prerelease()
113+
using Enzyme
114+
end
97115

98116
preconditioners = [
99117
(u0) -> nothing,
100118
u0 -> ((args...) -> (Diagonal(rand!(similar(u0))), nothing))
101119
]
102120

103-
@testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme())
121+
# Filter autodiff backends based on Julia version
122+
autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()]
123+
if !is_julia_prerelease()
124+
push!(autodiff_backends, AutoEnzyme())
125+
end
126+
127+
@testset for ad in autodiff_backends
104128
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)
105129

106130
@testset "[OOP] u0: $(typeof(u0))" for u0 in u0s
@@ -176,15 +200,27 @@ end
176200
using ADTypes, LinearSolve, LinearAlgebra
177201
using BenchmarkTools: @ballocated
178202
using StaticArrays: @SVector
179-
using Zygote, Enzyme, ForwardDiff, FiniteDiff
203+
using Zygote, ForwardDiff, FiniteDiff
204+
205+
# Conditionally import Enzyme only if not on Julia prerelease
206+
include("test_utilities.jl")
207+
if !is_julia_prerelease()
208+
using Enzyme
209+
end
180210

181211
radius_update_schemes = [
182212
RadiusUpdateSchemes.Simple, RadiusUpdateSchemes.NocedalWright,
183213
RadiusUpdateSchemes.NLsolve, RadiusUpdateSchemes.Hei,
184214
RadiusUpdateSchemes.Yuan, RadiusUpdateSchemes.Fan, RadiusUpdateSchemes.Bastin
185215
]
186216

187-
@testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme())
217+
# Filter autodiff backends based on Julia version
218+
autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()]
219+
if !is_julia_prerelease()
220+
push!(autodiff_backends, AutoEnzyme())
221+
end
222+
223+
@testset for ad in autodiff_backends
188224
@testset for radius_update_scheme in radius_update_schemes,
189225
linsolve in (nothing, LUFactorization(), KrylovJL_GMRES(), \)
190226

@@ -296,9 +332,21 @@ end
296332
using ADTypes, LinearSolve, LinearAlgebra
297333
using BenchmarkTools: @ballocated
298334
using StaticArrays: SVector, @SVector
299-
using Zygote, Enzyme, ForwardDiff, FiniteDiff
335+
using Zygote, ForwardDiff, FiniteDiff
336+
337+
# Conditionally import Enzyme only if not on Julia prerelease
338+
include("test_utilities.jl")
339+
if !is_julia_prerelease()
340+
using Enzyme
341+
end
300342

301-
@testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme())
343+
# Filter autodiff backends based on Julia version
344+
autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()]
345+
if !is_julia_prerelease()
346+
push!(autodiff_backends, AutoEnzyme())
347+
end
348+
349+
@testset for ad in autodiff_backends
302350
solver = LevenbergMarquardt(; autodiff = ad)
303351

304352
@testset "[OOP] u0: $(typeof(u0))" for u0 in ([1.0, 1.0], 1.0, @SVector([1.0, 1.0]))
@@ -394,8 +442,17 @@ end
394442

395443
@testitem "Simple Sparse AutoDiff" setup=[CoreRootfindTesting] tags=[:core] begin
396444
using ADTypes, SparseConnectivityTracer, SparseMatrixColorings
397-
398-
@testset for ad in (AutoForwardDiff(), AutoFiniteDiff(), AutoZygote(), AutoEnzyme())
445+
446+
# Include utility functions for prerelease detection
447+
include("test_utilities.jl")
448+
449+
# Filter autodiff backends based on Julia version
450+
autodiff_backends = [AutoForwardDiff(), AutoFiniteDiff(), AutoZygote()]
451+
if !is_julia_prerelease()
452+
push!(autodiff_backends, AutoEnzyme())
453+
end
454+
455+
@testset for ad in autodiff_backends
399456
@testset for u0 in ([1.0, 1.0], 1.0)
400457
prob = NonlinearProblem(
401458
NonlinearFunction(quadratic_f; sparsity = TracerSparsityDetector()), u0, 2.0
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Test utilities for NonlinearSolveFirstOrder
2+
3+
"""
4+
is_julia_prerelease()
5+
6+
Check if the current Julia version is a prerelease version (e.g., DEV, alpha, beta, rc).
7+
"""
8+
function is_julia_prerelease()
9+
version_string = string(VERSION)
10+
# Check for DEV versions (e.g., "1.12.0-DEV.1234")
11+
contains(version_string, "DEV") && return true
12+
# Check for alpha/beta/rc versions
13+
contains(version_string, "alpha") && return true
14+
contains(version_string, "beta") && return true
15+
contains(version_string, "rc") && return true
16+
return false
17+
end
18+
19+
"""
20+
filter_autodiff_backends(backends)
21+
22+
Filter out AutoEnzyme from the list of autodiff backends if running on Julia prerelease.
23+
"""
24+
function filter_autodiff_backends(backends)
25+
if is_julia_prerelease()
26+
return filter(ad -> !isa(ad, AutoEnzyme), backends)
27+
else
28+
return backends
29+
end
30+
end

lib/NonlinearSolveHomotopyContinuation/test/allroots.jl

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ using NonlinearSolve
22
using NonlinearSolveHomotopyContinuation
33
using SciMLBase: NonlinearSolution
44
using ADTypes
5-
using Enzyme
65
import NaNMath
76

7+
# Conditionally import Enzyme only if not on Julia prerelease
8+
include("test_utilities.jl")
9+
if !is_julia_prerelease()
10+
using Enzyme
11+
end
12+
813
alg = HomotopyContinuationJL{true}(; threading = false)
914

1015
@testset "scalar u" begin
@@ -14,9 +19,13 @@ alg = HomotopyContinuationJL{true}(; threading = false)
1419
jac = function (u, p)
1520
return 2u - p[1]
1621
end
17-
@testset "`NonlinearProblem` - $name" for (jac_or_autodiff, name) in [
18-
(AutoForwardDiff(), "no jac - forwarddiff"), (AutoEnzyme(), "no jac - enzyme"), (
19-
jac, "jac")]
22+
# Filter autodiff backends based on Julia version
23+
autodiff_backends = [(AutoForwardDiff(), "no jac - forwarddiff"), (jac, "jac")]
24+
if !is_julia_prerelease()
25+
push!(autodiff_backends, (AutoEnzyme(), "no jac - enzyme"))
26+
end
27+
28+
@testset "`NonlinearProblem` - $name" for (jac_or_autodiff, name) in autodiff_backends
2029
if jac_or_autodiff isa Function
2130
jac = jac_or_autodiff
2231
autodiff = nothing
@@ -107,11 +116,17 @@ fjac = function (u, p)
107116
2*p[2]*u[2] 3*u[2]^2+2*p[2]*u[1]+1]
108117
end
109118

110-
@testset "vector u - $name" for (rhs, jac_or_autodiff, name) in [
111-
(f, AutoForwardDiff(), "oop + forwarddiff"), (f, AutoEnzyme(), "oop + enzyme"), (
112-
f, fjac, "oop + jac"),
113-
(f!, AutoForwardDiff(), "iip + forwarddiff"), (f!, AutoEnzyme(), "iip + enzyme"), (
114-
f!, fjac!, "iip + jac")]
119+
# Filter test cases based on Julia version
120+
vector_test_cases = [
121+
(f, AutoForwardDiff(), "oop + forwarddiff"), (f, fjac, "oop + jac"),
122+
(f!, AutoForwardDiff(), "iip + forwarddiff"), (f!, fjac!, "iip + jac")
123+
]
124+
if !is_julia_prerelease()
125+
push!(vector_test_cases, (f, AutoEnzyme(), "oop + enzyme"))
126+
push!(vector_test_cases, (f!, AutoEnzyme(), "iip + enzyme"))
127+
end
128+
129+
@testset "vector u - $name" for (rhs, jac_or_autodiff, name) in vector_test_cases
115130
sol = nothing
116131
if jac_or_autodiff isa Function
117132
jac = jac_or_autodiff

lib/NonlinearSolveHomotopyContinuation/test/single_root.jl

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ using NonlinearSolveHomotopyContinuation
33
using SciMLBase: NonlinearSolution
44
import NaNMath
55

6+
# Include utility functions for prerelease detection
7+
include("test_utilities.jl")
8+
69
alg = HomotopyContinuationJL{false}(; threading = false)
710

811
@testset "scalar u" begin
@@ -12,9 +15,13 @@ alg = HomotopyContinuationJL{false}(; threading = false)
1215
jac = function (u, p)
1316
return 2u - (p + 3)
1417
end
15-
@testset "`NonlinearProblem` - $name" for (jac_or_autodiff, name) in [
16-
(AutoForwardDiff(), "no jac - forwarddiff"), (AutoEnzyme(), "no jac - enzyme"), (
17-
jac, "jac")]
18+
# Filter autodiff backends based on Julia version
19+
autodiff_backends = [(AutoForwardDiff(), "no jac - forwarddiff"), (jac, "jac")]
20+
if !is_julia_prerelease()
21+
push!(autodiff_backends, (AutoEnzyme(), "no jac - enzyme"))
22+
end
23+
24+
@testset "`NonlinearProblem` - $name" for (jac_or_autodiff, name) in autodiff_backends
1825
if jac_or_autodiff isa Function
1926
jac = jac_or_autodiff
2027
autodiff = nothing
@@ -96,11 +103,17 @@ jac = function (u, p)
96103
2*p[2]*u[2] 3*u[2]^2+2*p[2]*u[1]+1]
97104
end
98105

99-
@testset "vector u - $name" for (rhs, jac_or_autodiff, name) in [
100-
(f, AutoForwardDiff(), "oop + forwarddiff"), (f, AutoEnzyme(), "oop + enzyme"), (
101-
f, jac, "oop + jac"),
102-
(f!, AutoForwardDiff(), "iip + forwarddiff"), (f!, AutoEnzyme(), "iip + enzyme"), (
103-
f!, jac!, "iip + jac")]
106+
# Filter test cases based on Julia version
107+
vector_test_cases = [
108+
(f, AutoForwardDiff(), "oop + forwarddiff"), (f, jac, "oop + jac"),
109+
(f!, AutoForwardDiff(), "iip + forwarddiff"), (f!, jac!, "iip + jac")
110+
]
111+
if !is_julia_prerelease()
112+
push!(vector_test_cases, (f, AutoEnzyme(), "oop + enzyme"))
113+
push!(vector_test_cases, (f!, AutoEnzyme(), "iip + enzyme"))
114+
end
115+
116+
@testset "vector u - $name" for (rhs, jac_or_autodiff, name) in vector_test_cases
104117
if jac_or_autodiff isa Function
105118
jac = jac_or_autodiff
106119
autodiff = nothing
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Test utilities for NonlinearSolveHomotopyContinuation
2+
3+
"""
4+
is_julia_prerelease()
5+
6+
Check if the current Julia version is a prerelease version (e.g., DEV, alpha, beta, rc).
7+
"""
8+
function is_julia_prerelease()
9+
version_string = string(VERSION)
10+
# Check for DEV versions (e.g., "1.12.0-DEV.1234")
11+
contains(version_string, "DEV") && return true
12+
# Check for alpha/beta/rc versions
13+
contains(version_string, "alpha") && return true
14+
contains(version_string, "beta") && return true
15+
contains(version_string, "rc") && return true
16+
return false
17+
end

lib/NonlinearSolveQuasiNewton/test/core_tests.jl

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@ end
99
using LineSearches: LineSearches
1010
using BenchmarkTools: @ballocated
1111
using StaticArrays: @SVector
12-
using Zygote, Enzyme, ForwardDiff, FiniteDiff
12+
using Zygote, ForwardDiff, FiniteDiff
13+
14+
# Conditionally import Enzyme only if not on Julia prerelease
15+
include("test_utilities.jl")
16+
if !is_julia_prerelease()
17+
using Enzyme
18+
end
1319

1420
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)
1521

16-
@testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme())
22+
# Filter autodiff backends based on Julia version
23+
autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()]
24+
if !is_julia_prerelease()
25+
push!(autodiff_backends, AutoEnzyme())
26+
end
27+
28+
@testset for ad in autodiff_backends
1729
@testset "$(nameof(typeof(linesearch)))" for linesearch in (
1830
# LineSearchesJL(; method = LineSearches.Static(), autodiff = ad),
1931
# LineSearchesJL(; method = LineSearches.BackTracking(), autodiff = ad),
@@ -84,9 +96,21 @@ end
8496
using LineSearches: LineSearches
8597
using BenchmarkTools: @ballocated
8698
using StaticArrays: @SVector
87-
using Zygote, Enzyme, ForwardDiff, FiniteDiff
99+
using Zygote, ForwardDiff, FiniteDiff
100+
101+
# Conditionally import Enzyme only if not on Julia prerelease
102+
include("test_utilities.jl")
103+
if !is_julia_prerelease()
104+
using Enzyme
105+
end
88106

89-
@testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme())
107+
# Filter autodiff backends based on Julia version
108+
autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()]
109+
if !is_julia_prerelease()
110+
push!(autodiff_backends, AutoEnzyme())
111+
end
112+
113+
@testset for ad in autodiff_backends
90114
@testset "$(nameof(typeof(linesearch)))" for linesearch in (
91115
# LineSearchesJL(; method = LineSearches.Static(), autodiff = ad),
92116
# LineSearchesJL(; method = LineSearches.BackTracking(), autodiff = ad),
@@ -157,9 +181,21 @@ end
157181
using LineSearches: LineSearches
158182
using BenchmarkTools: @ballocated
159183
using StaticArrays: @SVector
160-
using Zygote, Enzyme, ForwardDiff, FiniteDiff
184+
using Zygote, ForwardDiff, FiniteDiff
185+
186+
# Conditionally import Enzyme only if not on Julia prerelease
187+
include("test_utilities.jl")
188+
if !is_julia_prerelease()
189+
using Enzyme
190+
end
161191

162-
@testset for ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff(), AutoEnzyme())
192+
# Filter autodiff backends based on Julia version
193+
autodiff_backends = [AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()]
194+
if !is_julia_prerelease()
195+
push!(autodiff_backends, AutoEnzyme())
196+
end
197+
198+
@testset for ad in autodiff_backends
163199
@testset "$(nameof(typeof(linesearch)))" for linesearch in (
164200
# LineSearchesJL(; method = LineSearches.Static(), autodiff = ad),
165201
# LineSearchesJL(; method = LineSearches.BackTracking(), autodiff = ad),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Test utilities for NonlinearSolveQuasiNewton
2+
3+
"""
4+
is_julia_prerelease()
5+
6+
Check if the current Julia version is a prerelease version (e.g., DEV, alpha, beta, rc).
7+
"""
8+
function is_julia_prerelease()
9+
version_string = string(VERSION)
10+
# Check for DEV versions (e.g., "1.12.0-DEV.1234")
11+
contains(version_string, "DEV") && return true
12+
# Check for alpha/beta/rc versions
13+
contains(version_string, "alpha") && return true
14+
contains(version_string, "beta") && return true
15+
contains(version_string, "rc") && return true
16+
return false
17+
end
18+
19+
"""
20+
filter_autodiff_backends(backends)
21+
22+
Filter out AutoEnzyme from the list of autodiff backends if running on Julia prerelease.
23+
"""
24+
function filter_autodiff_backends(backends)
25+
if is_julia_prerelease()
26+
return filter(ad -> !isa(ad, AutoEnzyme), backends)
27+
else
28+
return backends
29+
end
30+
end

0 commit comments

Comments
 (0)