lanl-ansi / Alpine.jl

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

ERROR: KeyError: key MathOptInterface.FEASIBILITY_SENSE not found #242

Closed freemin7 closed 1 month ago

freemin7 commented 4 months ago

I have not narrowed this down to a minimal example yet.

using JuMP, SCIP

n = 8

mmm = [
[
1 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
],
[
0 0 0 0 0 0 0 0;
0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
],
[
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 1 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
],
[
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
],
[
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
],
[
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 1 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0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0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
],
[
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 1;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
]
];

lmmm = length(mmm)

#m = Model(SCIP.Optimizer);

using JuMP, Alpine, Ipopt, HiGHS, Juniper
ipopt = optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0)
highs = optimizer_with_attributes(HiGHS.Optimizer, "output_flag" => false)
juniper =  optimizer_with_attributes(
        Juniper.Optimizer,
        MOI.Silent() => true,
        "mip_solver" => highs,
        "nl_solver" => ipopt,
    )

m = Model(
    optimizer_with_attributes(
        Alpine.Optimizer,
        "nlp_solver" => ipopt,
        "mip_solver" => highs,
        "minlp_solver" => juniper
    ),
)

@variable(m,  Mat[1:n,1:n]);
@variable(m,  MatP[1:n,1:n,1:lmmm]);

@variable(m, Spa[1:n,1:n], Bin);
@variable(m, SpaS[1:n,1:n]);
@variable(m, SpaP[1:n,1:n,1:lmmm], Bin);

for l=1:lmmm
    @constraint(m, MatP[:,:,l] .== Mat*mmm[l]*(Mat'))
end

for i=1:n
    for j=1:n
        @constraint(m, SpaS[i,j] == sum([SpaP[i,j,l] for l=1:lmmm]))
        @constraint(m, SpaS[i,j] <= n*n*Spa[i,j])
        @constraint(m, 2 >= Mat[i,j])
        @constraint(m, Mat[i,j] >= -2)
    end
end

@constraint(m, sum(Spa) <= 32)
#@constraint(m, 12 <= sum(Spa))

for i=1:n
    @constraint(m, sum( Mat[i,:].*Mat[i,:] ) == 1)
end

for i=1:n
    for j=(1+i):n
        @constraint(m, sum( Mat[i,:].*Mat[j,:] ) == 0)
    end
end
#=
set_attribute(m, "constraints/countsols/collect", true)
set_attribute(m, "constraints/countsols/sollimit", 1000000)
set_attribute(m, "heuristics/subnlp/freq", -1)
=#

optimize!(m)

for l=1:lmmm
    for i=1:n
        for j=1:n
    @constraint(m, MatP[i,j,l] <= 10000000000*SpaP[i,j,l])
    @constraint(m, -10000000000*SpaP[i,j,l] <= MatP[i,j,l])
        end
    end

    optimize!(m)

    @show value.(Mat)
end

I get this error output:

Warning: -/+Inf bounds detected on at least 1536 variables. Initializing with values -/+1.0e6. This may affect global optimal values and run times.
Automatically turning OFF 'partition_scaling_factor_branch' due to the size of the problem

PROBLEM STATISTICS
  # Variables = 3008
  # Bin-Int Variables = 1472
  # Constraints = 1829
  # NL Constraints = 1444
  # Linear Constraints = 385
  # Detected convex constraints = 0
  # Detected nonlinear terms = 1120
  # Variables involved in nonlinear terms = 64
  # Potential variables for partitioning = 64
SUB-SOLVERS USED BY ALPINE
  MINLP local solver = Juniper
  MIP solver = HiGHS
ALPINE CONFIGURATION
  Alpine version = 0.5.6
  Maximum iterations (bounding MIPs) =  99
  Relative global optimality gap = 0.01%
  Partition scaling factor = 10
  Bound-tightening presolve = true
  Maximum iterations (OBBT) = 25
PRESOLVE 
  Doing local search
ERROR: KeyError: key MathOptInterface.FEASIBILITY_SENSE not found
Stacktrace:
  [1] getindex
    @ ./dict.jl:484 [inlined]
  [2] update_incumbent(m::Alpine.Optimizer, objval::Float64, sol::Vector{Float64})
    @ Alpine ~/.julia/packages/Alpine/2DP5q/src/utility.jl:119
  [3] local_solve(m::Alpine.Optimizer; presolve::Bool)
    @ Alpine ~/.julia/packages/Alpine/2DP5q/src/main_algorithm.jl:483
  [4] local_solve
    @ ~/.julia/packages/Alpine/2DP5q/src/main_algorithm.jl:390 [inlined]
  [5] presolve(m::Alpine.Optimizer)
    @ Alpine ~/.julia/packages/Alpine/2DP5q/src/main_algorithm.jl:231
  [6] optimize!(m::Alpine.Optimizer)
    @ Alpine ~/.julia/packages/Alpine/2DP5q/src/main_algorithm.jl:157
  [7] optimize!
    @ ~/.julia/packages/MathOptInterface/2rAFb/src/Bridges/bridge_optimizer.jl:380 [inlined]
  [8] optimize!
    @ ~/.julia/packages/MathOptInterface/2rAFb/src/MathOptInterface.jl:85 [inlined]
  [9] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.Bridges.LazyBridgeOptimizer{Alpine.Optimizer}, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/2rAFb/src/Utilities/cachingoptimizer.jl:316
 [10] optimize!(model::Model; ignore_optimize_hook::Bool, _differentiation_backend::MathOptInterface.Nonlinear.SparseReverseMode, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ JuMP ~/.julia/packages/JuMP/Gwn88/src/optimizer_interface.jl:457
 [11] optimize!(model::Model)
    @ JuMP ~/.julia/packages/JuMP/Gwn88/src/optimizer_interface.jl:409
 [12] top-level scope
    @ ./REPL[92]:9
odow commented 4 months ago

I have not narrowed this down to a minimal example yet

You don't have an objective function.

But this is still a bug.

harshangrjn commented 3 months ago

From a global optimization perspective, a model without an objective is not relevant for Alpine, as it can always be solved to feasibility using any local solver. But, the error message can be better.

freemin7 commented 3 months ago

I am not familiar with the code base but in principle i would be highly surprised if Alpine couldn't also help a local solver find solutions faster on difficult feasibility problems by excluding parts of the search space based on relaxations and focusing the non linear solver on regions of suspected feasibility.