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`

?

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`

?

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

Use `delete`

to delete a variable. Variables Â· JuMP

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> 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.

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

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

So, u actually doesnâ€™t appear anywhere yet.

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

Take a read of the first post in PSA: make it easier to help you. It has some advice on how to write a good post on construct a minimal working example.

There is nothing equivalent for

`NLparameter`

right?

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> 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
```

1 Like

Actually, this is expected behavior. Use `unregister(model, :x)`

to remove the name.

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

Opened an issue to document this better: Document that delete does not call unregister Â· Issue #2589 Â· jump-dev/JuMP.jl Â· GitHub

1 Like

Please also document â€śwhyâ€ť not just â€śthatâ€ť delete does not unregister. Understanding is key here.