I have an NLP model nlp_model, and I want to evaluate its objective function / constraints at a point x. I first create an NLPEvaluator as mpb_model = JuMP.NLPEvaluator(nlp_model) and then try to query it with MathProgBase.eval_f(mpb_model, x), but I get an Undefined Reference error.
I can first initialize the interface with MathProgBase.initialize(mpb_model, [:Grad]) and then call eval_f fine, but this calls the JIT warmup on computing the gradient. To avoid this, I added a :Func option to the features_available function so that initialize performs the initialization without a gradient call.
Is there a better way to ask for the objective function / constraints?
Why to you need to use MathProgBase? NLPModels have their own functions to compute values. To compute the objective you should use obj(nlp_model, x). To compute the constraints use cons(nlp_model, x).
If you need, for some reason, to convert the NLPModel to a MathProgBase one, you should use mpb_model = NLPtoMPB(nlp_model, solver). I am not sure if the solver parameter is required. I believe not.
You can pass an empty Symbol vector to initialize if you don’t need the gradients. It seems to work here. I hope it avoids the JIT for the gradient as you did not ask for it. Initialize with something like:
That said, you may have luck defining an NLPModel from NLPModels.jl and evaluating it as @pjssilva indicated. If you need to pass it to a NLP solver later, you can convert it to a MathProgBase model. We’re taking care of the evaluator under the hood.