# Deleting @NLconstraint from JuMP model

**URL:** <https://discourse.julialang.org/t/deleting-nlconstraint-from-jump-model/13002>\
**Category:** Optimization (Mathematical)\
**Created:** [August 7, 2018, 6:08pm UTC](https://discourse.julialang.org/t/deleting-nlconstraint-from-jump-model/13002 "2018-08-07T18:08:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chkwon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chkwon/32/3632_2.png) [@chkwon](https://discourse.julialang.org/u/chkwon)\
**Post date:** [August 7, 2018, 6:08pm UTC](https://discourse.julialang.org/t/deleting-nlconstraint-from-jump-model/13002/1 "2018-08-07T18:08:02Z")

</div>

JuMP v0.18:

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

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

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [August 7, 2018, 9:47pm UTC](https://discourse.julialang.org/t/deleting-nlconstraint-from-jump-model/13002/2 "2018-08-07T21:47:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [August 8, 2018, 12:02am UTC](https://discourse.julialang.org/t/deleting-nlconstraint-from-jump-model/13002/3 "2018-08-08T00:02:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chkwon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chkwon/32/3632_2.png) [@chkwon](https://discourse.julialang.org/u/chkwon)\
**Post date:** [August 8, 2018, 3:19pm UTC](https://discourse.julialang.org/t/deleting-nlconstraint-from-jump-model/13002/4 "2018-08-08T15:19:59Z")

</div>

Thanks Miles and Oscar.

In [Complementarity.jl](https://github.com/chkwon/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.
