# Variables declaration in JuliaPro 1.5.2-1

**URL:** <https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [October 5, 2020, 4:52pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802 "2020-10-05T16:52:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [October 5, 2020, 4:52pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/1 "2020-10-05T16:52:39Z")

</div>

When compiling `@variabel` on my model, julia displays the following message

```julia
Expected ModeloDeterministico to be a JuMP model, but it has type DataType
error(::String, ::Type{T} where T) at error.jl:42
validmodel(::Type{T} where T, ::Symbol) at macros.jl:279
top-level scope at macros.jl:284

```

Is there another way to declare variables?  
I tried to follow a macro but the message kept showing

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [October 5, 2020, 5:38pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/2 "2020-10-05T17:38:21Z")

</div>

The error message is telling you that `ModeloDeterministico` should be an _instance_ of type `JuMP.Model`, but you actually have a _type_. If you can create a [reproducible example](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) of the problem, it will be easier for us to figure out what went wrong.

Most likely, you have something like:

```julia
# This makes `ModeloDeterministico` just another name for the *type* Model
ModeloDerministico = Model

```

instead of:

```julia
# This actually creates a new *instance* of a `Model`
ModeloDerministico = Model()

```

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [October 5, 2020, 7:34pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/4 "2020-10-05T19:34:29Z")

</div>

```julia
using JuMP,Cbc
ModelD = Model()
ModelD = Cbc.Optimizer

a = 1:4
A = a

@variable(ModelD,b[A], lower_bound=0, Bin)

```

In the first compilation this error appeared: `In @variable(ModelD,b[A],lower_bound = 0,Bin): Unrecognized keyword argument lower_bound`

And in the second compilation this error appeared again: `Expected ModeloD to be a JuMP model, but it has type DataType`

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [October 5, 2020, 8:17pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/5 "2020-10-05T20:17:28Z")

</div>

Which version of JuMP are you using? The syntax you are using is for JuMP v0.19 and higher

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [October 5, 2020, 8:19pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/6 "2020-10-05T20:19:49Z")

</div>

> [@RaquelSantos](#):
>
> `ModelD = Cbc.Optimizer`

This line is the problem. You are making `ModelD` just an alias for the _type_ `Cbc.Optimizer`.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [October 5, 2020, 8:26pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/7 "2020-10-05T20:26:37Z")

</div>

> [@rdeits](#):
>
> This line is the problem. You are making `ModelD` just an alias for the _type_ `Cbc.Optimizer` .

Understand. I put `Cbc.Optimizer` because it was a suggestion that appeared in Julia for the compilation

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [October 5, 2020, 8:28pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/8 "2020-10-05T20:28:55Z")

</div>

@rdeits Was this the correct way?

```julia
ModelD = Model(with_optimizer(Cbc.Optimizer))

```

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [October 5, 2020, 8:29pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/9 "2020-10-05T20:29:52Z")

</div>

@blegat I’m using JuliaPro 1.5.2-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:** [October 5, 2020, 8:39pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/10 "2020-10-05T20:39:17Z")

</div>

Please read the documentation: [https://jump.dev/JuMP.jl/stable/quickstart/](https://jump.dev/JuMP.jl/stable/quickstart/)

You want `ModelD = Model(Cbc.Optimizer)`.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [October 6, 2020, 3:08pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/12 "2020-10-06T15:08:52Z")

</div>

Even though I used `ModelD = Model (Cbc.Optimizer)` the error message continues: `MethodError: no method matches Model (:: Type {Cbc.Optimizer})`

I did until the update and the package rm and add again but the error continues.

```julia
using JuMP,Cbc
ModeloD = Model()
ModeloD = Model(Cbc.Optimizer)
a = 1:4
A = a
@variable(ModeloD,b[A],lower_bound=0,Bin)

```

---

<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:** [October 6, 2020, 7:58pm UTC](https://discourse.julialang.org/t/variables-declaration-in-juliapro-1-5-2-1/47802/13 "2020-10-06T19:58:44Z")

</div>

After updating packages, you need to close Julia and re-open for the changes to take effect. You need JuMP 0.21 for `Model(Cbc.Optimizer)` to work.

Note that discourse has a search function. This question has been asked multiple times recently:

> [@ERROR: MethodError: no method matching Model](https://discourse.julialang.org/t/error-methoderror-no-method-matching-model/45699):
>
> Hello, I’m new in Julia and JuMP and I just tried to install and test JuMP but I got this error (with all solvers that I tested): julia\> Model(Gurobi.Optimizer) ERROR: MethodError: no method matching Model(::Type{Gurobi.Optimizer}) Closest candidates are: Model(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) at …

> [@Optimization errors with simple JuMP function using GLPK Optimizer](https://discourse.julialang.org/t/optimization-errors-with-simple-jump-function-using-glpk-optimizer/46652):
>
> Hello, I am a novice to Julia programming. Going though a tutorial I see myself running into this error and I am not quite sure what it means. Can someone who is an expert in JuMP and GLPK advise? Error: MethodError: no method matching Model(::Type{GLPK.Optimizer}) Code: using Interact using Plots using JuMP, GLPK # Define some input data about the test system # Maximum power output of generators const GENERATION\_MAX = [1000, 1000] # Minimum power output of generators const GENERATION\_MIN =…

> [@JuMP Stopped Working Today](https://discourse.julialang.org/t/jump-stopped-working-today/46348):
>
> Hi, I’ve been using JuMP for a project and it stopped working today after I installed Gurobi. I get ERROR: LoadError: MethodError: no method matching Model(::Type{Gurobi.Optimizer}) when I set the solver to Gurobi, but it is also doing this for Ipopt. I have tried downgrading/upgrading the package versions but the same error keeps occurring. What could be causing this? Thanks.
