Skip to content

Commit d44b6b6

Browse files
committed
test: fix more of NonlinearSolve tests
1 parent 2d4a35d commit d44b6b6

34 files changed

+756
-764
lines changed

.buildkite/pipeline.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ steps:
1414
Pkg.Registry.update();
1515
# Install packages present in subdirectories
1616
dev_pks = Pkg.PackageSpec[];
17-
for path in ("lib/SciMLJacobianOperators", "lib/BracketingNonlinearSolve", "lib/NonlinearSolveBase", "lib/SimpleNonlinearSolve")
17+
for path in ("lib/SciMLJacobianOperators", "lib/BracketingNonlinearSolve", "lib/NonlinearSolveBase", "lib/SimpleNonlinearSolve", "lib/NonlinearSolveFirstOrder", "lib/NonlinearSolveSpectralMethods", "lib/NonlinearSolveQuasiNewton")
1818
push!(dev_pks, Pkg.PackageSpec(; path));
1919
end
2020
Pkg.develop(dev_pks);
@@ -42,7 +42,7 @@ steps:
4242
Pkg.Registry.update();
4343
# Install packages present in subdirectories
4444
dev_pks = Pkg.PackageSpec[];
45-
for path in ("lib/NonlinearSolveBase", "lib/BracketingNonlinearSolve")
45+
for path in ("lib/NonlinearSolveBase", "lib/BracketingNonlinearSolve", "lib/SciMLJacobianOperators")
4646
push!(dev_pks, Pkg.PackageSpec(; path))
4747
end
4848
Pkg.develop(dev_pks);

.github/workflows/CI_BracketingNonlinearSolve.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
version:
29-
- "lts"
29+
- "1.10"
3030
- "1"
3131
os:
3232
- ubuntu-latest

.github/workflows/CI_NonlinearSolve.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ on:
1414
- "lib/BracketingNonlinearSolve/**"
1515
- "lib/NonlinearSolveBase/**"
1616
- "lib/SimpleNonlinearSolve/**"
17+
- "lib/NonlinearSolveFirstOrder/**"
18+
- "lib/NonlinearSolveSpectralMethods/**"
19+
- "lib/NonlinearSolveQuasiNewton/**"
1720
push:
1821
branches:
1922
- master
@@ -33,10 +36,9 @@ jobs:
3336
group:
3437
- Core
3538
- Downstream
36-
- Misc
3739
- Wrappers
3840
version:
39-
- "lts"
41+
- "1.10"
4042
- "1"
4143
os:
4244
- ubuntu-latest
@@ -63,7 +65,7 @@ jobs:
6365
Pkg.Registry.update()
6466
# Install packages present in subdirectories
6567
dev_pks = Pkg.PackageSpec[]
66-
for path in ("lib/SciMLJacobianOperators", "lib/BracketingNonlinearSolve", "lib/NonlinearSolveBase", "lib/SimpleNonlinearSolve")
68+
for path in ("lib/SciMLJacobianOperators", "lib/BracketingNonlinearSolve", "lib/NonlinearSolveBase", "lib/SimpleNonlinearSolve", "lib/NonlinearSolveFirstOrder", "lib/NonlinearSolveSpectralMethods", "lib/NonlinearSolveQuasiNewton")
6769
push!(dev_pks, Pkg.PackageSpec(; path))
6870
end
6971
Pkg.develop(dev_pks)
@@ -74,7 +76,7 @@ jobs:
7476
GROUP: ${{ matrix.group }}
7577
- uses: julia-actions/julia-processcoverage@v1
7678
with:
77-
directories: src,ext,lib/SciMLJacobianOperators/src
79+
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
7880
- uses: codecov/codecov-action@v4
7981
with:
8082
file: lcov.info

.github/workflows/CI_NonlinearSolveBase.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
version:
28-
- "lts"
28+
- "1.10"
2929
- "1"
3030
os:
3131
- ubuntu-latest

.github/workflows/CI_NonlinearSolveFirstOrder.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
version:
29-
- "lts"
29+
- "1.10"
3030
- "1"
3131
os:
3232
- ubuntu-latest

.github/workflows/CI_NonlinearSolveQuasiNewton.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
version:
29-
- "lts"
29+
- "1.10"
3030
- "1"
3131
os:
3232
- ubuntu-latest

.github/workflows/CI_NonlinearSolveSpectralMethods.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
version:
29-
- "lts"
29+
- "1.10"
3030
- "1"
3131
os:
3232
- ubuntu-latest

.github/workflows/CI_SciMLJacobianOperators.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
fail-fast: false
2525
matrix:
2626
version:
27-
- "lts"
27+
- "1.10"
2828
- "1"
2929
os:
3030
- ubuntu-latest

.github/workflows/Downgrade.yml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
group:
2222
- Core
2323
- Downstream
24-
- Misc
2524
- Wrappers
2625
steps:
2726
- uses: actions/checkout@v4

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ InteractiveUtils = "<0.0.1, 1"
7878
LeastSquaresOptim = "0.8.5"
7979
LineSearch = "0.1.4"
8080
LineSearches = "7.3"
81-
LinearAlgebra = "1.11.0"
81+
LinearAlgebra = "1.10"
8282
LinearSolve = "2.36.1"
8383
MINPACK = "1.2"
8484
MPI = "0.20.22"

lib/NonlinearSolveBase/src/NonlinearSolveBase.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module NonlinearSolveBase
33
using Compat: @compat
44
using ConcreteStructs: @concrete
55
using FastClosures: @closure
6-
using Preferences: @load_preference
6+
using Preferences: @load_preference, @set_preferences!
77

88
using ADTypes: ADTypes, AbstractADType, AutoSparse, NoSparsityDetector,
99
KnownJacobianSparsityDetector

lib/NonlinearSolveBase/src/timer_outputs.jl

+22
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,25 @@ end
3131
@static if !TIMER_OUTPUTS_ENABLED
3232
@inline reset_timer!(::Nothing) = nothing
3333
end
34+
35+
"""
36+
enable_timer_outputs()
37+
38+
Enable `TimerOutput` for all `NonlinearSolve` algorithms. This is useful for debugging
39+
but has some overhead, so it is disabled by default.
40+
"""
41+
function enable_timer_outputs()
42+
@set_preferences!("enable_timer_outputs" => true)
43+
@info "Timer Outputs Enabled. Restart the Julia session for this to take effect."
44+
end
45+
46+
"""
47+
disable_timer_outputs()
48+
49+
Disable `TimerOutput` for all `NonlinearSolve` algorithms. This should be used when
50+
`NonlinearSolve` is being used in performance-critical code.
51+
"""
52+
function disable_timer_outputs()
53+
@set_preferences!("enable_timer_outputs" => false)
54+
@info "Timer Outputs Disabled. Restart the Julia session for this to take effect."
55+
end

lib/NonlinearSolveFirstOrder/Project.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Reexport = "1"
5252
SciMLBase = "2.54"
5353
SciMLJacobianOperators = "0.1.0"
5454
Setfield = "1.1.1"
55+
SparseArrays = "1.10"
5556
SparseConnectivityTracer = "0.6.8"
5657
SparseMatrixColorings = "0.4.8"
5758
StableRNGs = "1"
@@ -75,6 +76,7 @@ NonlinearProblemLibrary = "b7050fa9-e91f-4b37-bcee-a89a063da141"
7576
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
7677
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
7778
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
79+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
7880
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
7981
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
8082
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
@@ -83,4 +85,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8385
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
8486

8587
[targets]
86-
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "Enzyme", "ExplicitImports", "Hwloc", "InteractiveUtils", "LineSearch", "LineSearches", "NonlinearProblemLibrary", "Pkg", "Random", "ReTestItems", "SparseConnectivityTracer", "SparseMatrixColorings", "StableRNGs", "StaticArrays", "Test", "Zygote"]
88+
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "Enzyme", "ExplicitImports", "Hwloc", "InteractiveUtils", "LineSearch", "LineSearches", "NonlinearProblemLibrary", "Pkg", "Random", "ReTestItems", "SparseArrays", "SparseConnectivityTracer", "SparseMatrixColorings", "StableRNGs", "StaticArrays", "Test", "Zygote"]

src/NonlinearSolve.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ using DiffEqBase: DiffEqBase # Needed for `init` / `solve` dispatches
1212
using LinearAlgebra: LinearAlgebra, norm
1313
using LineSearch: BackTracking
1414
using NonlinearSolveBase: NonlinearSolveBase, InternalAPI, AbstractNonlinearSolveAlgorithm,
15-
AbstractNonlinearSolveCache, Utils, L2_NORM
15+
AbstractNonlinearSolveCache, Utils, L2_NORM,
16+
enable_timer_outputs, disable_timer_outputs
1617

1718
using Preferences: set_preferences!
1819
using SciMLBase: SciMLBase, NLStats, ReturnCode, AbstractNonlinearProblem, NonlinearProblem,

src/helpers.jl

-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +0,0 @@
1-
"""
2-
enable_timer_outputs()
3-
4-
Enable `TimerOutput` for all `NonlinearSolve` algorithms. This is useful for debugging
5-
but has some overhead, so it is disabled by default.
6-
"""
7-
function enable_timer_outputs()
8-
set_preferences!(NonlinearSolveBase, "enable_timer_outputs" => true; force = true)
9-
@info "Timer Outputs Enabled. Restart the Julia session for this to take effect."
10-
end
11-
12-
"""
13-
disable_timer_outputs()
14-
15-
Disable `TimerOutput` for all `NonlinearSolve` algorithms. This should be used when
16-
`NonlinearSolve` is being used in performance-critical code.
17-
"""
18-
function disable_timer_outputs()
19-
set_preferences!(NonlinearSolveBase, "enable_timer_outputs" => false; force = true)
20-
@info "Timer Outputs Disabled. Restart the Julia session for this to take effect."
21-
end

test/23_test_problems_tests.jl

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# @testsetup module RobustnessTesting
2+
# using NonlinearSolve, LinearAlgebra, LinearSolve, NonlinearProblemLibrary, Test
3+
4+
# problems = NonlinearProblemLibrary.problems
5+
# dicts = NonlinearProblemLibrary.dicts
6+
7+
# function test_on_library(
8+
# problems, dicts, alg_ops, broken_tests, ϵ = 1e-4; skip_tests = nothing)
9+
# for (idx, (problem, dict)) in enumerate(zip(problems, dicts))
10+
# x = dict["start"]
11+
# res = similar(x)
12+
# nlprob = NonlinearProblem(problem, copy(x))
13+
# @testset "$idx: $(dict["title"])" begin
14+
# for alg in alg_ops
15+
# try
16+
# sol = solve(nlprob, alg; maxiters = 10000)
17+
# problem(res, sol.u, nothing)
18+
19+
# skip = skip_tests !== nothing && idx in skip_tests[alg]
20+
# if skip
21+
# @test_skip norm(res, Inf) ≤ ϵ
22+
# continue
23+
# end
24+
# broken = idx in broken_tests[alg] ? true : false
25+
# @test norm(res, Inf)≤ϵ broken=broken
26+
# catch err
27+
# @error err
28+
# broken = idx in broken_tests[alg] ? true : false
29+
# if broken
30+
# @test false broken=true
31+
# else
32+
# @test 1 == 2
33+
# end
34+
# end
35+
# end
36+
# end
37+
# end
38+
# end
39+
40+
# export test_on_library, problems, dicts
41+
# end
42+
43+
# @testitem "PolyAlgorithms" setup=[RobustnessTesting] tags=[:core] begin
44+
# alg_ops = (RobustMultiNewton(), FastShortcutNonlinearPolyalg())
45+
46+
# broken_tests = Dict(alg => Int[] for alg in alg_ops)
47+
# broken_tests[alg_ops[1]] = []
48+
# broken_tests[alg_ops[2]] = []
49+
50+
# test_on_library(problems, dicts, alg_ops, broken_tests)
51+
# end
52+
53+
# @testitem "NewtonRaphson" setup=[RobustnessTesting] tags=[:core] begin
54+
# alg_ops = (NewtonRaphson(),)
55+
56+
# broken_tests = Dict(alg => Int[] for alg in alg_ops)
57+
# broken_tests[alg_ops[1]] = [1]
58+
59+
# test_on_library(problems, dicts, alg_ops, broken_tests)
60+
# end
61+
62+
# @testitem "TrustRegion" setup=[RobustnessTesting] tags=[:core] begin
63+
# alg_ops = (TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Simple),
64+
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Fan),
65+
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Hei),
66+
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Yuan),
67+
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Bastin),
68+
# TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.NLsolve))
69+
70+
# broken_tests = Dict(alg => Int[] for alg in alg_ops)
71+
# broken_tests[alg_ops[1]] = [11, 21]
72+
# broken_tests[alg_ops[2]] = [11, 21]
73+
# broken_tests[alg_ops[3]] = [11, 21]
74+
# broken_tests[alg_ops[4]] = [8, 11, 21]
75+
# broken_tests[alg_ops[5]] = [21]
76+
# broken_tests[alg_ops[6]] = [11, 21]
77+
78+
# test_on_library(problems, dicts, alg_ops, broken_tests)
79+
# end
80+
81+
# @testitem "LevenbergMarquardt" setup=[RobustnessTesting] tags=[:core] begin
82+
# using LinearSolve
83+
84+
# alg_ops = (LevenbergMarquardt(), LevenbergMarquardt(; α_geodesic = 0.1),
85+
# LevenbergMarquardt(; linsolve = CholeskyFactorization()))
86+
87+
# broken_tests = Dict(alg => Int[] for alg in alg_ops)
88+
# broken_tests[alg_ops[1]] = [11, 21]
89+
# broken_tests[alg_ops[2]] = [11, 21]
90+
# broken_tests[alg_ops[3]] = [11, 21]
91+
92+
# test_on_library(problems, dicts, alg_ops, broken_tests)
93+
# end
94+
95+
# @testitem "DFSane" setup=[RobustnessTesting] tags=[:core] begin
96+
# alg_ops = (DFSane(),)
97+
98+
# broken_tests = Dict(alg => Int[] for alg in alg_ops)
99+
# broken_tests[alg_ops[1]] = [1, 2, 3, 5, 21]
100+
101+
# test_on_library(problems, dicts, alg_ops, broken_tests)
102+
# end
103+
104+
# @testitem "Broyden" setup=[RobustnessTesting] tags=[:core] begin
105+
# alg_ops = (Broyden(), Broyden(; init_jacobian = Val(:true_jacobian)),
106+
# Broyden(; update_rule = Val(:bad_broyden)),
107+
# Broyden(; init_jacobian = Val(:true_jacobian), update_rule = Val(:bad_broyden)))
108+
109+
# broken_tests = Dict(alg => Int[] for alg in alg_ops)
110+
# if Sys.isapple()
111+
# broken_tests[alg_ops[1]] = [1, 5, 11]
112+
# broken_tests[alg_ops[2]] = [1, 5, 8, 11, 18]
113+
# broken_tests[alg_ops[3]] = [1, 5, 6, 9, 11]
114+
# broken_tests[alg_ops[4]] = [5, 6, 8, 11]
115+
# else
116+
# broken_tests[alg_ops[1]] = [1, 5, 11, 15]
117+
# broken_tests[alg_ops[2]] = [1, 5, 8, 11, 18]
118+
# broken_tests[alg_ops[3]] = [1, 5, 9, 11]
119+
# broken_tests[alg_ops[4]] = [5, 6, 8, 11]
120+
# end
121+
122+
# test_on_library(problems, dicts, alg_ops, broken_tests, Sys.isapple() ? 1e-3 : 1e-4)
123+
# end
124+
125+
# @testitem "Klement" setup=[RobustnessTesting] tags=[:core] begin
126+
# alg_ops = (Klement(), Klement(; init_jacobian = Val(:true_jacobian_diagonal)))
127+
128+
# broken_tests = Dict(alg => Int[] for alg in alg_ops)
129+
# broken_tests[alg_ops[1]] = [1, 2, 4, 5, 11, 18, 22]
130+
# broken_tests[alg_ops[2]] = [2, 4, 5, 7, 18, 22]
131+
132+
# test_on_library(problems, dicts, alg_ops, broken_tests)
133+
# end
134+
135+
# @testitem "PseudoTransient" setup=[RobustnessTesting] tags=[:core] begin
136+
# # PT relies on the root being a stable equilibrium for convergence, so it won't work on
137+
# # most problems
138+
# alg_ops = (PseudoTransient(),)
139+
140+
# broken_tests = Dict(alg => Int[] for alg in alg_ops)
141+
# broken_tests[alg_ops[1]] = [1, 2, 3, 11, 15, 16]
142+
143+
# test_on_library(problems, dicts, alg_ops, broken_tests)
144+
# end

0 commit comments

Comments
 (0)