Skip to content

Commit 07963b7

Browse files
authored
Add tests with Aqua, ExplicitImports and JET (#189)
* Require Julia 1.10 and remove Parameters * Add tests with Aqua, ExplicitImports and JET
1 parent 427ee74 commit 07963b7

File tree

11 files changed

+88
-35
lines changed

11 files changed

+88
-35
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ name: Run tests
22

33
on: [push, pull_request]
44

5+
# needed to allow julia-actions/cache to delete old caches that it has created
6+
permissions:
7+
actions: write
8+
contents: read
9+
510
jobs:
611
test:
712
runs-on: ${{ matrix.os }}
813
strategy:
914
matrix:
10-
julia-version: ['1.6', '1', 'nightly']
11-
julia-arch: [x64, x86]
15+
julia-version: ['min', 'lts', '1']
1216
os: [ubuntu-latest, windows-latest, macOS-latest]
13-
exclude:
14-
- os: macOS-latest
15-
julia-arch: x86
16-
1717
steps:
1818
- uses: actions/checkout@v2
19-
- uses: julia-actions/setup-julia@v1
19+
- uses: julia-actions/setup-julia@v2
2020
with:
2121
version: ${{ matrix.julia-version }}
22-
arch: ${{ matrix.julia-arch }}
22+
- uses: julia-actions/cache@v2
2323
- uses: julia-actions/julia-buildpkg@v1
2424
- uses: julia-actions/julia-runtest@v1
2525
with:

Project.toml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
name = "LineSearches"
22
uuid = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
3-
version = "7.4.1"
3+
version = "7.5.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
77
NLSolversBase = "d41bc354-129a-5804-8e4c-c37616107c6c"
88
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
9-
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
109
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1110

1211
[compat]
12+
Aqua = "0.8.14"
1313
DoubleFloats = "1"
14+
ExplicitImports = "1.14"
15+
JET = "0.9, 0.10"
16+
LinearAlgebra = "<0.0.1, 1"
1417
NLSolversBase = "7"
1518
NaNMath = "1"
1619
Optim = "1"
1720
OptimTestProblems = "2"
18-
Parameters = "0.10, 0.11, 0.12"
19-
julia = "1.6"
21+
Printf = "<0.0.1, 1"
22+
Test = "<0.0.1, 1"
23+
julia = "1.10"
2024

2125
[extras]
26+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2227
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
28+
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
29+
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
2330
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
2431
OptimTestProblems = "cec144fc-5a64-5bc6-99fb-dde8f63e154c"
2532
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2633

2734
[targets]
28-
test = ["Test", "OptimTestProblems", "Optim", "DoubleFloats"]
35+
test = ["Aqua", "ExplicitImports", "JET", "Test", "OptimTestProblems", "Optim", "DoubleFloats"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Build Status](https://travis-ci.org/JuliaNLSolvers/LineSearches.jl.svg?branch=master)](https://travis-ci.org/JuliaNLSolvers/LineSearches.jl)
44
[![Codecov branch](https://img.shields.io/codecov/c/github/JuliaNLSolvers/LineSearches.jl/master.svg?maxAge=2592000)](https://codecov.io/gh/JuliaNLSolvers/LineSearches.jl)
55
[![][docs-stable-img]][docs-stable-url]
6+
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
67

78
## Description
89
This package provides an interface to line search algorithms implemented in Julia.

src/LineSearches.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
module LineSearches
22

3-
using Printf
4-
import LinearAlgebra: dot, norm
5-
using Parameters, NaNMath
6-
7-
import NLSolversBase
8-
import NLSolversBase: AbstractObjective
3+
using Printf: @sprintf
4+
using LinearAlgebra: dot, norm
5+
using NaNMath: NaNMath
6+
using NLSolversBase: NLSolversBase, AbstractObjective
97

108
export LineSearchException, LineSearchCache
119

src/backtracking.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ there exists a factor ρ = ρ(c₁) such that α' ≦ ρ α.
88
99
This is a modification of the algorithm described in Nocedal Wright (2nd ed), Sec. 3.5.
1010
"""
11-
@with_kw struct BackTracking{TF, TI} <: AbstractLineSearch
11+
@kwdef struct BackTracking{TF, TI} <: AbstractLineSearch
1212
c_1::TF = 1e-4
1313
ρ_hi::TF = 0.5
1414
ρ_lo::TF = 0.1
@@ -38,7 +38,7 @@ end
3838

3939
# TODO: Should we deprecate the interface that only uses the ϕ argument?
4040
function (ls::BackTracking)(ϕ, αinitial::Tα, ϕ_0, dϕ_0) where
41-
@unpack c_1, ρ_hi, ρ_lo, iterations, order, cache = ls
41+
(; c_1, ρ_hi, ρ_lo, iterations, order, cache) = ls
4242
emptycache!(cache)
4343
pushcache!(cache, 0, ϕ_0, dϕ_0) # backtracking doesn't use the slope except here
4444

src/hagerzhang.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Conjugate gradient line search implementation from:
8080
conjugate gradient method with guaranteed descent. ACM
8181
Transactions on Mathematical Software 32: 113–137.
8282
"""
83-
@with_kw struct HagerZhang{T, Tm} <: AbstractLineSearch
83+
@kwdef struct HagerZhang{T, Tm} <: AbstractLineSearch
8484
delta::T = DEFAULTDELTA # c_1 Wolfe sufficient decrease condition
8585
sigma::T = DEFAULTSIGMA # c_2 Wolfe curvature condition (Recommend 0.1 for GradientDescent)
8686
alphamax::T = Inf
@@ -110,8 +110,8 @@ function (ls::HagerZhang)(ϕ, ϕdϕ,
110110
c::T,
111111
phi_0::Real,
112112
dphi_0::Real) where T # Should c and phi_0 be same type?
113-
@unpack delta, sigma, alphamax, rho, epsilon, gamma,
114-
linesearchmax, psi3, display, mayterminate, cache = ls
113+
(; delta, sigma, alphamax, rho, epsilon, gamma,
114+
linesearchmax, psi3, display, mayterminate, cache) = ls
115115
emptycache!(cache)
116116

117117
zeroT = convert(T, 0)
@@ -129,7 +129,7 @@ function (ls::HagerZhang)(ϕ, ϕdϕ,
129129
# ϕ(x_new) infinite
130130
iterfinitemax::Int = ceil(Int, -log2(eps(T)))
131131
if cache !== nothing
132-
@unpack alphas, values, slopes = cache
132+
(; alphas, values, slopes) = cache
133133
else
134134
alphas = [zeroT] # for bisection
135135
values = [phi_0]

src/initialguess.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Keyword `alpha` corresponds to static step length, default is 1.0.
77
If keyword `scaled = true`, then the initial step length
88
is scaled with the `l_2` norm of the step direction.
99
"""
10-
@with_kw struct InitialStatic{T}
10+
@kwdef struct InitialStatic{T}
1111
alpha::T = 1.0
1212
scaled::Bool = false # Scales step. alpha ← min(alpha,||s||_2) / ||s||_2
1313
end
@@ -29,7 +29,7 @@ within the bounds [alphamin, alphamax]
2929
3030
If state.alpha is NaN, then return fallback value is.alpha
3131
"""
32-
@with_kw struct InitialPrevious{T}
32+
@kwdef struct InitialPrevious{T}
3333
alpha::T = 1.0
3434
alphamin::T = 0.0
3535
alphamax::T = Inf
@@ -61,7 +61,7 @@ This procedure have several arguments, with the following defaults.
6161
6262
If αmax ≠ 1.0, then you should consider to ensure that snap2one[2] < αmax.
6363
"""
64-
@with_kw struct InitialQuadratic{T}
64+
@kwdef struct InitialQuadratic{T}
6565
αmin::T = 1e-12 # Minimum initial step size (value somewhat arbitrary)
6666
αmax::T = 1.0 # Maximum initial step size (advised by Nocedal+Wright)
6767
α0::T = 1.0 # Fallback at first iteration
@@ -121,7 +121,7 @@ function InitialConstantChange{T}(; αmin = 1e-12,
121121
snap2one = (0.75, Inf)) where T
122122
αmin, αmax, α0, ρ = convert.(T, (αmin, αmax, α0, ρ))
123123
snap2one = convert.(T, snap2one)
124-
InitialConstantChange(αmin, αmax, α0, ρ, snap2one, Ref{T}(convert(T, NaN)))
124+
InitialConstantChange(αmin, αmax, α0, ρ, snap2one, Ref(convert(T, NaN)))
125125
end
126126

127127
# Have to make this constructor without with_kw because Ref(NaN) has to adapt to T
@@ -131,7 +131,7 @@ function InitialConstantChange(; αmin = 1e-12,
131131
ρ = 0.25,
132132
snap2one = (0.75, Inf))
133133
T = promote_type(typeof.((αmin, αmax, α0, ρ))...)
134-
InitialConstantChange(αmin, αmax, α0, ρ, snap2one, Ref{T}(convert(T, NaN)))
134+
InitialConstantChange(αmin, αmax, α0, ρ, snap2one, Ref(convert(T, NaN)))
135135
end
136136

137137
function (is::InitialConstantChange{T})(ls, state, phi_0, dphi_0, df) where T
@@ -163,7 +163,7 @@ Initial step size algorithm from
163163
If α0 is NaN, then procedure I0 is called at the first iteration,
164164
otherwise, we select according to procedure I1-2, with starting value α0.
165165
"""
166-
@with_kw struct InitialHagerZhang{T}
166+
@kwdef struct InitialHagerZhang{T}
167167
ψ0::T = 0.01
168168
ψ1::T = 0.2
169169
ψ2::T = 2.0

src/morethuente.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ The line search implementation from:
138138
Line search algorithms with guaranteed sufficient decrease.
139139
ACM Transactions on Mathematical Software (TOMS) 20.3 (1994): 286-307.
140140
"""
141-
@with_kw struct MoreThuente{T} <: AbstractLineSearch
141+
@kwdef struct MoreThuente{T} <: AbstractLineSearch
142142
f_tol::T = 1e-4 # c_1 Wolfe sufficient decrease condition
143143
gtol::T = 0.9 # c_2 Wolfe curvature condition (Recommend 0.1 for GradientDescent)
144144
x_tol::T = 1e-8
@@ -162,7 +162,7 @@ function (ls::MoreThuente)(ϕdϕ,
162162
alpha::T,
163163
ϕ_0,
164164
dϕ_0) where T
165-
@unpack f_tol, gtol, x_tol, alphamin, alphamax, maxfev, cache = ls
165+
(; f_tol, gtol, x_tol, alphamin, alphamax, maxfev, cache) = ls
166166
emptycache!(cache)
167167

168168
iterfinitemax = -log2(eps(T))

src/strongwolfe.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use `MoreThuente`, `HagerZhang` or `BackTracking`.
1414
* `c_2 = 0.9` : second (strong) Wolfe condition
1515
* `ρ = 2.0` : bracket growth
1616
"""
17-
@with_kw struct StrongWolfe{T} <: AbstractLineSearch
17+
@kwdef struct StrongWolfe{T} <: AbstractLineSearch
1818
c_1::T = 1e-4
1919
c_2::T = 0.9
2020
ρ::T = 2.0
@@ -50,7 +50,7 @@ Both `alpha` and `ϕ(alpha)` are returned.
5050
"""
5151
function (ls::StrongWolfe)(ϕ, dϕ, ϕdϕ,
5252
alpha0::T, ϕ_0, dϕ_0) where T<:Real
53-
@unpack c_1, c_2, ρ, cache = ls
53+
(; c_1, c_2, ρ, cache) = ls
5454
emptycache!(cache)
5555

5656
zeroT = convert(T, 0)

test/qa.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using LineSearches
2+
using Test
3+
import Aqua
4+
import ExplicitImports
5+
import JET
6+
7+
@testset "QA" begin
8+
@testset "Aqua" begin
9+
Aqua.test_all(LineSearches)
10+
end
11+
12+
@testset "ExplicitImports" begin
13+
# No implicit imports (`using XY`)
14+
@test ExplicitImports.check_no_implicit_imports(LineSearches) === nothing
15+
16+
# All explicit imports (`using XY: Z`) are loaded via their owners
17+
@test ExplicitImports.check_all_explicit_imports_via_owners(LineSearches) === nothing
18+
19+
# No explicit imports (`using XY: Z`) that are not used
20+
@test ExplicitImports.check_no_stale_explicit_imports(LineSearches) === nothing
21+
22+
# Nothing is accessed via modules other than its owner
23+
@test ExplicitImports.check_all_qualified_accesses_via_owners(LineSearches) === nothing
24+
25+
# Almost no accesses of non-public names
26+
@test ExplicitImports.check_all_qualified_accesses_are_public(
27+
LineSearches;
28+
ignore = (
29+
:RefValue, # Base
30+
:max, # NaNMath
31+
:min, # NaNMath
32+
),
33+
) === nothing
34+
35+
# No self-qualified accesses
36+
@test ExplicitImports.check_no_self_qualified_accesses(LineSearches) === nothing
37+
end
38+
39+
@testset "JET" begin
40+
# Check that there are no undefined global references and undefined field accesses
41+
JET.test_package(LineSearches; target_defined_modules = true, mode = :typo)
42+
43+
# Analyze methods based on their declared signature
44+
JET.test_package(LineSearches; target_defined_modules = true)
45+
end
46+
end

0 commit comments

Comments
 (0)