Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JuMP.@objective #5

Open
lassepe opened this issue Feb 3, 2021 · 1 comment · May be fixed by #7
Open

Support JuMP.@objective #5

lassepe opened this issue Feb 3, 2021 · 1 comment · May be fixed by #7

Comments

@lassepe
Copy link

lassepe commented Feb 3, 2021

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
@gnowzil gnowzil linked a pull request Feb 3, 2021 that will close this issue
@gnowzil
Copy link
Contributor

gnowzil commented Feb 3, 2021

@lassepe Do you think you could test out the branch 'test_objective'? Should allow linear or quadratic objective defined via @objective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants