# Disassociate parameter or variable from a model in JuMP

**URL:** <https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [May 10, 2021, 5:05am UTC](https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851 "2021-05-10T05:05:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [May 10, 2021, 5:05am UTC](https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851/1 "2021-05-10T05:05:48Z")

</div>

Suppose I have associated the NLvariable `y` with the model `mod`.

Then suppose I change my mind and want to disassociate the variable `y` from `mod`.

Is there something like `unset`?

---

<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:** [May 10, 2021, 5:30am UTC](https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851/2 "2021-05-10T05:30:36Z")

</div>

Please provide a minimal working example. We don’t have the concept of an NLvariable.

Use `delete` to delete a variable. [Variables · JuMP](https://jump.dev/JuMP.jl/stable/manual/variables/#Deleting-variables)

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [May 10, 2021, 8:21am UTC](https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851/3 "2021-05-10T08:21:29Z")

</div>

Re `delete` for a variable, many thanks for quick reply. I am still confused as the number of variables is decreasing, but the Names registered in the model is not.

```julia
julia> delete(mod0,y_11)

**julia>** mod0

A JuMP Model

Maximization problem with:

Variables: 5

Objective function type: Nonlinear

Model mode: AUTOMATIC

CachingOptimizer state: EMPTY_OPTIMIZER

Solver name: Ipopt

Names registered in the model: p_1, u, y_11, y_12, y_21, y_22

**julia>** delete(mod0, u)

**julia>** mod0

A JuMP Model

Maximization problem with:

Variables: 4

Objective function type: Nonlinear

Model mode: AUTOMATIC

CachingOptimizer state: EMPTY_OPTIMIZER

Solver name: Ipopt

Names registered in the model: p_1, u, y_11, y_12, y_21, y_22 

```

There is nothing equivalent for `NLparameter` right?

Not a major one, this is for quick REPL work really.

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [May 10, 2021, 8:23am UTC](https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851/4 "2021-05-10T08:23:02Z")

</div>

Oh I see, this is probably because these variables appear in equations such as the objective etc… Got it.

Or maybe not:

My objective is

```julia
@NLobjective(mod0, Max, 1.8898*y_11^.3333*y_21^.6666)

```

So, u actually doesn’t appear anywhere yet.

```julia
@variable(mod0, u, start = 1)

```

---

<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:** [May 10, 2021, 8:11pm UTC](https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851/5 "2021-05-10T20:11:45Z")

</div>

Take a read of the first post in [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757). It has some advice on how to write a good post on construct a minimal working example.

> There is nothing equivalent for `NLparameter` right?

No. [Certain base functions on JuMP constraints not implemented for NLconstraints. · Issue #2355 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/issues/2355)

> because these variables appear in equations such as the objective

You can delete variables that appear in objectives and constraints.

> I am still confused as the number of variables is decreasing, but the Names registered in the model is not.

Looks like you found a bug 😄. I don’t know how we missed this one for so long… I’ll open an issue.

```Julia
julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @variable(model, x)
x

julia> model
A JuMP Model
Feasibility problem with:
Variable: 1
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: x

julia> delete(model, x)

julia> model[:x]
noname

julia> model
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: x

```

---

<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:** [May 10, 2021, 8:19pm UTC](https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851/6 "2021-05-10T20:19:04Z")

</div>

Actually, this is expected behavior. Use `unregister(model, :x)` to remove the name.

```nohighlight
model = Model()
@variable(model, x)
delete(model, x)
unregister(model, :x)

```

Opened an issue to document this better: [https://github.com/jump-dev/JuMP.jl/issues/2589](https://github.com/jump-dev/JuMP.jl/issues/2589)

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [May 11, 2021, 12:37am UTC](https://discourse.julialang.org/t/disassociate-parameter-or-variable-from-a-model-in-jump/60851/7 "2021-05-11T00:37:46Z")

</div>

Please also document “why” not just “that” delete does not unregister. Understanding is key here.
