tkoolen / Parametron.jl

Efficiently solving instances of a parameterized family of (possibly mixed-integer) linear/quadratic optimization problems in Julia
Other
73 stars 7 forks source link

A few more MethodErrors #29

Closed rdeits closed 6 years ago

rdeits commented 6 years ago

Trying to constrain a scalar variable causes a few different errors:

optimizer = OSQP.MathOptInterfaceOSQP.OSQPOptimizer()
model = Model(optimizer)
x = Variable(model)
@constraint model x >= 0
solve!(model)
MethodError: no method matching length(::SimpleQP.Functions.AffineFunction{Int64})
Closest candidates are:
  length(::SimpleVector) at essentials.jl:256
  length(::Base.MethodList) at reflection.jl:558
  length(::MethodTable) at reflection.jl:634
  ...

Stacktrace:
 [1] add_nonnegative_constraint!(::SimpleQP.Model{Float64,OSQP.MathOptInterfaceOSQP.OSQPOptimizer}, ::SimpleQP.LazyExpression{FunctionWrappers.FunctionWrapper{SimpleQP.Functions.AffineFunction{Int64},Tuple{}},Tuple{}}) at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/model.jl:85

Trying to wrap the that scalar as a vector causes a different error:

@constraint model [x] >= 0
solve!(model)
MethodError: no method matching vecsubtract!(::Array{SimpleQP.Functions.AffineFunction{Int64},1}, ::Array{SimpleQP.Functions.Variable,1}, ::Int64)
Closest candidates are:
  vecsubtract!(::AbstractArray{SimpleQP.Functions.AffineFunction{T},1}, ::AbstractArray{T,1} where T, ::AbstractArray{T,1} where T) where T at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/functions.jl:419

Stacktrace:
 [1] macro expansion at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:20 [inlined]
 [2] evalexpr at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:17 [inlined]
 [3] LazyExpression at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:14 [inlined]
 [4] wrap(::SimpleQP.LazyExpression{SimpleQP.Functions.#vecsubtract!,Tuple{Array{SimpleQP.Functions.AffineFunction{Int64},1},SimpleQP.LazyExpression{FunctionWrappers.FunctionWrapper{Array{SimpleQP.Functions.Variable,1},Tuple{}},Tuple{}},Int64}}) at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:146

and wrapping both x and 0 produces a conversion error:

@constraint model [x] >= [0]
solve!(model)
MethodError: Cannot `convert` an object of type SimpleQP.Functions.AffineFunction{Int64} to an object of type SimpleQP.Functions.AffineFunction{Float64}
This may have arisen from a call to the constructor SimpleQP.Functions.AffineFunction{Float64}(...),
since type constructors fall back to convert methods.

Stacktrace:
 [1] copy!(::IndexLinear, ::Array{SimpleQP.Functions.AffineFunction{Float64},1}, ::IndexLinear, ::Array{SimpleQP.Functions.AffineFunction{Int64},1}) at ./abstractarray.jl:656
 [2] convert(::Type{Array{SimpleQP.Functions.AffineFunction{Float64},1}}, ::Array{SimpleQP.Functions.AffineFunction{Int64},1}) at ./array.jl:368
 [3] macro expansion at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:20 [inlined]
 [4] evalexpr at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:17 [inlined]
 [5] LazyExpression at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:14 [inlined]
 [6] optimize(::SimpleQP.LazyExpression{Base.#convert,Tuple{SimpleQP.LazyExpression{FunctionWrappers.FunctionWrapper{DataType,Tuple{}},Tuple{}},SimpleQP.LazyExpression{FunctionWrappers.FunctionWrapper{Array{SimpleQP.Functions.AffineFunction{Int64},1},Tuple{}},Tuple{}}}}, ::Type{T} where T, ::Type{Array{SimpleQP.Functions.AffineFunction{Int64},1}}) at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:135
 [7] optimize_toplevel(::SimpleQP.LazyExpression{Base.#convert,Tuple{SimpleQP.LazyExpression{FunctionWrappers.FunctionWrapper{DataType,Tuple{}},Tuple{}},SimpleQP.LazyExpression{FunctionWrappers.FunctionWrapper{Array{SimpleQP.Functions.AffineFunction{Int64},1},Tuple{}},Tuple{}}}}) at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/lazyexpression.jl:55
 [8] addconstraint!(::SimpleQP.Model{Float64,OSQP.MathOptInterfaceOSQP.OSQPOptimizer}, ::SimpleQP.LazyExpression{FunctionWrappers.FunctionWrapper{Array{SimpleQP.Functions.AffineFunction{Int64},1},Tuple{}},Tuple{}}, ::MathOptInterface.Nonnegatives) at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/model.jl:77
 [9] add_nonnegative_constraint!(::SimpleQP.Model{Float64,OSQP.MathOptInterfaceOSQP.OSQPOptimizer}, ::SimpleQP.LazyExpression{FunctionWrappers.FunctionWrapper{Array{SimpleQP.Functions.AffineFunction{Int64},1},Tuple{}},Tuple{}}) at /home/rdeits/locomotion/explorations/simple-qp-miqp/packages/v0.6/SimpleQP/src/model.jl:85
tkoolen commented 6 years ago

Scalar constraints:

https://github.com/tkoolen/SimpleQP.jl/blob/f78aed61733d4d950afb8807176a54708e6e4b80/src/model.jl#L11

For @constraint model [x] >= [0], that's partly #30 as you noticed, but we also need to do a better job with promotion of coefficient types.

tkoolen commented 6 years ago

I opened https://github.com/tkoolen/SimpleQP.jl/issues/35 (better than the random comment).