Skip to content

Commit 8660e4c

Browse files
committed
reorder fields in OptimizationCache for cleaner dispatches
Since we always dispatch on the optimizer, it makes much more sense to have this as the first argument (and first type parameter)
1 parent d201417 commit 8660e4c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/OptimizationBase/src/cache.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ struct AnalysisResults{O, C}
55
constraints::C
66
end
77

8-
struct OptimizationCache{F, RC, LB, UB, LC, UC, S, O, P, C, M} <:
8+
struct OptimizationCache{O, F, RC, LB, UB, LC, UC, S, P, C, M} <:
99
SciMLBase.AbstractOptimizationCache
10+
opt::O
1011
f::F
1112
reinit_cache::RC
1213
lb::LB
1314
ub::UB
1415
lcons::LC
1516
ucons::UC
1617
sense::S
17-
opt::O
1818
progress::P
1919
callback::C
2020
manifold::M
@@ -46,13 +46,13 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt;
4646
prob.f.adtype isa AutoZygote) &&
4747
(SciMLBase.requireshessian(opt) || SciMLBase.requiresconshess(opt) ||
4848
SciMLBase.requireslagh(opt))
49-
@warn "The selected optimization algorithm requires second order derivatives, but `SecondOrder` ADtype was not provided.
50-
So a `SecondOrder` with $(prob.f.adtype) for both inner and outer will be created, this can be suboptimal and not work in some cases so
49+
@warn "The selected optimization algorithm requires second order derivatives, but `SecondOrder` ADtype was not provided.
50+
So a `SecondOrder` with $(prob.f.adtype) for both inner and outer will be created, this can be suboptimal and not work in some cases so
5151
an explicit `SecondOrder` ADtype is recommended."
5252
elseif prob.f.adtype isa AutoZygote &&
5353
(SciMLBase.requiresconshess(opt) || SciMLBase.requireslagh(opt) ||
5454
SciMLBase.requireshessian(opt))
55-
@warn "The selected optimization algorithm requires second order derivatives, but `AutoZygote` ADtype was provided.
55+
@warn "The selected optimization algorithm requires second order derivatives, but `AutoZygote` ADtype was provided.
5656
So a `SecondOrder` with `AutoZygote` for inner and `AutoForwardDiff` for outer will be created, for choosing another pair
5757
an explicit `SecondOrder` ADtype is recommended."
5858
end
@@ -71,9 +71,9 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt;
7171
cons_res = nothing
7272
end
7373

74-
return OptimizationCache(f, reinit_cache_passedon, prob.lb, prob.ub, prob.lcons,
74+
return OptimizationCache(opt, f, reinit_cache_passedon, prob.lb, prob.ub, prob.lcons,
7575
prob.ucons, prob.sense,
76-
opt, progress, callback, manifold, AnalysisResults(obj_res, cons_res),
76+
progress, callback, manifold, AnalysisResults(obj_res, cons_res),
7777
merge((; maxiters, maxtime, abstol, reltol),
7878
NamedTuple(kwargs)))
7979
end

0 commit comments

Comments
 (0)