Deleting @NLconstraint from JuMP model

JuMP v0.18:

When I want to delete all @NLconstraints added to the JuMP model, is it safe and sufficient to do the following?

m.nlpdata.nlconstr = Array{JuMP.GenericRangeConstraint{JuMP.NonlinearExprData},1}(0)

I think the correct answer is probably “rebuild the model from scratch without them.”

I’m not sure re your suggestion. @mlubin might have to weigh in here.

The code was written assuming that constraints would not be deleted, so no, I would guess that this is not safe. A more precise answer would require a lot of digging and testing of the code. What’s more likely to be safe is m.nlpdata = nothing to clear out all NLP-related data from the model.

Thanks Miles and Oscar.

In Complementarity.jl, there are no other constraints in the model (neither @constraint nor @NLconstraint). I only add some dummy @NLconstraints to obtain Jacobian programmatically. I wanted to delete those dummy @NLconstraints after using them. It looks like the above mentioned method works okay.

I cannot set m.nlpdata = nothing, because I have some @NLexpressions in the model.