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

Failing on problems with no objective function #195

Closed
rb004f opened this issue Jul 24, 2020 · 11 comments · Fixed by #196
Closed

Failing on problems with no objective function #195

rb004f opened this issue Jul 24, 2020 · 11 comments · Fixed by #196

Comments

@rb004f
Copy link

rb004f commented Jul 24, 2020

I have a case which appears to fail when a problem has no objective function and the feasibility pump is executed. I don't have a simple problem example, but this script should reproduce it using the master branch of Gas Models

using GasModels

import Juniper
import Cbc
import Ipopt
import JuMP


ipopt_solver = JuMP.optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0, "sb" => "yes", "max_iter" => 50000)
cbc_solver = JuMP.optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
juniper_solver = JuMP.optimizer_with_attributes(Juniper.Optimizer,
    "nl_solver" => ipopt_solver,
    "mip_solver" => cbc_solver, "log_levels" => [])

result = run_gf("../../test/data/matgas/gaslib-40-E.m", MISOCPGasModel, juniper_solver)

The file gaslib-40-E.m is in the GasModels repository.

The specific exception error is

ERROR: LoadError: TypeError: in ObjectiveFunction, in F, expected F<:MathOptInterface.AbstractScalarFunction, got Type{Nothing}
Stacktrace:
 [1] #generate_real_nlp#24(::Bool, ::Function, ::Juniper.Optimizer, ::Juniper.JuniperProblem, ::Array{Float64,1}) at C:\Users\210117\.julia\packages\Juniper\Hm6I1\src\fpump.jl:216
 [2] generate_real_nlp at C:\Users\210117\.julia\packages\Juniper\Hm6I1\src\fpump.jl:181 [inlined]
 [3] fpump(::Juniper.Optimizer, ::Juniper.JuniperProblem) at C:\Users\210117\.julia\packages\Juniper\Hm6I1\src\fpump.jl:416
 [4] optimize!(::Juniper.Optimizer) at C:\Users\210117\.julia\packages\Juniper\Hm6I1\src\MOI_wrapper\MOI_wrapper.jl:413
 [5] optimize!(::MathOptInterface.Bridges.LazyBridgeOptimizer{Juniper.Optimizer}) at C:\Users\210117\.julia\packages\MathOptInterface\RmalA\src\Bridges\bridge_optimizer.jl:239
 [6] optimize!(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}) at C:\Users\210117\.julia\packages\MathOptInterface\RmalA\src\Utilities\cachingoptimizer.jl:189
 [7] #optimize!#97(::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::JuMP.Model, ::Nothing) at C:\Users\210117\.julia\packages\JuMP\YXK4e\src\optimizer_interface.jl:131
 [8] optimize! at C:\Users\210117\.julia\packages\JuMP\YXK4e\src\optimizer_interface.jl:107 [inlined] (repeats 2 times)
 [9] macro expansion at .\util.jl:289 [inlined]
 [10] #optimize_model!#21(::MathOptInterface.OptimizerWithAttributes, ::Array{Function,1}, ::Function, ::MISOCPGasModel) at C:\Users\210117\Documents\GitHub\InfrastructureModels.jl\src\core\base.jl:232
 [11] (::getfield(InfrastructureModels, Symbol("#kw##optimize_model!")))(::NamedTuple{(:optimizer, :solution_processors),Tuple{MathOptInterface.OptimizerWithAttributes,Array{Function,1}}}, ::typeof(optimize_model!), ::MISOCPGasModel) at .\none:0
 [12] #run_model#71(::Array{Any,1}, ::Array{Function,1}, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Dict{String,Any}, ::Type, ::MathOptInterface.OptimizerWithAttributes, ::Function) at C:\Users\210117\Documents\GitHub\GasModels.jl\src\core\base.jl:19
 [13] (::getfield(GasModels, Symbol("#kw##run_model")))(::NamedTuple{(:ref_extensions, :solution_processors),Tuple{Array{Any,1},Array{Function,1}}}, ::typeof(run_model), ::Dict{String,Any}, ::Type, ::MathOptInterface.OptimizerWithAttributes, ::Function) at .\none:0
 [14] #run_model#70(::Array{Any,1}, ::Array{Function,1}, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::String, ::Type, ::MathOptInterface.OptimizerWithAttributes, ::Function) at C:\Users\210117\Documents\GitHub\GasModels.jl\src\core\base.jl:13
 [15] (::getfield(GasModels, Symbol("#kw##run_model")))(::NamedTuple{(:solution_processors,),Tuple{Array{Function,1}}}, ::typeof(run_model), ::String, ::Type, ::MathOptInterface.OptimizerWithAttributes, ::Function) at .\none:0       
 [16] #run_gf#697(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::String, ::Type, ::MathOptInterface.OptimizerWithAttributes) at GasModels.jl\src\prob\gf.jl:5    
 [17] run_gf(::String, ::Type, ::MathOptInterface.OptimizerWithAttributes) at GasModels.jl\src\prob\gf.jl:5
 [18] top-level scope at none:0
 [19] include at .\boot.jl:326 [inlined]
 [20] include_relative(::Module, ::String) at .\loading.jl:1038
 [21] include(::Module, ::String) at .\sysimg.jl:29
 [22] include(::String) at .\client.jl:403
 [23] top-level scope at none:0

it appears to be a typing error

@Wikunia
Copy link
Member

Wikunia commented Jul 24, 2020

Did you have a deja vu moment? @rb004f #145 😄
I'll have a look. Thanks for opening the issue!

@rb004f
Copy link
Author

rb004f commented Jul 24, 2020

Apparently!

@ccoffrin
Copy link
Member

@Wikunia, if we can understand the core issue it might make a good test to add to MINLP Tests?

@Wikunia
Copy link
Member

Wikunia commented Jul 24, 2020

The solving process is quite slow but it solves the issue without raising an error for me. I try to create a more minimal example.
I assume you're using the latest version of Juniper @rb004f ?

@Wikunia
Copy link
Member

Wikunia commented Jul 24, 2020

Oh maybe I need the master branch of GasModels. I just copied the model file...

@Wikunia
Copy link
Member

Wikunia commented Jul 24, 2020

Okay I found the error:
If the objective is non-linear it is stored in optimizer.nlp_data if it's linear it is in optimizer.objective which is nothing if there is no objective. I only worked with either linear or non-linear and not with no objective.
Bugfix coming soon.

@rb004f
Copy link
Author

rb004f commented Jul 24, 2020

Fantastic! Thanks.

@ccoffrin
Copy link
Member

That sounds like a case that should be tested in MINLP Tests, can you also propose a PR there?

@Wikunia
Copy link
Member

Wikunia commented Jul 24, 2020

Sure I'll have a look @ccoffrin

@rb004f
Copy link
Author

rb004f commented Jul 24, 2020

Once you have a fix, it would be great to push a new version. I have a unit test in GasModels I'd like to activate once juniper is updated.

@Wikunia
Copy link
Member

Wikunia commented Jul 24, 2020

Should be shortly available as v0.6.4
Sorry the test cases always take too long :/

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.

3 participants