Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/CI_NonlinearSolve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ jobs:
- downstream
- wrappers
- misc
- nopre
version:
- "1"
- "lts"
- "pre"
os:
- ubuntu-latest
- macos-latest
exclude:
# Don't run nopre tests on prerelease Julia
- group: nopre
version: "pre"
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/CI_SimpleNonlinearSolve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- core
- adjoint
- alloc_check
- nopre
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
Expand Down
54 changes: 54 additions & 0 deletions test/enzyme_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@testitem "PolyAlgorithms with Enzyme" tags=[:nopre] skip=!isempty(VERSION.prerelease) begin
using ADTypes

# Only run these tests on non-prerelease Julia versions
@info "Running Enzyme tests (Julia $(VERSION))"

cache = zeros(2)
function f(du, u, p)
cache .= u .* u
du .= cache .- 2
end
u0 = [1.0, 1.0]
probN = NonlinearProblem{true}(f, u0)

# Test with AutoEnzyme for autodiff
if isempty(VERSION.prerelease)
using Enzyme
sol = solve(probN, RobustMultiNewton(; autodiff = AutoEnzyme()))
@test SciMLBase.successful_retcode(sol)

sol = solve(
probN, FastShortcutNonlinearPolyalg(; autodiff = AutoEnzyme()); abstol = 1e-9
)
@test SciMLBase.successful_retcode(sol)
end
end

@testitem "ForwardDiff with Enzyme backend" tags=[:nopre] skip=!isempty(VERSION.prerelease) begin
using ForwardDiff, ADTypes

# Only run these tests on non-prerelease Julia versions
@info "Running ForwardDiff-Enzyme integration tests (Julia $(VERSION))"

test_f!(du, u, p) = (@. du = u^2 - p)
test_f(u, p) = (@. u^2 - p)

function solve_oop(p)
solve(NonlinearProblem(test_f, 2.0, p), NewtonRaphson(; autodiff = AutoEnzyme())).u
end

if isempty(VERSION.prerelease)
using Enzyme

# Test scalar AD with Enzyme backend
for p in 1.0:0.1:10.0
sol = solve(NonlinearProblem(test_f, 2.0, p), NewtonRaphson(; autodiff = AutoEnzyme()))
if SciMLBase.successful_retcode(sol)
gs = abs.(ForwardDiff.derivative(solve_oop, p))
gs_true = abs.(1 / (2 * √p))
@test abs.(gs) ≈ abs.(gs_true) atol=1e-5
end
end
end
end
Loading