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

jump

#1

In julia 0.7


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


#2

Did you checkout the master branch using ] dev JuMP?


#3

It is much better to use add Jump#master.


#4

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

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


#5

For JuMP, you probably want

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.


#6

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?