plasmo-dev / Plasmo.jl

A Platform for Scalable Modeling and Optimization
Other
150 stars 21 forks source link

Plasmo.set_model() no longer appears to work #39

Closed etatara closed 3 years ago

etatara commented 3 years ago

Hi Jordan,

Thanks for you great work in moving Plasmo forward! I've updated to Plasmo v.0.4 and my existing model that worked fine in 0.3 is throwing errors on the optimize!(graph) call. It seems to be due to using Plasmo.set_model() as I can reproduce this error in the optigraph_4_nodes.jl example,e g. by using this form:

m = Model()

@variable(m,0 <= x <= 2)
@variable(m,0 <= y <= 3)
@variable(m, 0 <= z <= 2)
@constraint(m,x+y+z >= 4)
@objective(m,Min,y)

Plasmo.set_model(nodes[1], m)

it throws the following error:

 include("optigraph_4_nodes.jl")
ERROR: LoadError: type CachingOptimizer has no field optimizers
Stacktrace:
 [1] getproperty(x::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, f::Symbol)
   @ Base ./Base.jl:33
 [2] _aggregate_backends!(graph::OptiGraph)
   @ Plasmo ~/julia-1.6.2/share/julia/packages/Plasmo/djSWE/src/optimizer_interface.jl:25
 [3] _moi_optimize!(graph::OptiGraph)
   @ Plasmo ~/julia-1.6.2/share/julia/packages/Plasmo/djSWE/src/optimizer_interface.jl:258
 [4] optimize!(graph::OptiGraph; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Plasmo ~/julia-1.6.2/share/julia/packages/Plasmo/djSWE/src/optimizer_interface.jl:248
 [5] optimize!(graph::OptiGraph)
   @ Plasmo ~/julia-1.6.2/share/julia/packages/Plasmo/djSWE/src/optimizer_interface.jl:227
 [6] top-level scope
   @ /mnt/e/ANL/Projects/NG_Modeling/NGTransient/examples/optigraph_4_nodes.jl:44
 [7] include(fname::String)
   @ Base.MainInclude ./client.jl:444
 [8] top-level scope
   @ REPL[1]:1
in expression starting at .../optigraph_4_nodes.jl:44

caused by: ArgumentError: ModelLike of type Ipopt.Optimizer does not support accessing the attribute Plasmo.OptiGraphOptimizeHook()
Stacktrace:
 [1] get_fallback(::Ipopt.Optimizer, ::Plasmo.OptiGraphOptimizeHook)
   @ MathOptInterface ~/julia-1.6.2/share/julia/packages/MathOptInterface/YDdD3/src/attributes.jl:296
 [2] get(::Ipopt.Optimizer, ::Plasmo.OptiGraphOptimizeHook)
   @ MathOptInterface ~/julia-1.6.2/share/julia/packages/MathOptInterface/YDdD3/src/attributes.jl:293
 [3] get(b::MathOptInterface.Bridges.LazyBridgeOptimizer{Ipopt.Optimizer}, attr::Plasmo.OptiGraphOptimizeHook)
   @ MathOptInterface.Bridges ~/julia-1.6.2/share/julia/packages/MathOptInterface/YDdD3/src/Bridges/bridge_optimizer.jl:804
 [4] get(m::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, attr::MathOptInterface.Utilities.AttributeFromOptimizer{Plasmo.OptiGraphOptimizeHook})
   @ MathOptInterface.Utilities ~/julia-1.6.2/share/julia/packages/MathOptInterface/YDdD3/src/Utilities/cachingoptimizer.jl:890
 [5] optimize!(graph::OptiGraph; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Plasmo ~/julia-1.6.2/share/julia/packages/Plasmo/djSWE/src/optimizer_interface.jl:241
 [6] optimize!(graph::OptiGraph)
   @ Plasmo ~/julia-1.6.2/share/julia/packages/Plasmo/djSWE/src/optimizer_interface.jl:227
 [7] top-level scope
   @ .../optigraph_4_nodes.jl:44
 [8] include(fname::String)
   @ Base.MainInclude ./client.jl:444
 [9] top-level scope
   @ REPL[1]:1

Is the Plasmo.set_model() being deprecated, or is there an bug in 0.4? I'd appreciate your suggestion on how to best to update my model to verion 0.4, if that involves simply passing the optinode objects to the JuMP macros I can do that but wanted to avoid re-writing lots of code if there is another way!

Eric

jalving commented 3 years ago

Hey @etatara. The set_model function should still work, and the associated test seems to pass. As you said, you can always create an OptiNode instead of a JuMP.Model and use the same macros, but you shouldn't have to re-write your code since your original approach is supposed to be supported. This is definitely a bug. I'll take a look in the next couple days.

jalving commented 3 years ago

Alright @etatara , this should be fixed by PR #40. Keep in mind, It only works if you use set_model before you call optimize!. It would be a bit harder to support incremental updates using set_model, but you can still create the initial model this way and modify the optinodes afterwards.