Skip to content

Commit

Permalink
Merge pull request #160 from SciML/ap/up_di
Browse files Browse the repository at this point in the history
feat: update to new DI.jl
  • Loading branch information
ChrisRackauckas authored Sep 26, 2024
2 parents c48ef4f + 8a50d1d commit ee060e5
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 78 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:
fail-fast: false
matrix:
group:
- "Core"
- "core"
- "adjoint"
os:
- "ubuntu-latest"
- "macos-latest"
Expand Down
18 changes: 8 additions & 10 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SimpleNonlinearSolve"
uuid = "727e6d20-b764-4bd8-a329-72de5adea6c7"
authors = ["SciML"]
version = "1.12.2"
version = "1.12.3"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -34,22 +34,22 @@ SimpleNonlinearSolveTrackerExt = "Tracker"
SimpleNonlinearSolveZygoteExt = "Zygote"

[compat]
ADTypes = "1.2"
ADTypes = "1.9"
AllocCheck = "0.1.1"
Aqua = "0.8"
ArrayInterface = "7.9"
CUDA = "5.2"
ChainRulesCore = "1.23"
ConcreteStructs = "0.2.3"
DiffEqBase = "6.149"
DiffResults = "1.1"
DifferentiationInterface = "0.5"
DifferentiationInterface = "0.6.1"
ExplicitImports = "1.5.0"
FastClosures = "0.3.2"
FiniteDiff = "2.23.1"
ForwardDiff = "0.10.36"
Hwloc = "3"
InteractiveUtils = "<0.0.1, 1"
LinearAlgebra = "1.10"
LinearSolve = "2.30"
MaybeInplace = "0.1.3"
NonlinearProblemLibrary = "0.1.2"
Pkg = "1.10"
Expand All @@ -60,7 +60,6 @@ ReTestItems = "1.23"
Reexport = "1.2"
ReverseDiff = "1.15.3"
SciMLBase = "2.37.0"
SciMLSensitivity = "7.58"
Setfield = "1.1.1"
StaticArrays = "1.9"
StaticArraysCore = "1.4.2"
Expand All @@ -72,25 +71,24 @@ julia = "1.10"
[extras]
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Hwloc = "0e44f5e4-bd66-52a0-8798-143a42290a1d"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
NonlinearProblemLibrary = "b7050fa9-e91f-4b37-bcee-a89a063da141"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["AllocCheck", "Aqua", "CUDA", "DiffEqBase", "ExplicitImports", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "LinearSolve", "NonlinearProblemLibrary", "Pkg", "PolyesterForwardDiff", "Random", "ReTestItems", "Reexport", "ReverseDiff", "SciMLSensitivity", "StaticArrays", "Test", "Tracker", "Zygote"]
test = ["AllocCheck", "Aqua", "DiffEqBase", "ExplicitImports", "FiniteDiff", "ForwardDiff", "Hwloc", "InteractiveUtils", "LinearAlgebra", "NonlinearProblemLibrary", "Pkg", "PolyesterForwardDiff", "Random", "ReTestItems", "Reexport", "ReverseDiff", "StaticArrays", "Test", "Tracker", "Zygote"]
8 changes: 4 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ end

function value_and_jacobian(
ad, prob::AbstractNonlinearProblem, f::F, y, x, cache; J = nothing) where {F}
x isa Number && return DI.value_and_derivative(f, ad, x, cache)
x isa Number && return DI.value_and_derivative(f, cache, ad, x)

if isinplace(prob)
if cache isa HasAnalyticJacobian
prob.f.jac(J, x, prob.p)
f(y, x)
return y, J
end
return DI.value_and_jacobian!(f, y, J, ad, x, cache)
return DI.value_and_jacobian!(f, y, J, cache, ad, x)
else
cache isa HasAnalyticJacobian && return f(x), prob.f.jac(x, prob.p)
J === nothing && return DI.value_and_jacobian(f, ad, x, cache)
y, J = DI.value_and_jacobian!(f, J, ad, x, cache)
J === nothing && return DI.value_and_jacobian(f, cache, ad, x)
y, J = DI.value_and_jacobian!(f, J, cache, ad, x)
return y, J
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/core/23_test_problems_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ end
test_on_library(problems, dicts, alg_ops, broken_tests)
end

@testitem "23 Test Problems: SimpleBroyden" retries=5 setup=[RobustnessTesting] tags=[:core] begin
@testitem "23 Test Problems: SimpleBroyden" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (SimpleBroyden(),)

broken_tests = Dict(alg => Int[] for alg in alg_ops)
Expand Down
2 changes: 1 addition & 1 deletion test/core/adjoint_tests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testitem "Simple Adjoint Test" tags=[:core] begin
@testitem "Simple Adjoint Test" tags=[:adjoint] begin
using ForwardDiff, ReverseDiff, SciMLSensitivity, Tracker, Zygote

ff(u, p) = u .^ 2 .- p
Expand Down
3 changes: 1 addition & 2 deletions test/core/rootfind_tests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@testsetup module RootfindingTesting
using Reexport
@reexport using AllocCheck, LinearSolve, StaticArrays, Random, LinearAlgebra, ForwardDiff,
DiffEqBase
@reexport using AllocCheck, StaticArrays, Random, LinearAlgebra, ForwardDiff, DiffEqBase
import PolyesterForwardDiff

quadratic_f(u, p) = u .* u .- p
Expand Down
108 changes: 56 additions & 52 deletions test/gpu/cuda_tests.jl
Original file line number Diff line number Diff line change
@@ -1,73 +1,77 @@
@testitem "Solving on GPUs" tags=[:cuda] skip=:(using CUDA; !CUDA.functional()) begin
@testitem "Solving on GPUs" tags=[:cuda] begin
using StaticArrays, CUDA

CUDA.allowscalar(false)
if CUDA.functional()
CUDA.allowscalar(false)

f(u, p) = u .* u .- 2
f!(du, u, p) = du .= u .* u .- 2
f(u, p) = u .* u .- 2
f!(du, u, p) = du .= u .* u .- 2

@testset "$(nameof(typeof(alg)))" for alg in (
SimpleNewtonRaphson(), SimpleDFSane(), SimpleTrustRegion(),
SimpleTrustRegion(; nlsolve_update_rule = Val(true)),
SimpleBroyden(), SimpleLimitedMemoryBroyden(), SimpleKlement(),
SimpleHalley(), SimpleBroyden(; linesearch = Val(true)),
SimpleLimitedMemoryBroyden(; linesearch = Val(true)))
# Static Arrays
u0 = @SVector[1.0f0, 1.0f0]
probN = NonlinearProblem{false}(f, u0)
sol = solve(probN, alg; abstol = 1.0f-6)
@test SciMLBase.successful_retcode(sol)
@test maximum(abs, sol.resid) 1.0f-6

# Regular Arrays
u0 = [1.0, 1.0]
probN = NonlinearProblem{false}(f, u0)
sol = solve(probN, alg; abstol = 1.0f-6)
@test SciMLBase.successful_retcode(sol)
@test maximum(abs, sol.resid) 1.0f-6
@testset "$(nameof(typeof(alg)))" for alg in (
SimpleNewtonRaphson(), SimpleDFSane(), SimpleTrustRegion(),
SimpleTrustRegion(; nlsolve_update_rule = Val(true)),
SimpleBroyden(), SimpleLimitedMemoryBroyden(), SimpleKlement(),
SimpleHalley(), SimpleBroyden(; linesearch = Val(true)),
SimpleLimitedMemoryBroyden(; linesearch = Val(true)))
# Static Arrays
u0 = @SVector[1.0f0, 1.0f0]
probN = NonlinearProblem{false}(f, u0)
sol = solve(probN, alg; abstol = 1.0f-6)
@test SciMLBase.successful_retcode(sol)
@test maximum(abs, sol.resid) 1.0f-6

# Regular Arrays Inplace
if !(alg isa SimpleHalley)
# Regular Arrays
u0 = [1.0, 1.0]
probN = NonlinearProblem{true}(f!, u0)
probN = NonlinearProblem{false}(f, u0)
sol = solve(probN, alg; abstol = 1.0f-6)
@test SciMLBase.successful_retcode(sol)
@test maximum(abs, sol.resid) 1.0f-6

# Regular Arrays Inplace
if !(alg isa SimpleHalley)
u0 = [1.0, 1.0]
probN = NonlinearProblem{true}(f!, u0)
sol = solve(probN, alg; abstol = 1.0f-6)
@test SciMLBase.successful_retcode(sol)
@test maximum(abs, sol.resid) 1.0f-6
end
end
end
end

@testitem "CUDA Kernel Launch Test" tags=[:cuda] skip=:(using CUDA; !CUDA.functional()) timeout=3600 begin
@testitem "CUDA Kernel Launch Test" tags=[:cuda] begin
using StaticArrays, CUDA

CUDA.allowscalar(false)
if CUDA.functional()
CUDA.allowscalar(false)

f(u, p) = u .* u .- 2
f!(du, u, p) = du .= u .* u .- 2
f(u, p) = u .* u .- 2
f!(du, u, p) = du .= u .* u .- 2

function kernel_function(prob, alg)
solve(prob, alg)
return nothing
end
function kernel_function(prob, alg)
solve(prob, alg)
return nothing
end

prob = NonlinearProblem{false}(f, @SVector[1.0f0, 1.0f0])
prob = convert(SimpleNonlinearSolve.ImmutableNonlinearProblem, prob)
prob = NonlinearProblem{false}(f, @SVector[1.0f0, 1.0f0])
prob = convert(SimpleNonlinearSolve.ImmutableNonlinearProblem, prob)

@testset "$(nameof(typeof(alg)))" for alg in (
SimpleNewtonRaphson(), SimpleDFSane(), SimpleTrustRegion(),
SimpleTrustRegion(; nlsolve_update_rule = Val(true)),
SimpleBroyden(), SimpleLimitedMemoryBroyden(), SimpleKlement(),
SimpleHalley(), SimpleBroyden(; linesearch = Val(true)),
SimpleLimitedMemoryBroyden(; linesearch = Val(true)))
@test begin
try
@cuda kernel_function(prob, alg)
@info "Successfully launched kernel for $(alg)."
true
catch err
@error "Kernel Launch failed for $(alg)."
false
end
end broken=(alg isa SimpleHalley)
@testset "$(nameof(typeof(alg)))" for alg in (
SimpleNewtonRaphson(), SimpleDFSane(), SimpleTrustRegion(),
SimpleTrustRegion(; nlsolve_update_rule = Val(true)),
SimpleBroyden(), SimpleLimitedMemoryBroyden(), SimpleKlement(),
SimpleHalley(), SimpleBroyden(; linesearch = Val(true)),
SimpleLimitedMemoryBroyden(; linesearch = Val(true)))
@test begin
try
@cuda kernel_function(prob, alg)
@info "Successfully launched kernel for $(alg)."
true
catch err
@error "Kernel Launch failed for $(alg)."
false
end
end broken=(alg isa SimpleHalley)
end
end
end
31 changes: 24 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
using ReTestItems, CUDA
using ReTestItems, SimpleNonlinearSolve, Hwloc, InteractiveUtils
using Pkg

const GROUP = get(ENV, "GROUP", CUDA.functional() ? "All" : "Core")
@info sprint(InteractiveUtils.versioninfo)

if GROUP == "All"
ReTestItems.runtests(@__DIR__)
else
tags = [Symbol(lowercase(GROUP))]
ReTestItems.runtests(@__DIR__; tags)
const GROUP = lowercase(get(ENV, "GROUP", "All"))

if GROUP == "adjoint" || GROUP == "all"
Pkg.add(["SciMLSensitivity"])
end

if GROUP == "cuda" || GROUP == "all"
Pkg.add(["CUDA"])
end

const RETESTITEMS_NWORKERS = parse(
Int, get(ENV, "RETESTITEMS_NWORKERS", string(min(Hwloc.num_physical_cores(), 4))))
const RETESTITEMS_NWORKER_THREADS = parse(Int,
get(ENV, "RETESTITEMS_NWORKER_THREADS",
string(max(Hwloc.num_virtual_cores() ÷ RETESTITEMS_NWORKERS, 1))))

@info "Running tests for group: $(GROUP) with $(RETESTITEMS_NWORKERS) workers"

ReTestItems.runtests(
SimpleNonlinearSolve; tags = (GROUP == "all" ? nothing : [Symbol(GROUP)]),
nworkers = RETESTITEMS_NWORKERS, nworker_threads = RETESTITEMS_NWORKER_THREADS,
testitem_timeout = 3600, retries = 4)

2 comments on commit ee060e5

@avik-pal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/116050

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.12.3 -m "<description of version>" ee060e53bdf39639966e08767bb6d17967603fdc
git push origin v1.12.3

Please sign in to comment.