Skip to content

Commit

Permalink
test: fix more of NonlinearSolve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 31, 2024
1 parent f37da0a commit f49c308
Show file tree
Hide file tree
Showing 34 changed files with 756 additions and 764 deletions.
4 changes: 2 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ steps:
Pkg.Registry.update();
# Install packages present in subdirectories
dev_pks = Pkg.PackageSpec[];
for path in ("lib/SciMLJacobianOperators", "lib/BracketingNonlinearSolve", "lib/NonlinearSolveBase", "lib/SimpleNonlinearSolve")
for path in ("lib/SciMLJacobianOperators", "lib/BracketingNonlinearSolve", "lib/NonlinearSolveBase", "lib/SimpleNonlinearSolve", "lib/NonlinearSolveFirstOrder", "lib/NonlinearSolveSpectralMethods", "lib/NonlinearSolveQuasiNewton")
push!(dev_pks, Pkg.PackageSpec(; path));
end
Pkg.develop(dev_pks);
Expand Down Expand Up @@ -42,7 +42,7 @@ steps:
Pkg.Registry.update();
# Install packages present in subdirectories
dev_pks = Pkg.PackageSpec[];
for path in ("lib/NonlinearSolveBase", "lib/BracketingNonlinearSolve")
for path in ("lib/NonlinearSolveBase", "lib/BracketingNonlinearSolve", "lib/SciMLJacobianOperators")
push!(dev_pks, Pkg.PackageSpec(; path))
end
Pkg.develop(dev_pks);
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_BracketingNonlinearSolve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fail-fast: false
matrix:
version:
- "lts"
- "1.10"
- "1"
os:
- ubuntu-latest
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/CI_NonlinearSolve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
- "lib/BracketingNonlinearSolve/**"
- "lib/NonlinearSolveBase/**"
- "lib/SimpleNonlinearSolve/**"
- "lib/NonlinearSolveFirstOrder/**"
- "lib/NonlinearSolveSpectralMethods/**"
- "lib/NonlinearSolveQuasiNewton/**"
push:
branches:
- master
Expand All @@ -33,10 +36,9 @@ jobs:
group:
- Core
- Downstream
- Misc
- Wrappers
version:
- "lts"
- "1.10"
- "1"
os:
- ubuntu-latest
Expand All @@ -63,7 +65,7 @@ jobs:
Pkg.Registry.update()
# Install packages present in subdirectories
dev_pks = Pkg.PackageSpec[]
for path in ("lib/SciMLJacobianOperators", "lib/BracketingNonlinearSolve", "lib/NonlinearSolveBase", "lib/SimpleNonlinearSolve")
for path in ("lib/SciMLJacobianOperators", "lib/BracketingNonlinearSolve", "lib/NonlinearSolveBase", "lib/SimpleNonlinearSolve", "lib/NonlinearSolveFirstOrder", "lib/NonlinearSolveSpectralMethods", "lib/NonlinearSolveQuasiNewton")
push!(dev_pks, Pkg.PackageSpec(; path))
end
Pkg.develop(dev_pks)
Expand All @@ -74,7 +76,7 @@ jobs:
GROUP: ${{ matrix.group }}
- uses: julia-actions/julia-processcoverage@v1
with:
directories: src,ext,lib/SciMLJacobianOperators/src
directories: src,ext,lib/SciMLJacobianOperators/src,lib/BracketingNonlinearSolve/src,lib/NonlinearSolveBase/src,lib/NonlinearSolveBase/ext,lib/SimpleNonlinearSolve/src,lib/NonlinearSolveFirstOrder/src,lib/NonlinearSolveSpectralMethods/src,lib/NonlinearSolveQuasiNewton/src
- uses: codecov/codecov-action@v4
with:
file: lcov.info
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_NonlinearSolveBase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fail-fast: false
matrix:
version:
- "lts"
- "1.10"
- "1"
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_NonlinearSolveFirstOrder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fail-fast: false
matrix:
version:
- "lts"
- "1.10"
- "1"
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_NonlinearSolveQuasiNewton.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fail-fast: false
matrix:
version:
- "lts"
- "1.10"
- "1"
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_NonlinearSolveSpectralMethods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fail-fast: false
matrix:
version:
- "lts"
- "1.10"
- "1"
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_SciMLJacobianOperators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fail-fast: false
matrix:
version:
- "lts"
- "1.10"
- "1"
os:
- ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/Downgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
group:
- Core
- Downstream
- Misc
- Wrappers
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ InteractiveUtils = "<0.0.1, 1"
LeastSquaresOptim = "0.8.5"
LineSearch = "0.1.4"
LineSearches = "7.3"
LinearAlgebra = "1.11.0"
LinearAlgebra = "1.10"
LinearSolve = "2.36.1"
MINPACK = "1.2"
MPI = "0.20.22"
Expand Down
2 changes: 1 addition & 1 deletion lib/NonlinearSolveBase/src/NonlinearSolveBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module NonlinearSolveBase
using Compat: @compat
using ConcreteStructs: @concrete
using FastClosures: @closure
using Preferences: @load_preference
using Preferences: @load_preference, @set_preferences!

using ADTypes: ADTypes, AbstractADType, AutoSparse, NoSparsityDetector,
KnownJacobianSparsityDetector
Expand Down
22 changes: 22 additions & 0 deletions lib/NonlinearSolveBase/src/timer_outputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ end
@static if !TIMER_OUTPUTS_ENABLED
@inline reset_timer!(::Nothing) = nothing
end

"""
enable_timer_outputs()
Enable `TimerOutput` for all `NonlinearSolve` algorithms. This is useful for debugging
but has some overhead, so it is disabled by default.
"""
function enable_timer_outputs()
@set_preferences!("enable_timer_outputs" => true)
@info "Timer Outputs Enabled. Restart the Julia session for this to take effect."
end

"""
disable_timer_outputs()
Disable `TimerOutput` for all `NonlinearSolve` algorithms. This should be used when
`NonlinearSolve` is being used in performance-critical code.
"""
function disable_timer_outputs()
@set_preferences!("enable_timer_outputs" => false)
@info "Timer Outputs Disabled. Restart the Julia session for this to take effect."
end
4 changes: 3 additions & 1 deletion lib/NonlinearSolveFirstOrder/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Reexport = "1"
SciMLBase = "2.54"
SciMLJacobianOperators = "0.1.0"
Setfield = "1.1.1"
SparseArrays = "1.10"
SparseConnectivityTracer = "0.6.8"
SparseMatrixColorings = "0.4.8"
StableRNGs = "1"
Expand All @@ -75,6 +76,7 @@ NonlinearProblemLibrary = "b7050fa9-e91f-4b37-bcee-a89a063da141"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Expand All @@ -83,4 +85,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "Enzyme", "ExplicitImports", "Hwloc", "InteractiveUtils", "LineSearch", "LineSearches", "NonlinearProblemLibrary", "Pkg", "Random", "ReTestItems", "SparseConnectivityTracer", "SparseMatrixColorings", "StableRNGs", "StaticArrays", "Test", "Zygote"]
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "Enzyme", "ExplicitImports", "Hwloc", "InteractiveUtils", "LineSearch", "LineSearches", "NonlinearProblemLibrary", "Pkg", "Random", "ReTestItems", "SparseArrays", "SparseConnectivityTracer", "SparseMatrixColorings", "StableRNGs", "StaticArrays", "Test", "Zygote"]
3 changes: 2 additions & 1 deletion src/NonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ using DiffEqBase: DiffEqBase # Needed for `init` / `solve` dispatches
using LinearAlgebra: LinearAlgebra, norm
using LineSearch: BackTracking
using NonlinearSolveBase: NonlinearSolveBase, InternalAPI, AbstractNonlinearSolveAlgorithm,
AbstractNonlinearSolveCache, Utils, L2_NORM
AbstractNonlinearSolveCache, Utils, L2_NORM,
enable_timer_outputs, disable_timer_outputs

using Preferences: set_preferences!
using SciMLBase: SciMLBase, NLStats, ReturnCode, AbstractNonlinearProblem, NonlinearProblem,
Expand Down
21 changes: 0 additions & 21 deletions src/helpers.jl
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
"""
enable_timer_outputs()
Enable `TimerOutput` for all `NonlinearSolve` algorithms. This is useful for debugging
but has some overhead, so it is disabled by default.
"""
function enable_timer_outputs()
set_preferences!(NonlinearSolveBase, "enable_timer_outputs" => true; force = true)
@info "Timer Outputs Enabled. Restart the Julia session for this to take effect."
end

"""
disable_timer_outputs()
Disable `TimerOutput` for all `NonlinearSolve` algorithms. This should be used when
`NonlinearSolve` is being used in performance-critical code.
"""
function disable_timer_outputs()
set_preferences!(NonlinearSolveBase, "enable_timer_outputs" => false; force = true)
@info "Timer Outputs Disabled. Restart the Julia session for this to take effect."
end
144 changes: 144 additions & 0 deletions test/23_test_problems_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# @testsetup module RobustnessTesting
# using NonlinearSolve, LinearAlgebra, LinearSolve, NonlinearProblemLibrary, Test

# problems = NonlinearProblemLibrary.problems
# dicts = NonlinearProblemLibrary.dicts

# function test_on_library(
# problems, dicts, alg_ops, broken_tests, ϵ = 1e-4; skip_tests = nothing)
# for (idx, (problem, dict)) in enumerate(zip(problems, dicts))
# x = dict["start"]
# res = similar(x)
# nlprob = NonlinearProblem(problem, copy(x))
# @testset "$idx: $(dict["title"])" begin
# for alg in alg_ops
# try
# sol = solve(nlprob, alg; maxiters = 10000)
# problem(res, sol.u, nothing)

# skip = skip_tests !== nothing && idx in skip_tests[alg]
# if skip
# @test_skip norm(res, Inf) ≤ ϵ
# continue
# end
# broken = idx in broken_tests[alg] ? true : false
# @test norm(res, Inf)≤ϵ broken=broken
# catch err
# @error err
# broken = idx in broken_tests[alg] ? true : false
# if broken
# @test false broken=true
# else
# @test 1 == 2
# end
# end
# end
# end
# end
# end

# export test_on_library, problems, dicts
# end

# @testitem "PolyAlgorithms" setup=[RobustnessTesting] tags=[:core] begin
# alg_ops = (RobustMultiNewton(), FastShortcutNonlinearPolyalg())

# broken_tests = Dict(alg => Int[] for alg in alg_ops)
# broken_tests[alg_ops[1]] = []
# broken_tests[alg_ops[2]] = []

# test_on_library(problems, dicts, alg_ops, broken_tests)
# end

# @testitem "NewtonRaphson" setup=[RobustnessTesting] tags=[:core] begin
# alg_ops = (NewtonRaphson(),)

# broken_tests = Dict(alg => Int[] for alg in alg_ops)
# broken_tests[alg_ops[1]] = [1]

# test_on_library(problems, dicts, alg_ops, broken_tests)
# end

# @testitem "TrustRegion" setup=[RobustnessTesting] tags=[:core] begin
# alg_ops = (TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Simple),
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Fan),
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Hei),
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Yuan),
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Bastin),
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.NLsolve))

# broken_tests = Dict(alg => Int[] for alg in alg_ops)
# broken_tests[alg_ops[1]] = [11, 21]
# broken_tests[alg_ops[2]] = [11, 21]
# broken_tests[alg_ops[3]] = [11, 21]
# broken_tests[alg_ops[4]] = [8, 11, 21]
# broken_tests[alg_ops[5]] = [21]
# broken_tests[alg_ops[6]] = [11, 21]

# test_on_library(problems, dicts, alg_ops, broken_tests)
# end

# @testitem "LevenbergMarquardt" setup=[RobustnessTesting] tags=[:core] begin
# using LinearSolve

# alg_ops = (LevenbergMarquardt(), LevenbergMarquardt(; α_geodesic = 0.1),
# LevenbergMarquardt(; linsolve = CholeskyFactorization()))

# broken_tests = Dict(alg => Int[] for alg in alg_ops)
# broken_tests[alg_ops[1]] = [11, 21]
# broken_tests[alg_ops[2]] = [11, 21]
# broken_tests[alg_ops[3]] = [11, 21]

# test_on_library(problems, dicts, alg_ops, broken_tests)
# end

# @testitem "DFSane" setup=[RobustnessTesting] tags=[:core] begin
# alg_ops = (DFSane(),)

# broken_tests = Dict(alg => Int[] for alg in alg_ops)
# broken_tests[alg_ops[1]] = [1, 2, 3, 5, 21]

# test_on_library(problems, dicts, alg_ops, broken_tests)
# end

# @testitem "Broyden" setup=[RobustnessTesting] tags=[:core] begin
# alg_ops = (Broyden(), Broyden(; init_jacobian = Val(:true_jacobian)),
# Broyden(; update_rule = Val(:bad_broyden)),
# Broyden(; init_jacobian = Val(:true_jacobian), update_rule = Val(:bad_broyden)))

# broken_tests = Dict(alg => Int[] for alg in alg_ops)
# if Sys.isapple()
# broken_tests[alg_ops[1]] = [1, 5, 11]
# broken_tests[alg_ops[2]] = [1, 5, 8, 11, 18]
# broken_tests[alg_ops[3]] = [1, 5, 6, 9, 11]
# broken_tests[alg_ops[4]] = [5, 6, 8, 11]
# else
# broken_tests[alg_ops[1]] = [1, 5, 11, 15]
# broken_tests[alg_ops[2]] = [1, 5, 8, 11, 18]
# broken_tests[alg_ops[3]] = [1, 5, 9, 11]
# broken_tests[alg_ops[4]] = [5, 6, 8, 11]
# end

# test_on_library(problems, dicts, alg_ops, broken_tests, Sys.isapple() ? 1e-3 : 1e-4)
# end

# @testitem "Klement" setup=[RobustnessTesting] tags=[:core] begin
# alg_ops = (Klement(), Klement(; init_jacobian = Val(:true_jacobian_diagonal)))

# broken_tests = Dict(alg => Int[] for alg in alg_ops)
# broken_tests[alg_ops[1]] = [1, 2, 4, 5, 11, 18, 22]
# broken_tests[alg_ops[2]] = [2, 4, 5, 7, 18, 22]

# test_on_library(problems, dicts, alg_ops, broken_tests)
# end

# @testitem "PseudoTransient" setup=[RobustnessTesting] tags=[:core] begin
# # PT relies on the root being a stable equilibrium for convergence, so it won't work on
# # most problems
# alg_ops = (PseudoTransient(),)

# broken_tests = Dict(alg => Int[] for alg in alg_ops)
# broken_tests[alg_ops[1]] = [1, 2, 3, 11, 15, 16]

# test_on_library(problems, dicts, alg_ops, broken_tests)
# end
Loading

0 comments on commit f49c308

Please sign in to comment.