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

Assertion error on CPLEX callbacks #312

Closed
matbesancon opened this issue Aug 9, 2020 · 9 comments · Fixed by #316
Closed

Assertion error on CPLEX callbacks #312

matbesancon opened this issue Aug 9, 2020 · 9 comments · Fixed by #316

Comments

@matbesancon
Copy link
Contributor

matbesancon commented Aug 9, 2020

I got the error on two distinct Debian machines. I am on CPLEX 12.08, which may cause the error?

ERROR: LoadError: TypeError: in typeassert, expected Tuple{CPLEX.Model,Function}, got a value of type Core.Compiler.UseRef
Stacktrace:
 [1] callback_wrapper(::Ptr{Nothing}, ::Int64, ::Ptr{Nothing}) at /home/mbesanco/.julia/packages/CPLEX/Hxpuk/src/cpx_generic_callbacks.jl:15
 [2] optimize! at /home/mbesanco/.julia/packages/CPLEX/Hxpuk/src/cpx_solve.jl:7 [inlined]
 [3] optimize!(::CPLEX.Optimizer) at /home/mbesanco/.julia/packages/CPLEX/Hxpuk/src/MOI/MOI_wrapper.jl:1897
 [4] optimize!(::MathOptInterface.Bridges.LazyBridgeOptimizer{CPLEX.Optimizer}) at /home/mbesanco/.julia/packages/MathOptInterface/bygN7/src/Bridges/bridge_optimizer.jl:239
 [5] optimize!(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}) at /home/mbesanco/.julia/packages/MathOptInterface/bygN7/src/Utilities/cachingoptimizer.jl:189
 [6] optimize!(::Model, ::Nothing; bridge_constraints::Bool, ignore_optimize_hook::Bool, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/mbesanco/.julia/packages/JuMP/YXK4e/src/optimizer_interface.jl:131
 [7] optimize! at /home/mbesanco/.julia/packages/JuMP/YXK4e/src/optimizer_interface.jl:107 [inlined] (repeats 2 times)

I haven't managed to get a MWE yet, but the bug appears to be on code that was running before.
The breaking part is in cpx_generic_callback.jl:

function callback_wrapper(
    context::Ptr{Cvoid}, context_id::Clong, user_handle::Ptr{Cvoid}
)
    (model, callback_func) = unsafe_pointer_to_objref(user_handle)::Tuple{Model, Function}

Version info:
CPLEX v0.6.5
julia 1.5
JuMP 0.21.3
MOI 0.9.14

Edit: bug also observed with CPLEX 12.09

@matbesancon
Copy link
Contributor Author

This appeared when using lazy callbacks

@matbesancon
Copy link
Contributor Author

I seem to have another version of the bug (running the same code with CPLEX 12.08), where the error is:

   3   │ ERROR: LoadError: TypeError: in typeassert, expected Tuple{CPLEX.Model,Function}, got a value of type Core.Compiler.SlotInfo
   4   │ Stacktrace:
   5   │  [1] callback_wrapper(::Ptr{Nothing}, ::Int64, ::Ptr{Nothing}) at /home/mbesanco/.julia/packages/CPLEX/Hxpuk/src/cpx_generic_callbacks.jl:15

@odow
Copy link
Member

odow commented Aug 9, 2020

This might be a Julia 1.5 change?

@matbesancon
Copy link
Contributor Author

potentially yes, I will rerun it using 1.4 and see if it still errors

@matbesancon
Copy link
Contributor Author

matbesancon commented Aug 9, 2020

Ok the model is still running and would have errored by now, so I confirm the bug happens on 1.5 only. Sadly still no MWE I could build

@odow
Copy link
Member

odow commented Aug 9, 2020

Instead of using a tuple, we probably need to define a type with an appropriate cconvert

user_handle = (model, callback_func)::Tuple{Model, Function}
return_status = @cpx_ccall(
callbacksetfunc,
Cint,
(Ptr{Cvoid}, Ptr{Cvoid}, Clong, Ptr{Cvoid}, Any),
model.env, model.lp, context_mask, c_callback, user_handle

I don't know what it means to pass Any to a ccall.

@matbesancon
Copy link
Contributor Author

do we need to pass the model? Otherwise only passing a function as Ptr{CVoid} might work?

@odow
Copy link
Member

odow commented Sep 25, 2020

@matbesancon can you try #316? You'll need 12.10, however.

@matbesancon
Copy link
Contributor Author

Yes I should be able to give it a try this weekend

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

Successfully merging a pull request may close this issue.

2 participants