Skip to content

Support JuMP.@objective #5

@lassepe

Description

@lassepe

This is somewhat related to #4. I'm just creating a separate issue to make tracking a bit easier.

Currently, the use of JuMP.@objective does not seem to be supported. For example, the code

import JuMP
import SNOPT7

m = JuMP.Model(JuMP.optimizer_with_attributes(
    SNOPT7.Optimizer,
    "print_level" => 0,
    "system_information" => "yes",
))

JuMP.@variable(m, x[1:10])
JuMP.@objective(m, Min, x'*x)
JuMP.optimize!(m)

println(JuMP.value.(x))
println(JuMP.termination_status(m))

throws the following error

┌ Error: VariablePrimal not available.
└ @ SNOPT7 ~/.julia/packages/SNOPT7/tZVgh/src/MOIWrapper.jl:420
ERROR: LoadError: type Nothing has no field x
Stacktrace:
 [1] getproperty(::Nothing, ::Symbol) at ./Base.jl:33
 [2] get(::SNOPT7.Optimizer, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /home/lassepe/.julia/packages/SNOPT7/tZVgh/src/MOIWrapper.jl:422
 [3] get(::MathOptInterface.Utilities.CachingOptimizer{SNOPT7.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /home/lassepe/.julia/packages/MathOptInterface/ZJFKw/src/Utilities/cachingoptimizer.jl:605
 [4] get(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{SNOPT7.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /home/lassepe/.julia/packages/MathOptInterface/ZJFKw/src/Bridges/bridge_optimizer.jl:808
 [5] get(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /home/lassepe/.julia/packages/MathOptInterface/ZJFKw/src/Utilities/cachingoptimizer.jl:605
 [6] _moi_get_result(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::Vararg{Any,N} where N) at /home/lassepe/.julia/packages/JuMP/y5vgk/src/JuMP.jl:946
 [7] get(::JuMP.Model, ::MathOptInterface.VariablePrimal, ::JuMP.VariableRef) at /home/lassepe/.julia/packages/JuMP/y5vgk/src/JuMP.jl:976
 [8] value(::JuMP.VariableRef; result::Int64) at /home/lassepe/.julia/packages/JuMP/y5vgk/src/variables.jl:766
 [9] value at /home/lassepe/.julia/packages/JuMP/y5vgk/src/variables.jl:766 [inlined]
 [10] _broadcast_getindex_evalf at ./broadcast.jl:648 [inlined]
 [11] _broadcast_getindex at ./broadcast.jl:621 [inlined]
 [12] getindex at ./broadcast.jl:575 [inlined]
 [13] macro expansion at ./broadcast.jl:932 [inlined]
 [14] macro expansion at ./simdloop.jl:77 [inlined]
 [15] copyto! at ./broadcast.jl:931 [inlined]
 [16] copyto! at ./broadcast.jl:886 [inlined]
 [17] copy at ./broadcast.jl:862 [inlined]
 [18] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(JuMP.value),Tuple{Array{JuMP.VariableRef,1}}}) at ./broadcast.jl:837
 [19] top-level scope at /home/lassepe/worktree/research/20_inverse_games/SNOPT7Lib.jl/example.jl:15
 [20] include(::String) at ./client.jl:457
 [21] top-level scope at REPL[2]:1
in expression starting at /home/lassepe/worktree/research/20_inverse_games/SNOPT7Lib.jl/example.jl:15

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions