lanl-ansi / Alpine.jl

A Julia/JuMP-based Global Optimization Solver for Non-convex Programs
https://lanl-ansi.github.io/Alpine.jl/latest/
Other
243 stars 39 forks source link

Alpine LoadError #122

Closed samiit closed 5 years ago

samiit commented 5 years ago

I just added Alpine to my fresh installation of Julia 1.1.1 but when trying to load it, I get error:

julia> using Alpine
[ Info: Precompiling Alpine [07493b3f-dabb-5b16-a503-4139292d7dd4]
ERROR: LoadError: LoadError: UndefVarError: Variable not defined
Stacktrace:
 [1] getproperty(::Module, ::Symbol) at ./sysimg.jl:13
 [2] top-level scope at none:0
 [3] include at ./boot.jl:326 [inlined]
 [4] include_relative(::Module, ::String) at ./loading.jl:1038
 [5] include at ./sysimg.jl:29 [inlined]
 [6] include(::String) at /home/sam/.julia/packages/Alpine/k3g7z/src/Alpine.jl:3
 [7] top-level scope at none:0
 [8] include at ./boot.jl:326 [inlined]
 [9] include_relative(::Module, ::String) at ./loading.jl:1038
 [10] include(::Module, ::String) at ./sysimg.jl:29
 [11] top-level scope at none:2
 [12] eval at ./boot.jl:328 [inlined]
 [13] eval(::Expr) at ./client.jl:404
 [14] top-level scope at ./none:3
in expression starting at /home/sam/.julia/packages/Alpine/k3g7z/src/tmc.jl:203
in expression starting at /home/sam/.julia/packages/Alpine/k3g7z/src/Alpine.jl:57
ERROR: Failed to precompile Alpine [07493b3f-dabb-5b16-a503-4139292d7dd4] to /home/sam/.julia/compiled/v1.1/Alpine/TRSJF.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1197
 [3] _require(::Base.PkgId) at ./loading.jl:960
 [4] require(::Base.PkgId) at ./loading.jl:858
 [5] require(::Module, ::Symbol) at ./loading.jl:853

Does Alpine have issues with the latest Julia (v1.1.1)? I don't get this error while using Julia 0.6.1!

Thanks,

Sam

harshangrjn commented 5 years ago

Alpine is not supported yet to be compatible with JuMP 0.19+. Anything under JuMP 0.18.5 and Julia 1.0+ works fine. Install JuMP using the command 'Pkg.add(JuMP@v0.18.5)'. Let us know if you have issues.

harshangrjn commented 5 years ago

@kaarthiksundar Any inputs?

kaarthiksundar commented 5 years ago

What you said is correct.

ccoffrin commented 5 years ago

What i don’t get is how JuMP v0.19 was installed. The package requirements should prevent this.

On Fri, Jun 28, 2019 at 11:49 AM Kaarthik Sundar notifications@github.com wrote:

What you said is correct.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lanl-ansi/Alpine.jl/issues/122?email_source=notifications&email_token=AAIN5KQSUAI4H7YBTGKAWITP4ZFMBA5CNFSM4H4DBU4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY2X2DQ#issuecomment-506821902, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIN5KSGSIGMN6RKRI4US7TP4ZFMBANCNFSM4H4DBU4A .

harshangrjn commented 5 years ago

As @samiit says, he is using JuMP <= v0.18.5 in Julia 0.6.1, in which Alpine runs. But in Julia 1.1.1, JuMP was probably installed before Alpine, and hence v 0.19?

kaarthiksundar commented 5 years ago

@ccoffrin I have experienced similar issues where the package manager do not do a downgrade automatically in Jump is installed first. Also it was never consistent. Sometimes it works, sometimes it doesn’t. Harsha’s suggestion will help narrow down the issue.

ccoffrin commented 5 years ago

Sounds odd. Assuming the environment is clean, if you start by installing Alpine, it should pull down JuMP v0.18. If you first install JuMp v0.19, then installing Alpine should throw an error that the version requirements cannot be met.

samiit commented 5 years ago

While it is true that I don't get the load error while using JuMP <=18.5 (in Julia 0.6.1), I get other errors while solving an example model. I can only use Cbc and Ipopt like below.

using Alpine
using JuMP
using Cbc, Ipopt

m = Model()
@variable(m, 0 <= x <= 10 )
@variable(m, 0 <= y <= 5 )
@objective(m, Max, 5x + 9y )
@NLconstraint(m, (x - 5)^2 + (y-3)^2 >= 1) # non-convex constraint
setsolver(m, AlpineSolver(nlp_solver=IpoptSolver(print_level=0), mip_solver=CbcSolver()))
print(m)
status = solve(m)

And I get error as:

ERROR: Solver does not support quadratic constraints
Stacktrace:
 [1] addQuadratics(::JuMP.Model) at /home/sam/.julia/v0.6/JuMP/src/solvers.jl:469
 [2] #build#136(::Bool, ::Bool, ::JuMP.ProblemTraits, ::Function, ::JuMP.Model) at /home/sam/.julia/v0.6/JuMP/src/solvers.jl:374
 [3] (::JuMP.#kw##build)(::Array{Any,1}, ::JuMP.#build, ::JuMP.Model) at ./<missing>:0
 [4] #solve#133(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /home/sam/.julia/v0.6/JuMP/src/solvers.jl:168
 [5] (::JuMP.#kw##solve)(::Array{Any,1}, ::JuMP.#solve, ::JuMP.Model) at ./<missing>:0
 [6] #solve_bound_tightening_model#208(::Array{Any,1}, ::Function, ::Alpine.AlpineNonlinearModel) at /home/sam/.julia/v0.6/Alpine/src/presolve.jl:226
 [7] #minmax_bound_tightening#206(::Bool, ::Float64, ::Array{Any,1}, ::Function, ::Alpine.AlpineNonlinearModel) at /home/sam/.julia/v0.6/Alpine/src/presolve.jl:101
 [8] (::Alpine.#kw##minmax_bound_tightening)(::Array{Any,1}, ::Alpine.#minmax_bound_tightening, ::Alpine.AlpineNonlinearModel) at ./<missing>:0
 [9] #bound_tightening#205(::Bool, ::Array{Any,1}, ::Function, ::Alpine.AlpineNonlinearModel) at /home/sam/.julia/v0.6/Alpine/src/presolve.jl:20
 [10] (::Alpine.#kw##bound_tightening)(::Array{Any,1}, ::Alpine.#bound_tightening, ::Alpine.AlpineNonlinearModel) at ./<missing>:0
 [11] presolve(::Alpine.AlpineNonlinearModel) at /home/sam/.julia/v0.6/Alpine/src/algorithm.jl:84
 [12] optimize!(::Alpine.AlpineNonlinearModel) at /home/sam/.julia/v0.6/Alpine/src/algorithm.jl:9
 [13] #solvenlp#182(::Bool, ::Function, ::JuMP.Model, ::JuMP.ProblemTraits) at /home/sam/.julia/v0.6/JuMP/src/nlp.jl:1267
 [14] (::JuMP.#kw##solvenlp)(::Array{Any,1}, ::JuMP.#solvenlp, ::JuMP.Model, ::JuMP.ProblemTraits) at ./<missing>:0
 [15] #solve#133(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /home/sam/.julia/v0.6/JuMP/src/solvers.jl:172
 [16] solve(::JuMP.Model) at /home/sam/.julia/v0.6/JuMP/src/solvers.jl:150

Any suggestions how I should code a simple linear objective and a non-convex constraint?

kaarthiksundar commented 5 years ago

@samiit This is (as the error suggests) an issue with Cbc. Cbc solver does not support quadratic objective or constraints. Please use CPLEX or Gurobi and this error should not pop up. If that is not available, please use Pajarito or Pavito as the mip_solver and it should work fine.

harshangrjn commented 5 years ago

@samiit For the problem you have posted, isn't the global optimum trivial, which is at (x=10, y=5) and optimum = 95? This is because the variable bounds entirely contain the ellipse constraint you have mentioned and that the objective is linear, optimum has to be an extreme point.

samiit commented 5 years ago

@harshangrjn Yes the problem is trivial. It was something I just cooked up quick to test how Alpine can be put to use with free and open-source solvers. The real problem is to fit as many circles in a rectangular box and the constraints are naturally non-convex. I tried hard if there is any chance to make it convex but to no avail (any hints are welcome) so ended up at your impressive talk on Alpine. Thanks.

Thank you @kaarthiksundar to point me to the limitation of Cbc. I used Pavito and now it worked.

samiit commented 5 years ago

Just in case it helps someone else, the following code worked for me (cooked up example; you would need to add the package Pavito with Pkg.add("Pavito"):

using Alpine
using JuMP
using Cbc, Ipopt, Pavito

pavito_solver=PavitoSolver(mip_solver=CbcSolver(logLevel=0), cont_solver=IpoptSolver(print_level=0), mip_solver_drives=false, log_level=0)

m = Model(solver = AlpineSolver(nlp_solver=IpoptSolver(print_level=0), mip_solver=pavito_solver))
@variable(m, 0 <= x <= 10 )
@variable(m, 0 <= y <= 5 )
@objective(m, Max, 5x + 9y )
@NLconstraint(m, (x - 5)^2 + (y-3)^2 >= 1) # non-convex constraint
print(m)
status = solve(m)
println("Objective value: ", getobjectivevalue(m))
println("x = ", getvalue(x))
println("y = ", getvalue(y))
harshangrjn commented 5 years ago

Thanks @samiit! I will add this into the Alpine's documentation.

samiit commented 5 years ago

I updated the example, so that it is not so trivial and is worth to be in the documentation. I updated Alpine to 0.1.9 (of course, JuMP 0.18.5) while using Julia 1.1

I don't fully grasp though why there is a separate requirement for mip_solver and minlp_solver (I'm using Pavito for both, in the example below, but I found another issue that you addressed, you'd proposed Juniper for minlp_solver).

I mean, as an end-user I would have thought that mip_solver for Alpine should expect a mixed-integer linear solver like Cbc!

using Alpine
using JuMP
using Cbc, Ipopt, Pavito
#using Juniper

pavito_solver=PavitoSolver(mip_solver=CbcSolver(logLevel=0), 
                         cont_solver=IpoptSolver(print_level=0), 
                         mip_solver_drives=false, log_level=0)
#juniper_solver=JuniperSolver(IpoptSolver(print_level=0,sb="yes"))

m = Model(solver = AlpineSolver(presolve_bt=0, 
                        nlp_solver = IpoptSolver(print_level=0, sb="yes"), 
                        mip_solver=pavito_solver, minlp_solver = pavito_solver))#minlp_solver = juniper_solver))

@variable(m, 0 <= x <= 10 )
@variable(m, 0 <= y <= 5 )
@variable(m, z, Bin )

@objective(m, Max, 5x + 9y )
@NLconstraint(m, z*(x - 9)^2 + (y-3)^2 >= 9) # non-convex constraint
print(m)

status = solve(m)

println("Objective value: ", getobjectivevalue(m))
println("x = ", getvalue(x))
println("y = ", getvalue(y))
println("z = ", getvalue(z))
harshangrjn commented 5 years ago

minlp_solver is to be able to (hopefully quickly) solve the given non-convex MINLP to local optimality, without any global guarantees, which is what Juniper/Bonmin is meant for.

mip_solver is somewhat an overloaded term in Alpine. But the main purpose of mip_solver is to solve convex MIPs. If the MIP being solved after variable partitioning is linear, any solver such as CBC (including Gurobi and Cplex) can be used in Alpine. But, if the MIP being solved is convex but nonlinear, CBC can't be used as explained earlier. Hence, Pavito is an open-source option. For example, if the given nonconvex MINLP/NLP contains quadratic/quartic-type monomials, then the result MIP is nonlinear but convex (which is also the case in the example you shared). Else if the given nonconvex MINLP/NLP is bilinear/multilinear, then the resulting MIP is linear.

That said, we are currently working on outer-approximating convex MIPs too in Alpine with linear cuts, after which CBC itself can be used as a mip_solver.

Hope this answers your question.

samiit commented 5 years ago

Thanks Harsha.

samiit commented 5 years ago

I am writing after quite some time, since I finally managed to make Alpine work for my problem and am getting global optimum solutions. I just thought to give a suggestion to users who attempt such problems. A trick that worked for me was to avoid linearizing non-linear constraints through Big-M method.

I tried for quite some time using Alpine to convert a non-linear constraint involving two binary variables' product on the RHS as k x1 x2, into a linear one (e.g., k + M*(x1 + x2 - 2)). While it is a good idea if we want to use a linear solver, I found that while using Alpine, I got a global solution by leaving the non-linear constraint as it is. In fact while using the linear method (using Big-M), Alpine giving an error (I'm only copying the the last part of the error message):

====================================================================================================
UPPER-BOUNDING ITERATIONS 

| Iter   | Incumbent       | Best Incumbent      | Upper Bound        | Gap (%)         | Time      
Support for general integer problem is current limited...

Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] #amp_post_vars#206(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Alpine.AlpineNonlinearModel) at /home/sam/.julia/packages/Alpine/IFj1c/src/amp.jl:99
 [3] amp_post_vars at /home/sam/.julia/packages/Alpine/IFj1c/src/amp.jl:79 [inlined]
 [4] #create_bounding_mip#204(::Nothing, ::Function, ::Alpine.AlpineNonlinearModel) at /home/sam/.julia/packages/Alpine/IFj1c/src/amp.jl:43
 [5] create_bounding_mip at /home/sam/.julia/packages/Alpine/IFj1c/src/amp.jl:38 [inlined]
 [6] global_solve(::Alpine.AlpineNonlinearModel) at /home/sam/.julia/packages/Alpine/IFj1c/src/algorithm.jl:33
 [7] optimize!(::Alpine.AlpineNonlinearModel) at /home/sam/.julia/packages/Alpine/IFj1c/src/algorithm.jl:10
 [8] #solvenlp#155(::Bool, ::Function, ::Model, ::JuMP.ProblemTraits) at /home/sam/.julia/packages/JuMP/PbnIJ/src/nlp.jl:1267
 [9] #solvenlp at ./none:0 [inlined]
 [10] #solve#120(::Bool, ::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Model) at /home/sam/.julia/packages/JuMP/PbnIJ/src/solvers.jl:172
 [11] solve(::Model) at /home/sam/.julia/packages/JuMP/PbnIJ/src/solvers.jl:150
 [12] top-level scope at util.jl:156
 [13] top-level scope at In[52]:1
harshangrjn commented 5 years ago

@samiit Its not clear why this error is appearing for you. If you share the actual formulation you are trying to solve, we can look at it.

Regarding the big-M linearization, the whole purpose of Alpine to be able to handle the nonlinear terms in multilinear forms as it is. So you do not have to reformulate it, as Alpine would anyway do it for you.

samiit commented 5 years ago

Thanks @harshangrjn for your quick response. I am attaching the code that I've written which is giving this error.

CirclePackingSmall_Alpine.txt