Skip to content

Commit 8e7c260

Browse files
Merge pull request #659 from ParasPuneetSingh/master
Changed trait constraints to solve.jl for calculation of gradients, hessians and more. #651
2 parents ab38d18 + caafb86 commit 8e7c260

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/solve.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ function _check_opt_alg(prob::OptimizationProblem, alg; kwargs...)
116116
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires constraints, pass them with the `cons` kwarg in `OptimizationFunction`."))
117117
!allowscallback(alg) && haskey(kwargs, :callback) &&
118118
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) does not support callbacks, remove the `callback` keyword argument from the `solve` call."))
119+
!requiresgradient(alg) && !(prob.f isa OptimizationFunction) &&
120+
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires gradients, hence use `OptimizationFunction` to generate them with an automatic differentiation backend e.g. `OptimizationFunction(f, AutoForwardDiff())` or pass it in with `grad` kwarg."))
121+
!requireshessian(alg) && !(prob.f isa OptimizationFunction) &&
122+
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires hessians, hence use `OptimizationFunction` to generate them with an automatic differentiation backend e.g. `OptimizationFunction(f, AutoFiniteDiff(); kwargs...)` or pass them in with `hess` kwarg."))
123+
!requiresconsjac(alg) && !(prob.f isa OptimizationFunction) &&
124+
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires constraint jacobians, hence use `OptimizationFunction` to generate them with an automatic differentiation backend e.g. `OptimizationFunction(f, AutoFiniteDiff(); kwargs...)` or pass them in with `cons` kwarg."))
125+
!requiresconshess(alg) && !(prob.f isa OptimizationFunction) &&
126+
throw(IncompatibleOptimizerError("The algorithm $(typeof(alg)) requires constraint hessians, hence use `OptimizationFunction` to generate them with an automatic differentiation backend e.g. `OptimizationFunction(f, AutoFiniteDiff(), AutoFiniteDiff(hess=true); kwargs...)` or pass them in with `cons` kwarg."))
119127
return
120128
end
121129

0 commit comments

Comments
 (0)