1
1
"""
2
- LineSearch(method = Static() , autodiff = AutoFiniteDiff() , alpha = true)
2
+ LineSearch(method = nothing , autodiff = nothing , alpha = true)
3
3
4
4
Wrapper over algorithms from
5
5
[LineSeaches.jl](https://github.com/JuliaNLSolvers/LineSearches.jl/). Allows automatic
@@ -13,7 +13,7 @@ differentiation for fast Vector Jacobian Products.
13
13
- `autodiff`: the automatic differentiation backend to use for the line search. Defaults to
14
14
`AutoFiniteDiff()`, which means that finite differencing is used to compute the VJP.
15
15
`AutoZygote()` will be faster in most cases, but it requires `Zygote.jl` to be manually
16
- installed and loaded
16
+ installed and loaded.
17
17
- `alpha`: the initial step size to use. Defaults to `true` (which is equivalent to `1`).
18
18
"""
19
19
@concrete struct LineSearch
@@ -22,7 +22,7 @@ differentiation for fast Vector Jacobian Products.
22
22
α
23
23
end
24
24
25
- function LineSearch (; method = nothing , autodiff = AutoFiniteDiff () , alpha = true )
25
+ function LineSearch (; method = nothing , autodiff = nothing , alpha = true )
26
26
return LineSearch (method, autodiff, alpha)
27
27
end
28
28
@@ -113,12 +113,21 @@ function LineSearchesJLCache(ls::LineSearch, f::F, u, p, fu1, IIP::Val{iip}) whe
113
113
114
114
g₀ = _mutable_zero (u)
115
115
116
- autodiff = if iip && (ls. autodiff isa AutoZygote || ls. autodiff isa AutoSparseZygote)
117
- @warn " Attempting to use Zygote.jl for linesearch on an in-place problem. Falling \
118
- back to finite differencing."
119
- AutoFiniteDiff ()
116
+ autodiff = if ls. autodiff === nothing
117
+ if ! iip && haskey (Base. loaded_modules,
118
+ Base. PkgId (Base. UUID (" e88e6eb3-aa80-5325-afca-941959d7151f" ), " Zygote" ))
119
+ AutoZygote ()
120
+ else
121
+ AutoFiniteDiff ()
122
+ end
120
123
else
121
- ls. autodiff
124
+ if iip && (ls. autodiff isa AutoZygote || ls. autodiff isa AutoSparseZygote)
125
+ @warn " Attempting to use Zygote.jl for linesearch on an in-place problem. \
126
+ Falling back to finite differencing."
127
+ AutoFiniteDiff ()
128
+ else
129
+ ls. autodiff
130
+ end
122
131
end
123
132
124
133
function g! (u, fu)
0 commit comments