# Julia 0.7 and JuMP: ERROR: cosd is not defined for type Variable

**URL:** <https://discourse.julialang.org/t/julia-0-7-and-jump-error-cosd-is-not-defined-for-type-variable/13296>\
**Category:** General Usage\
**Tags:** jump\
**Created:** [August 12, 2018, 1:50pm UTC](https://discourse.julialang.org/t/julia-0-7-and-jump-error-cosd-is-not-defined-for-type-variable/13296 "2018-08-12T13:50:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [August 12, 2018, 1:50pm UTC](https://discourse.julialang.org/t/julia-0-7-and-jump-error-cosd-is-not-defined-for-type-variable/13296/1 "2018-08-12T13:50:06Z")

</div>

In julia 0.7

```julia

julia> using JuMP

julia> m=Model()
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
WARNING: Base.ObjectIdDict is deprecated, use IdDict{Any, Any} instead.
 in module JuMP
Feasibility problem with:
 * 0 linear constraints
 * 0 variables
Solver is default solver

julia> @variable(m,x)
┌ Warning: `shift!` is deprecated, use `popfirst!` instead.
│ caller = @variable(::LineNumberNode, ::Module, ::Vararg{Any,N} where N) at macros.jl:887
└ @ JuMP ~/.julia/packages/JuMP/6aWuF/src/macros.jl:887
x

julia> @NLobjective(m,Min,cosd(x))
┌ Warning: `Array{T, 1}(m::Int) where T` is deprecated, use `Array{T, 1}(undef, m)` instead.
│ caller = ReverseDiffSparse.UserOperatorRegistry() at types.jl:72
└ @ ReverseDiffSparse ~/.julia/packages/ReverseDiffSparse/8BEQH/src/types.jl:72
ERROR: cosd is not defined for type Variable. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] cosd(::Variable) at /home/bgodard/.julia/packages/JuMP/6aWuF/src/operators.jl:597
 [3] top-level scope at /home/bgodard/.julia/packages/JuMP/6aWuF/src/parsenlp.jl:226
 [4] top-level scope at /home/bgodard/.julia/packages/JuMP/6aWuF/src/macros.jl:1157

julia> methods(cosd)
# 7 methods for generic function "cosd":
[1] cosd(::Variable) in JuMP at /home/bgodard/.julia/packages/JuMP/6aWuF/src/operators.jl:597
[2] cosd(::JuMP.GenericAffExpr{Float64,Variable}) in JuMP at /home/bgodard/.julia/packages/JuMP/6aWuF/src/operators.jl:597
[3] cosd(::JuMP.GenericQuadExpr{Float64,Variable}) in JuMP at /home/bgodard/.julia/packages/JuMP/6aWuF/src/operators.jl:597
[4] cosd(d::ForwardDiff.Dual{T,V,N} where N where V<:Real) where T in ForwardDiff at /home/bgodard/.julia/packages/ForwardDiff/2v3a4/src/dual.jl:166
[5] cosd(x::Real) in Base.Math at special/trig.jl:1049
[6] cosd(x::SparseArrays.AbstractSparseArray{#s565,#s564,1} where #s564<:Integer where #s565<:Number) in SparseArrays at deprecated.jl:53
[7] cosd(z) in Base.Math at special/trig.jl:1081

```

This used to work in 0.6

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [August 12, 2018, 2:01pm UTC](https://discourse.julialang.org/t/julia-0-7-and-jump-error-cosd-is-not-defined-for-type-variable/13296/2 "2018-08-12T14:01:10Z")

</div>

Did you checkout the master branch using `] dev JuMP`?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 12, 2018, 2:10pm UTC](https://discourse.julialang.org/t/julia-0-7-and-jump-error-cosd-is-not-defined-for-type-variable/13296/3 "2018-08-12T14:10:09Z")

</div>

> [@mohamed82008](#):
>
> Did you checkout the master branch using

It is much better to use `add Jump#master`.

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [August 12, 2018, 8:25pm UTC](https://discourse.julialang.org/t/julia-0-7-and-jump-error-cosd-is-not-defined-for-type-variable/13296/4 "2018-08-12T20:25:58Z")

</div>

With JuMP master, it accepts the NLobjective but I cannot set the solver:

```julia
julia> using JuMP

julia> setsolver
ERROR: UndefVarError: setsolver not defined

julia> using NLopt

julia> m = Model(solver=NLoptSolver(algorithm=:LD_SLSQP))
ERROR: MethodError: no method matching Model(; solver=NLoptSolver(:LD_SLSQP, NaN, 1.0e-7, NaN, 1.0e-7, nothing, 1.0e-7, 0, 0, nothing, 0, nothing, 0))
Closest candidates are:
  Model(; caching_mode, bridge_constraints) at /home/astro/.julia/packages/JuMP/ImktK/src/JuMP.jl:195 got unsupported keyword argument "solver"
  Model(::Dict{MathOptInterface.VariableIndex,MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.GreaterThan{Float64}}}, ::Dict{MathOptInterface.VariableIndex,MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.LessThan{Float64}}}, ::Dict{MathOptInterface.VariableIndex,MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.EqualTo{Float64}}}, ::Dict{MathOptInterface.VariableIndex,MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Integer}}, ::Dict{MathOptInterface.VariableIndex,MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.ZeroOne}}, ::MathOptInterface.AbstractOptimizer, ::Any, ::Any, ::Dict{Symbol,Any}, ::Int64, ::Dict{Symbol,Any}) at /home/astro/.julia/packages/JuMP/ImktK/src/JuMP.jl:136 got unsupported keyword argument "solver"
  Model(::MathOptInterface.ModelLike) at /home/astro/.julia/packages/JuMP/ImktK/src/JuMP.jl:167 got unsupported keyword argument "solver"
  ...
Stacktrace:
 [1] kwerr(::NamedTuple{(:solver,),Tuple{NLoptSolver}}, ::Type) at ./error.jl:97
 [2] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:solver,),Tuple{NLoptSolver}}, ::Type{Model}) at ./none:0
 [3] top-level scope at none:0

```

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 12, 2018, 9:33pm UTC](https://discourse.julialang.org/t/julia-0-7-and-jump-error-cosd-is-not-defined-for-type-variable/13296/5 "2018-08-12T21:33:04Z")

</div>

For JuMP, you probably want

```julia
pkg> add JuMP#release-0.18
pkg> add ReverseDiffSparse#master

```

unless you also want the backend changes and API changes (e.g., `solver` kwarg will become `optimizer`) that will be present in JuMP 0.19.

That said, I still get the same error minus the depwarns.

---

<div class="post-metadata">

**Author:** ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)\
**Post date:** [August 13, 2018, 11:50am UTC](https://discourse.julialang.org/t/julia-0-7-and-jump-error-cosd-is-not-defined-for-type-variable/13296/6 "2018-08-13T11:50:57Z")

</div>

> [@tkoolen](#):
>
> For JuMP, you probably want
> 
> ```julia
> pkg> add JuMP#release-0.18
> pkg> add ReverseDiffSparse#master
> 
> ```
> 
> unless you also want the backend changes and API changes (e.g., `solver` kwarg will become `optimizer` ) that will be present in JuMP 0.19.
> 
> That said, I still get the same error minus the depwarns.

With 0.18, I get the error that cosd is not defined for type variable.

With master, I cannot define the solver (solver or optimizer keyword is not accepted).  
Is there a documentation of the change for the new API or some examples of how to solve NLP with the new API?
