Skip to content

Commit

Permalink
check that dense callbacks are available when DenseKKTSystem is used
Browse files Browse the repository at this point in the history
  • Loading branch information
frapac committed Sep 3, 2021
1 parent fe8ee1f commit 9a33164
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/interiorpointsolver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ function Solver(nlp::NonlinearProgram;
set_options!(opt,option_dict,kwargs)
check_option_sanity(opt)

# If we are using DenseKKTSystem, ensure that dense callbacks are available
if opt.kkt_system == DENSE_KKT_SYSTEM
if !has_dense_hessian_callback(nlp)
error("MadNLP is unable to find a dense callback for Hessian in `nlp`.\n" *
"Please add a new method with signature `lag_hess!(<:AbstractMatrix{T}, Any, Any, Any)`.")
end
if ((nlp.m > 0) && !has_dense_jacobian_callback(nlp))
error("MadNLP is unable to find a dense callback for Jacobian in `nlp`.\n" *
"Please add a new method with signature `con_jac!(<:AbstractMatrix{T}, Any)`.")
end
end
logger = Logger(print_level=opt.print_level,file_print_level=opt.file_print_level,
file = opt.output_file == "" ? nothing : open(opt.output_file,"w+"))
@trace(logger,"Logger is initialized.")
Expand Down
10 changes: 10 additions & 0 deletions src/nonlinearprogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ function get_index_constraints(nlp::NonlinearProgram; fixed_variable_treatment=M
)
end

function has_dense_hessian_callback(nlp::NonlinearProgram)
func = nlp.lag_hess!
return hasmethod(func, Tuple{AbstractMatrix{T} where T, Any, Any, Any})
end

function has_dense_jacobian_callback(nlp::NonlinearProgram)
func = nlp.con_jac!
return hasmethod(func, Tuple{AbstractMatrix{T} where T, Any})
end

function string(nlp::NonlinearProgram)
"""
Nonlinear program
Expand Down

0 comments on commit 9a33164

Please sign in to comment.