|
1 | 1 | using BenchmarkTools, LinearSolve, NonlinearSolve, StaticArrays, Random, LinearAlgebra,
|
2 | 2 | Test, ForwardDiff, Zygote, Enzyme, SparseDiffTools, DiffEqBase
|
3 | 3 |
|
| 4 | +function __autosparseenzyme() |
| 5 | + @static if Sys.iswindows() |
| 6 | + @warn "Enzyme on Windows stalls. Using AutoSparseFiniteDiff instead till \ |
| 7 | + https://github.com/EnzymeAD/Enzyme.jl/issues/1236 is resolved." |
| 8 | + return AutoSparseFiniteDiff() |
| 9 | + else |
| 10 | + return AutoSparseEnzyme() |
| 11 | + end |
| 12 | +end |
| 13 | + |
4 | 14 | _nameof(x) = applicable(nameof, x) ? nameof(x) : _nameof(typeof(x))
|
5 | 15 |
|
6 | 16 | quadratic_f(u, p) = u .* u .- p
|
@@ -95,7 +105,7 @@ const TERMINATION_CONDITIONS = [
|
95 | 105 | @test nlprob_iterator_interface(quadratic_f!, p, Val(true)) ≈ sqrt.(p)
|
96 | 106 |
|
97 | 107 | @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (AutoSparseForwardDiff(),
|
98 |
| - AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) |
| 108 | + AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), __autosparseenzyme()), u0 in (1.0, [1.0, 1.0]) |
99 | 109 | probN = NonlinearProblem(quadratic_f, u0, 2.0)
|
100 | 110 | @test all(solve(probN, NewtonRaphson(; autodiff)).u .≈ sqrt(2.0))
|
101 | 111 | end
|
|
175 | 185 | @test nlprob_iterator_interface(quadratic_f!, p, Val(true)) ≈ sqrt.(p)
|
176 | 186 |
|
177 | 187 | @testset "ADType: $(autodiff) u0: $(_nameof(u0)) radius_update_scheme: $(radius_update_scheme)" for autodiff in (AutoSparseForwardDiff(),
|
178 |
| - AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]), |
| 188 | + AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), __autosparseenzyme()), u0 in (1.0, [1.0, 1.0]), |
179 | 189 | radius_update_scheme in radius_update_schemes
|
180 | 190 |
|
181 | 191 | probN = NonlinearProblem(quadratic_f, u0, 2.0)
|
|
279 | 289 | end
|
280 | 290 |
|
281 | 291 | @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (AutoSparseForwardDiff(),
|
282 |
| - AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) |
| 292 | + AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), __autosparseenzyme()), u0 in (1.0, [1.0, 1.0]) |
283 | 293 | probN = NonlinearProblem(quadratic_f, u0, 2.0)
|
284 | 294 | @test all(solve(probN, LevenbergMarquardt(; autodiff); abstol = 1e-9,
|
285 | 295 | reltol = 1e-9).u .≈ sqrt(2.0))
|
|
494 | 504 | @test nlprob_iterator_interface(quadratic_f!, p, Val(true)) ≈ sqrt.(p)
|
495 | 505 |
|
496 | 506 | @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (AutoSparseForwardDiff(),
|
497 |
| - AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) |
| 507 | + AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), __autosparseenzyme()), u0 in (1.0, [1.0, 1.0]) |
498 | 508 | probN = NonlinearProblem(quadratic_f, u0, 2.0)
|
499 | 509 | @test all(solve(probN, PseudoTransient(; alpha_initial = 10.0, autodiff)).u .≈
|
500 | 510 | sqrt(2.0))
|
|
0 commit comments