Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 93db3fb

Browse files
Merge branch 'main' into qqy/downgrade_ci
2 parents ad1da99 + c258563 commit 93db3fb

21 files changed

+629
-550
lines changed

.buildkite/pipeline.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ steps:
44
- JuliaCI/julia#v1:
55
version: "1"
66
- JuliaCI/julia-test#v1:
7+
coverage: true
8+
- JuliaCI/julia-coverage#v1:
9+
codecov: true
10+
dirs:
11+
- src
12+
- ext
713
agents:
814
queue: "juliagpu"
915
cuda: "*"
@@ -13,4 +19,7 @@ steps:
1319

1420
env:
1521
GROUP: CUDA
16-
JULIA_PKG_SERVER: ""
22+
JULIA_PKG_SERVER: ""
23+
RETESTITEMS_NWORKERS: 4
24+
RETESTITEMS_NWORKER_THREADS: 2
25+
SECRET_CODECOV_TOKEN: "HsC3X/h3CrsRhMR199BUbw9xmASfTTEtdT2JMJlbkW6nsMtZXDIWxKzBNOpn0123zn3K+VE30i7+aLpcqZjlux0BQDMVLx5O5KudjrJmBE2G8KMMv1pra+UHEOFdFP3TzjHXGcHzpUrjpG8if8cHbsWdyQCV0Hdx2qAPnhX5haGPyMuIlRfoaWQfdxJPl5fDLXs1xe0LnMcYMx8uUsvvJZ/hhFtMYWJU0WFtqnAkCR8h/pQd6yZOaGP2SXJkOR8+1xbx+M8m6agH9idp2BjDPpXMOo27V3O2Gkoy3R4b5ouLdqOMaZSIOemoYCv6oh+EkbKaFvZydvm0xCW5YBFPPw==;U2FsdGVkX19FT0yFV6EMY/NVSQslXE6byckN0qa/HVU5dd3d4swmOCWBkBPtemRPGvCMP669iXSPfDTlw7ZSvw=="

.github/workflows/CI.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ on:
88
- main
99
jobs:
1010
test:
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
1414
group:
1515
- Core
1616
version:
1717
- '1'
18+
os:
19+
- ubuntu-latest
20+
- macos-latest
21+
- windows-latest
1822
steps:
1923
- uses: actions/checkout@v4
2024
- uses: julia-actions/setup-julia@v1
@@ -36,8 +40,15 @@ jobs:
3640
annotate: true
3741
env:
3842
GROUP: ${{ matrix.group }}
39-
JULIA_NUM_THREADS: "auto"
43+
JULIA_NUM_THREADS: 11
44+
RETESTITEMS_NWORKERS: 4
45+
RETESTITEMS_NWORKER_THREADS: 2
4046
- uses: julia-actions/julia-processcoverage@v1
41-
- uses: codecov/codecov-action@v3
47+
with:
48+
directories: src,ext
49+
- uses: codecov/codecov-action@v4
4250
with:
4351
file: lcov.info
52+
token: ${{ secrets.CODECOV_TOKEN }}
53+
verbose: true
54+
fail_ci_if_error: true

.github/workflows/Downstream.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- {user: SciML, repo: OrdinaryDiffEq.jl, group: InterfaceIII}
2525
- {user: SciML, repo: OrdinaryDiffEq.jl, group: InterfaceIV}
2626
- {user: SciML, repo: OrdinaryDiffEq.jl, group: InterfaceV}
27+
- {user: SciML, repo: NonlinearSolve.jl, group: All}
2728
steps:
2829
- uses: actions/checkout@v4
2930
- uses: julia-actions/setup-julia@v1
@@ -53,6 +54,9 @@ jobs:
5354
@info "Not compatible with this release. No problem." exception=err
5455
exit(0) # Exit immediately, as a success
5556
end
57+
env:
58+
RETESTITEMS_NWORKERS: 4
59+
RETESTITEMS_NWORKER_THREADS: 2
5660
- uses: julia-actions/julia-processcoverage@v1
5761
- uses: codecov/codecov-action@v3
5862
with:

.github/workflows/FormatPR.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
# https://github.com/peter-evans/create-pull-request#reference-example
1616
- name: Create Pull Request
1717
id: cpr
18-
uses: peter-evans/create-pull-request@v5
18+
uses: peter-evans/create-pull-request@v6
1919
with:
2020
token: ${{ secrets.GITHUB_TOKEN }}
2121
commit-message: Format .jl files

Project.toml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SimpleNonlinearSolve"
22
uuid = "727e6d20-b764-4bd8-a329-72de5adea6c7"
33
authors = ["SciML"]
4-
version = "1.3.2"
4+
version = "1.4.1"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -45,3 +45,24 @@ SciMLBase = "2.23"
4545
StaticArrays = "1.9"
4646
StaticArraysCore = "1.4.2"
4747
julia = "1.10"
48+
49+
[extras]
50+
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
51+
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
52+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
53+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
54+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
55+
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
56+
NonlinearProblemLibrary = "b7050fa9-e91f-4b37-bcee-a89a063da141"
57+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
58+
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
59+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
60+
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
61+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
62+
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
63+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
64+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
65+
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
66+
67+
[targets]
68+
test = ["AllocCheck", "DiffEqBase", "ForwardDiff", "LinearAlgebra", "LinearSolve", "NonlinearProblemLibrary", "Pkg", "Random", "ReTestItems", "SciMLSensitivity", "StaticArrays", "Zygote", "CUDA", "PolyesterForwardDiff", "Reexport", "Test"]

src/nlsolve/trustRegion.jl

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
2-
SimpleTrustRegion(; autodiff = AutoForwardDiff(), max_trust_radius::Real = 0.0,
3-
initial_trust_radius::Real = 0.0, step_threshold::Real = 0.1,
4-
shrink_threshold::Real = 0.25, expand_threshold::Real = 0.75,
5-
shrink_factor::Real = 0.25, expand_factor::Real = 2.0, max_shrink_times::Int = 32)
2+
SimpleTrustRegion(; autodiff = AutoForwardDiff(), max_trust_radius = 0.0,
3+
initial_trust_radius = 0.0, step_threshold = nothing,
4+
shrink_threshold = nothing, expand_threshold = nothing,
5+
shrink_factor = 0.25, expand_factor = 2.0, max_shrink_times::Int = 32,
6+
nlsolve_update_rule = Val(false))
67
78
A low-overhead implementation of a trust-region solver. This method is non-allocating on
89
scalar and static array problems.
@@ -36,17 +37,22 @@ scalar and static array problems.
3637
`expand_threshold < r` (with `r` defined in `shrink_threshold`). Defaults to `2.0`.
3738
- `max_shrink_times`: the maximum number of times to shrink the trust region radius in a
3839
row, `max_shrink_times` is exceeded, the algorithm returns. Defaults to `32`.
40+
- `nlsolve_update_rule`: If set to `Val(true)`, updates the trust region radius using the
41+
update rule from NLSolve.jl. Defaults to `Val(false)`. If set to `Val(true)`, few of the
42+
radius update parameters -- `step_threshold = 0.05`, `expand_threshold = 0.9`, and
43+
`shrink_factor = 0.5` -- have different defaults.
3944
"""
4045
@kwdef @concrete struct SimpleTrustRegion <: AbstractNewtonAlgorithm
4146
autodiff = nothing
4247
max_trust_radius = 0.0
4348
initial_trust_radius = 0.0
4449
step_threshold = 0.0001
45-
shrink_threshold = 0.25
46-
expand_threshold = 0.75
47-
shrink_factor = 0.25
50+
shrink_threshold = nothing
51+
expand_threshold = nothing
52+
shrink_factor = nothing
4853
expand_factor = 2.0
4954
max_shrink_times::Int = 32
55+
nlsolve_update_rule = Val(false)
5056
end
5157

5258
function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args...;
@@ -57,14 +63,27 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
5763
Δₘₐₓ = T(alg.max_trust_radius)
5864
Δ = T(alg.initial_trust_radius)
5965
η₁ = T(alg.step_threshold)
60-
η₂ = T(alg.shrink_threshold)
61-
η₃ = T(alg.expand_threshold)
62-
t₁ = T(alg.shrink_factor)
66+
if alg.shrink_threshold === nothing
67+
η₂ = _unwrap_val(alg.nlsolve_update_rule) ? T(0.05) : T(0.25)
68+
else
69+
η₂ = T(alg.shrink_threshold)
70+
end
71+
if alg.expand_threshold === nothing
72+
η₃ = _unwrap_val(alg.nlsolve_update_rule) ? T(0.9) : T(0.75)
73+
else
74+
η₃ = T(alg.expand_threshold)
75+
end
76+
if alg.shrink_factor === nothing
77+
t₁ = _unwrap_val(alg.nlsolve_update_rule) ? T(0.5) : T(0.25)
78+
else
79+
t₁ = T(alg.shrink_factor)
80+
end
6381
t₂ = T(alg.expand_factor)
6482
max_shrink_times = alg.max_shrink_times
6583
autodiff = __get_concrete_autodiff(prob, alg.autodiff)
6684

6785
fx = _get_fx(prob, x)
86+
norm_fx = norm(fx)
6887
@bb xo = copy(x)
6988
J, jac_cache = jacobian_cache(autodiff, prob.f, fx, x, prob.p)
7089
fx, ∇f = value_and_jacobian(autodiff, prob.f, fx, x, prob.p, jac_cache; J)
@@ -73,10 +92,17 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
7392
termination_condition)
7493

7594
# Set default trust region radius if not specified by user.
76-
Δₘₐₓ == 0 && (Δₘₐₓ = max(norm(fx), maximum(x) - minimum(x)))
77-
Δ == 0 &&= Δₘₐₓ / 11)
95+
Δₘₐₓ == 0 && (Δₘₐₓ = max(norm_fx, maximum(x) - minimum(x)))
96+
if Δ == 0
97+
if _unwrap_val(alg.nlsolve_update_rule)
98+
norm_x = norm(x)
99+
Δ = T(ifelse(norm_x > 0, norm_x, 1))
100+
else
101+
Δ = T(Δₘₐₓ / 11)
102+
end
103+
end
78104

79-
fₖ = 0.5 * norm(fx)^2
105+
fₖ = 0.5 * norm_fx^2
80106
H = ∇f' * ∇f
81107
g = _restructure(x, ∇f' * _vec(fx))
82108
shrink_counter = 0
@@ -87,7 +113,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
87113
@bb= copy(x)
88114
dogleg_cache = (; δsd, δN_δsd, δN)
89115

90-
for k in 1:maxiters
116+
for _ in 1:maxiters
91117
# Solve the trust region subproblem.
92118
δ = dogleg_method!!(dogleg_cache, ∇f, fx, g, Δ)
93119
@bb @. x = xo + δ
@@ -107,7 +133,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
107133
Δ = t₁ * Δ
108134
shrink_counter += 1
109135
shrink_counter > max_shrink_times && return build_solution(prob, alg, x, fx;
110-
retcode = ReturnCode.ConvergenceFailure)
136+
retcode = ReturnCode.ShrinkThresholdExceeded)
111137
end
112138

113139
if r η₁
@@ -121,12 +147,22 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
121147
fx, ∇f = value_and_jacobian(autodiff, prob.f, fx, x, prob.p, jac_cache; J)
122148

123149
# Update the trust region radius.
124-
(r > η₃) && (norm(δ) Δ) &&= min(t₂ * Δ, Δₘₐₓ))
150+
if !_unwrap_val(alg.nlsolve_update_rule) && r > η₃
151+
Δ = min(t₂ * Δ, Δₘₐₓ)
152+
end
125153
fₖ = fₖ₊₁
126154

127155
@bb H = transpose(∇f) × ∇f
128156
@bb g = transpose(∇f) × vec(fx)
129157
end
158+
159+
if _unwrap_val(alg.nlsolve_update_rule)
160+
if r > η₃
161+
Δ = t₂ * norm(δ)
162+
elseif r > 0.5
163+
Δ = max(Δ, t₂ * norm(δ))
164+
end
165+
end
130166
end
131167

132168
return build_solution(prob, alg, x, fx; retcode = ReturnCode.MaxIters)

test/23_test_problems.jl

Lines changed: 0 additions & 87 deletions
This file was deleted.

test/Project.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)